[PATCH] D115870: [ConstantFolding] Do not remove side effect from constrained functions
Serge Pavlov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 16 03:57:57 PST 2021
sepavloff created this revision.
sepavloff added reviewers: kpn, spatel, craig.topper, lebedev.ri, nikic.
Herald added a subscriber: hiraditya.
sepavloff requested review of this revision.
Herald added a project: LLVM.
According to the discussion in https://reviews.llvm.org/D110322 the code
that removes side effect from replaced function call is deleted.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115870
Files:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstSimplify/constfold-constrained.ll
llvm/test/Transforms/InstSimplify/fdiv-strictfp.ll
llvm/test/Transforms/InstSimplify/strictfp-fadd.ll
Index: llvm/test/Transforms/InstSimplify/strictfp-fadd.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/strictfp-fadd.ll
+++ llvm/test/Transforms/InstSimplify/strictfp-fadd.ll
@@ -363,6 +363,7 @@
define float @fold_fadd_qnan_qnan_ebstrict() #0 {
; CHECK-LABEL: @fold_fadd_qnan_qnan_ebstrict(
+; CHECK-NEXT: [[ADD:%.*]] = call float @llvm.experimental.constrained.fadd.f32(float 0x7FF8000000000000, float 0x7FF8000000000000, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
; CHECK-NEXT: ret float 0x7FF8000000000000
;
%add = call float @llvm.experimental.constrained.fadd.f32(float 0x7ff8000000000000, float 0x7ff8000000000000, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
Index: llvm/test/Transforms/InstSimplify/fdiv-strictfp.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/fdiv-strictfp.ll
+++ llvm/test/Transforms/InstSimplify/fdiv-strictfp.ll
@@ -12,6 +12,7 @@
define float @fdiv_constant_fold_strict() #0 {
; CHECK-LABEL: @fdiv_constant_fold_strict(
+; CHECK-NEXT: [[F:%.*]] = call float @llvm.experimental.constrained.fdiv.f32(float 3.000000e+00, float 2.000000e+00, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0:[0-9]+]]
; CHECK-NEXT: ret float 1.500000e+00
;
%f = call float @llvm.experimental.constrained.fdiv.f32(float 3.0, float 2.0, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
@@ -21,7 +22,7 @@
define float @fdiv_constant_fold_strict2() #0 {
; CHECK-LABEL: @fdiv_constant_fold_strict2(
-; CHECK-NEXT: [[F:%.*]] = call float @llvm.experimental.constrained.fdiv.f32(float 2.000000e+00, float 3.000000e+00, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0:[0-9]+]]
+; CHECK-NEXT: [[F:%.*]] = call float @llvm.experimental.constrained.fdiv.f32(float 2.000000e+00, float 3.000000e+00, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
; CHECK-NEXT: ret float [[F]]
;
%f = call float @llvm.experimental.constrained.fdiv.f32(float 2.0, float 3.0, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
@@ -39,6 +40,7 @@
define float @frem_constant_fold_strict() #0 {
; CHECK-LABEL: @frem_constant_fold_strict(
+; CHECK-NEXT: [[F:%.*]] = call float @llvm.experimental.constrained.frem.f32(float 3.000000e+00, float 2.000000e+00, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
; CHECK-NEXT: ret float 1.000000e+00
;
%f = call float @llvm.experimental.constrained.frem.f32(float 3.0, float 2.0, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
Index: llvm/test/Transforms/InstSimplify/constfold-constrained.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/constfold-constrained.ll
+++ llvm/test/Transforms/InstSimplify/constfold-constrained.ll
@@ -282,6 +282,7 @@
define double @fadd_05() #0 {
; CHECK-LABEL: @fadd_05(
; CHECK-NEXT: entry:
+; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 1.000000e+00, double 2.000000e+00, metadata !"round.tonearest", metadata !"fpexcept.strict") #[[ATTR0]]
; CHECK-NEXT: ret double 3.000000e+00
;
entry:
@@ -293,6 +294,7 @@
define double @fadd_06() #0 {
; CHECK-LABEL: @fadd_06(
; CHECK-NEXT: entry:
+; CHECK-NEXT: [[RESULT:%.*]] = call double @llvm.experimental.constrained.fadd.f64(double 1.000000e+00, double 2.000000e+00, metadata !"round.dynamic", metadata !"fpexcept.strict") #[[ATTR0]]
; CHECK-NEXT: ret double 3.000000e+00
;
entry:
@@ -503,6 +505,7 @@
define i1 @cmp_eq_nan_03() #0 {
; CHECK-LABEL: @cmp_eq_nan_03(
; CHECK-NEXT: entry:
+; CHECK-NEXT: [[RESULT:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f64(double 0x7FF8000000000000, double 1.000000e+00, metadata !"oeq", metadata !"fpexcept.strict") #[[ATTR0]]
; CHECK-NEXT: ret i1 false
;
entry:
Index: llvm/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/lib/Analysis/ConstantFolding.cpp
+++ llvm/lib/Analysis/ConstantFolding.cpp
@@ -1780,15 +1780,8 @@
// If the operation does not change exception status flags, it is safe
// to fold.
- if (St == APFloat::opStatus::opOK) {
- // When FP exceptions are not ignored, intrinsic call will not be
- // eliminated, because it is considered as having side effect. But we
- // know that its evaluation does not raise exceptions, so side effect
- // is absent. To allow removing the call, mark it as not accessing memory.
- if (EB && *EB != fp::ExceptionBehavior::ebIgnore)
- CI->addFnAttr(Attribute::ReadNone);
+ if (St == APFloat::opStatus::opOK)
return true;
- }
// If evaluation raised FP exception, the result can depend on rounding
// mode. If the latter is unknown, folding is not possible.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115870.394816.patch
Type: text/x-patch
Size: 4932 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211216/301f17cb/attachment.bin>
More information about the llvm-commits
mailing list