[PATCH] D118928: [FPEnv][InstSimplify] Fold fsub X, +0 ==> X
Kevin P. Neal via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 3 11:13:37 PST 2022
kpn created this revision.
kpn added reviewers: sepavloff, spatel, nlopes, lebedev.ri.
Herald added a subscriber: hiraditya.
kpn requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Currently the fsub optimizations in InstSimplify don't know how to fold X - +0.0 to X when using the constrained intrinsics. This adds the support.
This review is split out from D107285 <https://reviews.llvm.org/D107285>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118928
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
@@ -27,11 +27,9 @@
ret float %ret
}
-; TODO: This will fold if we allow non-default floating point environments.
define float @fsub_nnan_x_p0_ebmaytrap(float %a) #0 {
; CHECK-LABEL: @fsub_nnan_x_p0_ebmaytrap(
-; CHECK-NEXT: [[RET:%.*]] = call nnan float @llvm.experimental.constrained.fsub.f32(float [[A:%.*]], float 0.000000e+00, metadata !"round.tonearest", metadata !"fpexcept.maytrap") #[[ATTR0]]
-; CHECK-NEXT: ret float [[RET]]
+; CHECK-NEXT: ret float [[A:%.*]]
;
%ret = call nnan float @llvm.experimental.constrained.fsub.f32(float %a, float 0.0, metadata !"round.tonearest", metadata !"fpexcept.maytrap") #0
ret float %ret
@@ -47,12 +45,11 @@
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.
define float @fsub_nnan_x_p0_ebstrict(float %a) #0 {
; CHECK-LABEL: @fsub_nnan_x_p0_ebstrict(
; CHECK-NEXT: [[RET:%.*]] = call nnan float @llvm.experimental.constrained.fsub.f32(float [[A:%.*]], float 0.000000e+00, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
-; CHECK-NEXT: ret float [[RET]]
+; CHECK-NEXT: ret float [[A]]
;
%ret = call nnan float @llvm.experimental.constrained.fsub.f32(float %a, float 0.0, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
ret float %ret
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5130,13 +5130,14 @@
if (Constant *C = simplifyFPOp({Op0, Op1}, FMF, Q, ExBehavior, Rounding))
return C;
+ // fsub X, +0 ==> X
+ if (canIgnoreSNaN(ExBehavior, FMF))
+ if (match(Op1, m_PosZeroFP()))
+ return Op0;
+
if (!isDefaultFPEnvironment(ExBehavior, Rounding))
return nullptr;
- // fsub X, +0 ==> X
- if (match(Op1, m_PosZeroFP()))
- return Op0;
-
// fsub X, -0 ==> X, when we know X is not -0
if (match(Op1, m_NegZeroFP()) &&
(FMF.noSignedZeros() || CannotBeNegativeZero(Op0, Q.TLI)))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118928.405717.patch
Type: text/x-patch
Size: 2366 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220203/03a56154/attachment.bin>
More information about the llvm-commits
mailing list