[llvm] 07365f4 - InstSimplify: Combine computeKnownFPClass calls and pass AssumptionCache

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu May 18 15:29:56 PDT 2023


Author: Matt Arsenault
Date: 2023-05-18T23:29:47+01:00
New Revision: 07365f4a40a62c5e366f3135e6e00a845b86eb2c

URL: https://github.com/llvm/llvm-project/commit/07365f4a40a62c5e366f3135e6e00a845b86eb2c
DIFF: https://github.com/llvm/llvm-project/commit/07365f4a40a62c5e366f3135e6e00a845b86eb2c.diff

LOG: InstSimplify: Combine computeKnownFPClass calls and pass AssumptionCache

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 3d4e96937cd68..e3cd9fd9d2275 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5634,9 +5634,8 @@ static Value *simplifyFMAFMul(Value *Op0, Value *Op1, FastMathFlags FMF,
       return ConstantFP::getZero(Op0->getType());
 
     // +normal number * (-)0.0 --> (-)0.0
-    // TODO: Use computeKnownFPClass
-    if (isKnownNeverInfinity(Op0, Q.DL, Q.TLI) &&
-        isKnownNeverNaN(Op0, Q.DL, Q.TLI) &&
+    if (isKnownNeverInfOrNaN(Op0, Q.DL, Q.TLI, 0, Q.AC, Q.CxtI, Q.DT) &&
+        // TODO: Check SignBit from computeKnownFPClass when it's more complete.
         SignBitMustBeZero(Op0, Q.DL, Q.TLI))
       return Op1;
   }

diff  --git a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
index 4e75959832b3d..b8244b1d508c6 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
@@ -211,6 +211,24 @@ define double @fmul_nnan_ninf_nneg_n0.0_commute(i127 %x) {
   ret double %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(
+; CHECK-NEXT:    [[FABS_X:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
+; CHECK-NEXT:    [[IS_FINITE_X:%.*]] = fcmp one float [[FABS_X]], 0x7FF0000000000000
+; CHECK-NEXT:    call void @llvm.assume(i1 [[IS_FINITE_X]])
+; CHECK-NEXT:    ret { float, float } { float 0.000000e+00, float -0.000000e+00 }
+;
+  %fabs.x = call float @llvm.fabs.f32(float %x)
+  %is.finite.x = fcmp one float %fabs.x, 0x7FF0000000000000
+  call void @llvm.assume(i1 %is.finite.x)
+  %mul.0 = fmul float %fabs.x, 0.0
+  %mul.neg0 = fmul float %fabs.x, -0.0
+  %ins.0 = insertvalue { float, float } poison, float %mul.0, 0
+  %ins.1 = insertvalue { float, float } %ins.0, float %mul.neg0, 1
+  ret { float, float } %ins.1
+}
+
 ; negative test - the int could be big enough to round to INF
 
 define double @fmul_nnan_ninf_nneg_0.0_commute(i128 %x) {
@@ -292,6 +310,8 @@ declare float @llvm.copysign.f32(float, float)
 declare <2 x float> @llvm.fabs.v2f32(<2 x float>)
 declare float @llvm.sqrt.f32(float)
 declare float @llvm.maxnum.f32(float, float)
+declare void @llvm.assume(i1 noundef)
+
 
 define float @fabs_select_positive_constants(i32 %c) {
 ; CHECK-LABEL: @fabs_select_positive_constants(


        


More information about the llvm-commits mailing list