[llvm] 84812b9 - [InstCombine] drop FMF in select->copysign transform
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 1 05:53:07 PST 2022
Author: Sanjay Patel
Date: 2022-03-01T08:51:41-05:00
New Revision: 84812b9b072a513acfa76149c5a481d4eb8a511d
URL: https://github.com/llvm/llvm-project/commit/84812b9b072a513acfa76149c5a481d4eb8a511d
DIFF: https://github.com/llvm/llvm-project/commit/84812b9b072a513acfa76149c5a481d4eb8a511d.diff
LOG: [InstCombine] drop FMF in select->copysign transform
It is not correct to propagate flags from the select
to the new instructions:
https://alive2.llvm.org/ce/z/tNATrd
https://alive2.llvm.org/ce/z/VwcVzn
Fixes #54077
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/select.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index a9745cf38a77e..a46600a261fe3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -2353,17 +2353,16 @@ static Instruction *foldSelectToCopysign(SelectInst &Sel,
// (bitcast X) < 0 ? TC : -TC --> copysign(TC, -X)
// (bitcast X) >= 0 ? -TC : TC --> copysign(TC, -X)
// (bitcast X) >= 0 ? TC : -TC --> copysign(TC, X)
+ // Note: FMF from the select can not be propagated to the new instructions.
if (IsTrueIfSignSet ^ TC->isNegative())
- X = Builder.CreateFNegFMF(X, &Sel);
+ X = Builder.CreateFNeg(X);
// Canonicalize the magnitude argument as the positive constant since we do
// not care about its sign.
Value *MagArg = TC->isNegative() ? FVal : TVal;
Function *F = Intrinsic::getDeclaration(Sel.getModule(), Intrinsic::copysign,
Sel.getType());
- Instruction *CopySign = CallInst::Create(F, { MagArg, X });
- CopySign->setFastMathFlags(Sel.getFastMathFlags());
- return CopySign;
+ return CallInst::Create(F, { MagArg, X });
}
Instruction *InstCombinerImpl::foldVectorSelect(SelectInst &Sel) {
diff --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll
index 124d96f743646..d05336bddcc6d 100644
--- a/llvm/test/Transforms/InstCombine/select.ll
+++ b/llvm/test/Transforms/InstCombine/select.ll
@@ -1656,7 +1656,7 @@ define float @copysign1(float %x) {
define float @copysign1_fmf(float %x) {
; CHECK-LABEL: @copysign1_fmf(
-; CHECK-NEXT: [[R:%.*]] = call ninf nsz float @llvm.copysign.f32(float 1.000000e+00, float [[X:%.*]])
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.copysign.f32(float 1.000000e+00, float [[X:%.*]])
; CHECK-NEXT: ret float [[R]]
;
%i = bitcast float %x to i32
@@ -1667,8 +1667,8 @@ define float @copysign1_fmf(float %x) {
define <2 x float> @copysign2(<2 x float> %x) {
; CHECK-LABEL: @copysign2(
-; CHECK-NEXT: [[TMP1:%.*]] = fneg nsz <2 x float> [[X:%.*]]
-; CHECK-NEXT: [[R:%.*]] = call nsz <2 x float> @llvm.copysign.v2f32(<2 x float> <float 4.200000e+01, float 4.200000e+01>, <2 x float> [[TMP1]])
+; CHECK-NEXT: [[TMP1:%.*]] = fneg <2 x float> [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call <2 x float> @llvm.copysign.v2f32(<2 x float> <float 4.200000e+01, float 4.200000e+01>, <2 x float> [[TMP1]])
; CHECK-NEXT: ret <2 x float> [[R]]
;
%i = bitcast <2 x float> %x to <2 x i32>
@@ -1679,8 +1679,8 @@ define <2 x float> @copysign2(<2 x float> %x) {
define float @copysign3(float %x) {
; CHECK-LABEL: @copysign3(
-; CHECK-NEXT: [[TMP1:%.*]] = fneg fast float [[X:%.*]]
-; CHECK-NEXT: [[R:%.*]] = call fast float @llvm.copysign.f32(float 4.300000e+01, float [[TMP1]])
+; CHECK-NEXT: [[TMP1:%.*]] = fneg float [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = call float @llvm.copysign.f32(float 4.300000e+01, float [[TMP1]])
; CHECK-NEXT: ret float [[R]]
;
%i = bitcast float %x to i32
More information about the llvm-commits
mailing list