aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2022-07-13 12:18:40 +0200
committerNikita Popov <npopov@redhat.com>2022-07-14 14:41:51 +0200
commitdcf4b733ef8e8e876e55b85c0d67c9b32c4fde0e (patch)
treef512bf0ec980c9acabf782999bd76d029d387d63 /llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
parent69b312cde428056186928a3c1b6ad84e45de0353 (diff)
downloadllvm-dcf4b733ef8e8e876e55b85c0d67c9b32c4fde0e.zip
llvm-dcf4b733ef8e8e876e55b85c0d67c9b32c4fde0e.tar.gz
llvm-dcf4b733ef8e8e876e55b85c0d67c9b32c4fde0e.tar.bz2
[SCEVExpander] Make CanonicalMode handing in isSafeToExpand() more robust (PR50506)
isSafeToExpand() for addrecs depends on whether the SCEVExpander will be used in CanonicalMode. At least one caller currently gets this wrong, resulting in PR50506. Fix this by a) making the CanonicalMode argument on the freestanding functions required and b) adding member functions on SCEVExpander that automatically take the SCEVExpander mode into account. We can use the latter variant nearly everywhere, and thus make sure that there is no chance of CanonicalMode mismatch. Fixes https://github.com/llvm/llvm-project/issues/50506. Differential Revision: https://reviews.llvm.org/D129630
Diffstat (limited to 'llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 0c8bf38..8d3dbff 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -2557,6 +2557,15 @@ Value *SCEVExpander::fixupLCSSAFormFor(Instruction *User, unsigned OpIdx) {
return User->getOperand(OpIdx);
}
+bool SCEVExpander::isSafeToExpand(const SCEV *S) const {
+ return llvm::isSafeToExpand(S, SE, CanonicalMode);
+}
+
+bool SCEVExpander::isSafeToExpandAt(const SCEV *S,
+ const Instruction *InsertionPoint) const {
+ return llvm::isSafeToExpandAt(S, InsertionPoint, SE, CanonicalMode);
+}
+
namespace {
// Search for a SCEV subexpression that is not safe to expand. Any expression
// that may expand to a !isSafeToSpeculativelyExecute value is unsafe, namely
@@ -2623,8 +2632,8 @@ bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE, bool CanonicalMode) {
}
bool isSafeToExpandAt(const SCEV *S, const Instruction *InsertionPoint,
- ScalarEvolution &SE) {
- if (!isSafeToExpand(S, SE))
+ ScalarEvolution &SE, bool CanonicalMode) {
+ if (!isSafeToExpand(S, SE, CanonicalMode))
return false;
// We have to prove that the expanded site of S dominates InsertionPoint.
// This is easy when not in the same block, but hard when S is an instruction