[PATCH] D123396: [FPEnv][InstSimplify] Fold fsub -0.0, -X ==> X
Kevin P. Neal via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 14 08:49:37 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd43d9e1d5c98: [FPEnv][InstSimplify] Fold fsub -0.0, -X ==> X (authored by kpn).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D123396/new/
https://reviews.llvm.org/D123396
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/strictfp-fsub.ll
Index: llvm/test/Transforms/InstSimplify/strictfp-fsub.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/strictfp-fsub.ll
+++ llvm/test/Transforms/InstSimplify/strictfp-fsub.ll
@@ -251,12 +251,9 @@
ret float %ret
}
-; TODO: This will fold if we allow non-default floating point environments.
define float @fsub_fneg_nnan_n0_fnX_ebmaytrap(float %a) #0 {
; CHECK-LABEL: @fsub_fneg_nnan_n0_fnX_ebmaytrap(
-; CHECK-NEXT: [[NEGA:%.*]] = fneg float [[A:%.*]]
-; CHECK-NEXT: [[RET:%.*]] = call nnan float @llvm.experimental.constrained.fsub.f32(float -0.000000e+00, float [[NEGA]], metadata !"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR0]]
-; CHECK-NEXT: ret float [[RET]]
+; CHECK-NEXT: ret float [[A:%.*]]
;
%nega = fneg float %a
%ret = call nnan float @llvm.experimental.constrained.fsub.f32(float -0.0, float %nega, metadata !"round.tonearest", metadata !"fpexcept.maytrap") #0
@@ -275,13 +272,12 @@
ret float %ret
}
-; TODO: This will fold if we allow non-default floating point environments.
-; TODO: The instruction is expected to remain, but the result isn't used.
+; NOTE: The instruction is expected to remain, but the result isn't used.
define float @fsub_fneg_nnan_n0_fnX_ebstrict(float %a) #0 {
; CHECK-LABEL: @fsub_fneg_nnan_n0_fnX_ebstrict(
; CHECK-NEXT: [[NEGA:%.*]] = fneg float [[A:%.*]]
; CHECK-NEXT: [[RET:%.*]] = call nnan float @llvm.experimental.constrained.fsub.f32(float -0.000000e+00, float [[NEGA]], metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
-; CHECK-NEXT: ret float [[RET]]
+; CHECK-NEXT: ret float [[A]]
;
%nega = fneg float %a
%ret = call nnan float @llvm.experimental.constrained.fsub.f32(float -0.0, float %nega, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5207,15 +5207,16 @@
(FMF.noSignedZeros() || CannotBeNegativeZero(Op0, Q.TLI)))
return Op0;
- if (!isDefaultFPEnvironment(ExBehavior, Rounding))
- return nullptr;
-
// fsub -0.0, (fsub -0.0, X) ==> X
// fsub -0.0, (fneg X) ==> X
Value *X;
- if (match(Op0, m_NegZeroFP()) &&
- match(Op1, m_FNeg(m_Value(X))))
- return X;
+ if (canIgnoreSNaN(ExBehavior, FMF))
+ if (match(Op0, m_NegZeroFP()) &&
+ match(Op1, m_FNeg(m_Value(X))))
+ return X;
+
+ if (!isDefaultFPEnvironment(ExBehavior, Rounding))
+ return nullptr;
// fsub 0.0, (fsub 0.0, X) ==> X if signed zeros are ignored.
// fsub 0.0, (fneg X) ==> X if signed zeros are ignored.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123396.422876.patch
Type: text/x-patch
Size: 2764 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220414/0f030536/attachment.bin>
More information about the llvm-commits
mailing list