From 6acf6661dd17af9f9858f3d3ff67eb88f7675d31 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 13 Dec 2022 08:12:36 -0500 Subject: [PATCH] ConstantFolding: Ignore output denorm mode for canonicalize Alive2 opt plugin is now happy with the test. Fixes issue 59245 --- llvm/lib/Analysis/ConstantFolding.cpp | 7 ++++--- llvm/test/Transforms/InstSimplify/canonicalize.ll | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 9be7951..687c325 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 c14cd3b..f3d3ce9 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 -- 2.7.4