[llvm] 6acf666 - ConstantFolding: Ignore output denorm mode for canonicalize

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 13 05:44:27 PST 2022


Author: Matt Arsenault
Date: 2022-12-13T08:44:21-05:00
New Revision: 6acf6661dd17af9f9858f3d3ff67eb88f7675d31

URL: https://github.com/llvm/llvm-project/commit/6acf6661dd17af9f9858f3d3ff67eb88f7675d31
DIFF: https://github.com/llvm/llvm-project/commit/6acf6661dd17af9f9858f3d3ff67eb88f7675d31.diff

LOG: ConstantFolding: Ignore output denorm mode for canonicalize

Alive2 opt plugin is now happy with the test. Fixes issue 59245

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp
    llvm/test/Transforms/InstSimplify/canonicalize.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 9be7951c987b..687c325a2ab0 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1970,9 +1970,10 @@ static Constant *constantFoldCanonicalize(const Type *Ty, const CallBase *CI,
     if (DenormMode == DenormalMode::getIEEE())
       return nullptr;
 
-    bool IsPositive = !Src.isNegative() ||
-                      DenormMode.Input == DenormalMode::PositiveZero ||
-                      DenormMode.Output == DenormalMode::PositiveZero;
+    bool IsPositive =
+        (!Src.isNegative() || DenormMode.Input == DenormalMode::PositiveZero ||
+         (DenormMode.Output == DenormalMode::PositiveZero &&
+          DenormMode.Input == DenormalMode::IEEE));
     return ConstantFP::get(CI->getContext(),
                            APFloat::getZero(Src.getSemantics(), !IsPositive));
   }

diff  --git a/llvm/test/Transforms/InstSimplify/canonicalize.ll b/llvm/test/Transforms/InstSimplify/canonicalize.ll
index c14cd3b5e729..f3d3ce9c8ad0 100644
--- a/llvm/test/Transforms/InstSimplify/canonicalize.ll
+++ b/llvm/test/Transforms/InstSimplify/canonicalize.ll
@@ -238,7 +238,7 @@ define float @canonicalize_neg_denorm_preserve_sign_output_positive_zero_input()
 
 define float @canonicalize_neg_denorm_positive_zero_output_preserve_sign_input() "denormal-fp-math"="positive-zero,preserve-sign" {
 ; CHECK-LABEL: @canonicalize_neg_denorm_positive_zero_output_preserve_sign_input(
-; CHECK-NEXT:    ret float 0.000000e+00
+; CHECK-NEXT:    ret float -0.000000e+00
 ;
   %ret = call float @llvm.canonicalize.f32(float bitcast (i32 -2139095041 to float))
   ret float %ret


        


More information about the llvm-commits mailing list