Skip to content

[InstCombine] Propagate poison pow[i] #146750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6673,7 +6673,13 @@ Value *llvm::simplifyBinaryIntrinsic(Intrinsic::ID IID, Type *ReturnType,
if (auto *C1 = dyn_cast<Constant>(Op1))
return simplifyRelativeLoad(C0, C1, Q.DL);
break;
case Intrinsic::pow:
if (isa<PoisonValue>(Op0) || isa<PoisonValue>(Op1))
return PoisonValue::get(ReturnType);
break;
case Intrinsic::powi:
if (isa<PoisonValue>(Op0) || isa<PoisonValue>(Op1))
return PoisonValue::get(ReturnType);
if (auto *Power = dyn_cast<ConstantInt>(Op1)) {
// powi(x, 0) -> 1.0
if (Power->isZero())
Expand Down
32 changes: 31 additions & 1 deletion llvm/test/Transforms/InstSimplify/fold-intrinsics.ll
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ define void @powi(double %V, ptr%P) {
define void @powi_i16(float %V, ptr%P) {
; CHECK-LABEL: @powi_i16(
; CHECK-NEXT: store volatile float 1.000000e+00, ptr [[P:%.*]], align 4
; CHECK-NEXT: store volatile float [[V:%.*]], ptr [[P]], align 4
; CHECK-NEXT: store volatile float [[D:%.*]], ptr [[P]], align 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change?

Suggested change
; CHECK-NEXT: store volatile float [[D:%.*]], ptr [[P]], align 4
; CHECK-NEXT: store volatile float [[V:%.*]], ptr [[P]], align 4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comes from the auto updating test tool

; CHECK-NEXT: ret void
;
%B = tail call float @llvm.powi.f32.i16(float %V, i16 0) nounwind
Expand All @@ -44,3 +44,33 @@ define void @powi_i16(float %V, ptr%P) {

ret void
}

define void @pow_poison_i16(i16 %arg_int,float %arg_flt, ptr %P) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
define void @pow_poison_i16(i16 %arg_int,float %arg_flt, ptr %P) {
define void @pow_poison(i16 %int, float %flt, ptr %P) {

; CHECK-LABEL: @pow_poison_i16(
; CHECK-NEXT: store volatile float poison, ptr [[P:%.*]], align 4
; CHECK-NEXT: store volatile float poison, ptr [[P]], align 4
; CHECK-NEXT: store volatile float poison, ptr [[P]], align 4
; CHECK-NEXT: store volatile float poison, ptr [[P]], align 4
; CHECK-NEXT: store volatile float poison, ptr [[P]], align 4
; CHECK-NEXT: store volatile float poison, ptr [[P]], align 4
; CHECK-NEXT: ret void
;
%2 = tail call float @llvm.powi.f32.i16(float poison, i16 %arg_int) nounwind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nowadays you can leave out the type overload on the intrinsic signatures

Suggested change
%2 = tail call float @llvm.powi.f32.i16(float poison, i16 %arg_int) nounwind
%2 = tail call float @llvm.powi(float poison, i16 %arg_int) nounwind

store volatile float %2, ptr %P

%3 = tail call float @llvm.pow(float poison, float %arg_flt) nounwind
store volatile float %3, ptr %P

%4 = tail call float @llvm.powi.f32.i16(float %arg_flt, i16 poison) nounwind
store volatile float %4, ptr %P

%5 = tail call float @llvm.pow(float %arg_flt, float poison) nounwind
store volatile float %5, ptr %P

%6 = tail call float @llvm.powi.f32.i16(float poison, i16 poison) nounwind
store volatile float %6, ptr %P

%7 = tail call float @llvm.pow(float poison, float poison) nounwind
store volatile float %7, ptr %P
ret void
}
Loading