aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorSerge Pavlov <sepavloff@gmail.com>2021-05-04 20:43:56 +0700
committerSerge Pavlov <sepavloff@gmail.com>2021-07-23 14:39:51 +0700
commit1c64b5dc5ea8c20a7f2ae436f31030bde0c99db3 (patch)
tree5804d20962d5d3618dc030540425855882be73f3 /llvm/lib/Transforms/Utils/Local.cpp
parent2f15319968ec38314a28570bb978726b288bd7cc (diff)
downloadllvm-1c64b5dc5ea8c20a7f2ae436f31030bde0c99db3.zip
llvm-1c64b5dc5ea8c20a7f2ae436f31030bde0c99db3.tar.gz
llvm-1c64b5dc5ea8c20a7f2ae436f31030bde0c99db3.tar.bz2
[ConstantFolding] Fold constrained arithmetic intrinsics
Constfold constrained variants of operations fadd, fsub, fmul, fdiv, frem, fma and fmuladd. The change also sets up some means to support for removal of unused constrained intrinsics. They are declared as accessing memory to model interaction with floating point environment, so they were not removed, as they have side effect. Now constrained intrinsics that have "fpexcept.ignore" as exception behavior are removed if they have no uses. As for intrinsics that have exception behavior other than "fpexcept.ignore", they can be removed if it is known that they do not raise floating point exceptions. It happens when doing constant folding, attributes of such intrinsic are changed so that the intrinsic is not claimed as accessing memory. Differential Revision: https://reviews.llvm.org/D102673
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index d5e301b..d95c053 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -491,6 +491,16 @@ bool llvm::wouldInstructionBeTriviallyDead(Instruction *I,
if (isMathLibCallNoop(Call, TLI))
return true;
+ // To express possible interaction with floating point environment constrained
+ // intrinsics are described as if they access memory. So they look like having
+ // side effect but actually do not have it unless they raise floating point
+ // exception. If FP exceptions are ignored, the intrinsic may be deleted.
+ if (auto *CI = dyn_cast<ConstrainedFPIntrinsic>(I)) {
+ Optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
+ if (!EB || *EB == fp::ExceptionBehavior::ebIgnore)
+ return true;
+ }
+
return false;
}