ConstantFolding: Ignore output denorm mode for canonicalize
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 13 Dec 2022 13:12:36 +0000 (08:12 -0500)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Tue, 13 Dec 2022 13:44:21 +0000 (08:44 -0500)
Alive2 opt plugin is now happy with the test. Fixes issue 59245

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

index 9be7951..687c325 100644 (file)
@@ -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));
   }
index c14cd3b..f3d3ce9 100644 (file)
@@ -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