Skip to content

[InstSimplify] Handle nsz when simplifying X * 0.0 #142181

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

Merged
Merged
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
3 changes: 3 additions & 0 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
@@ -5844,6 +5844,9 @@ static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
KnownFPClass Known =
computeKnownFPClass(Op0, FMF, fcInf | fcNan, /*Depth=*/0, Q);
if (Known.isKnownNever(fcInf | fcNan)) {
// if nsz is set, return 0.0
if (FMF.noSignedZeros())
return ConstantFP::getZero(Op0->getType());
// +normal number * (-)0.0 --> (-)0.0
if (Known.SignBit == false)
return Op1;
16 changes: 16 additions & 0 deletions llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
Original file line number Diff line number Diff line change
@@ -211,6 +211,22 @@ define double @fmul_nnan_ninf_nneg_n0.0_commute(i127 %x) {
ret double %r
}

define float @fmul_ninf_nnan_mul_zero_nsz(float nofpclass(inf nan) %f) {
; CHECK-LABEL: @fmul_ninf_nnan_mul_zero_nsz(
; CHECK-NEXT: ret float 0.000000e+00
;
%r = fmul nsz float %f, 0.0
ret float %r
}

define float @fmul_ninf_nnan_mul_nzero_nsz(float nofpclass(inf nan) %f) {
; CHECK-LABEL: @fmul_ninf_nnan_mul_nzero_nsz(
; CHECK-NEXT: ret float 0.000000e+00
;
%r = fmul nsz float %f, -0.0
ret float %r
}

define float @src_mul_nzero_neg(float nofpclass(inf nan pzero psub pnorm) %f) {
; CHECK-LABEL: @src_mul_nzero_neg(
; CHECK-NEXT: ret float 0.000000e+00
Loading
Oops, something went wrong.