[llvm] 77b923d - [ConstantFolding] Do not remove side effect from constrained functions
Serge Pavlov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 21 22:47:08 PST 2021
Author: Serge Pavlov
Date: 2021-12-22T13:45:49+07:00
New Revision: 77b923d0dbe30f99b27ad533ef4322ee176b2046
URL: https://github.com/llvm/llvm-project/commit/77b923d0dbe30f99b27ad533ef4322ee176b2046
DIFF: https://github.com/llvm/llvm-project/commit/77b923d0dbe30f99b27ad533ef4322ee176b2046.diff
LOG: [ConstantFolding] Do not remove side effect from constrained functions
According to the discussion in https://reviews.llvm.org/D110322 the code
that removes side effect from replaced function call is deleted.
Differential Revision: https://reviews.llvm.org/D115870
Added:
Modified:
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
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index e4920c351ccaf..922b38e927852 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1778,15 +1778,8 @@ static bool mayFoldConstrained(ConstrainedFPIntrinsic *CI,
// 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.
diff --git a/llvm/test/Transforms/InstSimplify/constfold-constrained.ll b/llvm/test/Transforms/InstSimplify/constfold-constrained.ll
index 4db5fbff30aff..2bfd4e03b1e6c 100644
--- a/llvm/test/Transforms/InstSimplify/constfold-constrained.ll
+++ b/llvm/test/Transforms/InstSimplify/constfold-constrained.ll
@@ -282,6 +282,7 @@ entry:
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 @@ entry:
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:
diff --git a/llvm/test/Transforms/InstSimplify/fdiv-strictfp.ll b/llvm/test/Transforms/InstSimplify/fdiv-strictfp.ll
index 82101a4ef8286..39222b1916afb 100644
--- a/llvm/test/Transforms/InstSimplify/fdiv-strictfp.ll
+++ b/llvm/test/Transforms/InstSimplify/fdiv-strictfp.ll
@@ -12,6 +12,7 @@ define float @fdiv_constant_fold() #0 {
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_strict() #0 {
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() #0 {
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
diff --git a/llvm/test/Transforms/InstSimplify/strictfp-fadd.ll b/llvm/test/Transforms/InstSimplify/strictfp-fadd.ll
index 61b2cafc63adf..61d06e964ac5c 100644
--- a/llvm/test/Transforms/InstSimplify/strictfp-fadd.ll
+++ b/llvm/test/Transforms/InstSimplify/strictfp-fadd.ll
@@ -363,6 +363,7 @@ define float @fold_fadd_qnan_qnan_ebmaytrap() #0 {
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
More information about the llvm-commits
mailing list