[llvm] [InstSimply] Add tests for simplify `(fmul -x, +/-0)` -> `-/+0` (PR #85345)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 14 18:06:15 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: None (goldsteinn)
<details>
<summary>Changes</summary>
- **[InstSimply] Add tests for simplify `(fmul -x, +/-0)`; NFC**
- **[InstSimply] Add tests for simplify `(fmul -x, +/-0)` -> `-/+0`**
---
Full diff: https://github.com/llvm/llvm-project/pull/85345.diff
2 Files Affected:
- (modified) llvm/lib/Analysis/InstructionSimplify.cpp (+10-3)
- (modified) llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll (+16)
``````````diff
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index ce651783caf16b..434ee26ef01aa5 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5767,11 +5767,18 @@ static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
if (FMF.noNaNs() && FMF.noSignedZeros())
return ConstantFP::getZero(Op0->getType());
- // +normal number * (-)0.0 --> (-)0.0
KnownFPClass Known =
computeKnownFPClass(Op0, FMF, fcInf | fcNan, /*Depth=*/0, Q);
- if (Known.SignBit == false && Known.isKnownNever(fcInf | fcNan))
- return Op1;
+ if (Known.isKnownNever(fcInf | fcNan)) {
+ // +normal number * (-)0.0 --> (-)0.0
+ if (Known.SignBit == false)
+ return Op1;
+ // -normal number * (-)0.0 --> -(-)0.0
+ if (Known.SignBit == true)
+ return match(Op1, m_PosZeroFP())
+ ? ConstantFP::getNegativeZero(Op0->getType())
+ : ConstantFP::getZero(Op0->getType());
+ }
}
// sqrt(X) * sqrt(X) --> X, if we can:
diff --git a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
index b8244b1d508c62..9b913d68f4004e 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
@@ -211,6 +211,22 @@ define double @fmul_nnan_ninf_nneg_n0.0_commute(i127 %x) {
ret double %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
+;
+ %r = fmul float %f, -0.0
+ ret float %r
+}
+
+define float @src_mul_zero_neg(float nofpclass(inf nan pzero psub pnorm) %f) {
+; CHECK-LABEL: @src_mul_zero_neg(
+; CHECK-NEXT: ret float -0.000000e+00
+;
+ %r = fmul float %f, 0.0
+ ret float %r
+}
+
; Make sure we can infer %x can't be 0 based on assumes.
define { float, float } @test_fmul_0_assumed_finite(float %x) {
; CHECK-LABEL: @test_fmul_0_assumed_finite(
``````````
</details>
https://github.com/llvm/llvm-project/pull/85345
More information about the llvm-commits
mailing list