aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-05-31 21:22:21 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-06-04 20:57:22 +0200
commit14f350daf290e9d7f3eef700acf930d8b0887007 (patch)
treeaeffae7345e168b5e3af489fa7260030e9c1e320 /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
parent8d581857d77129b5a63515ca6794bba88418e0fd (diff)
downloadllvm-14f350daf290e9d7f3eef700acf930d8b0887007.zip
llvm-14f350daf290e9d7f3eef700acf930d8b0887007.tar.gz
llvm-14f350daf290e9d7f3eef700acf930d8b0887007.tar.bz2
[IndVars] Don't forget value when inferring nowrap flags
When SimplifyIndVars infers IR nowrap flags from SCEV, this may happen in two ways: Either nowrap flags were already present in SCEV and just get transferred to IR. Or zero/sign extension of addrecs infers additional nowrap flags, and those get transferred to IR. In the latter case, calling forgetValue() ensures that the newly inferred nowrap flags get propagated to any other SCEV expressions based on the addrec. However, the invalidation can also have a major compile-time effect in some cases. For https://bugs.llvm.org/show_bug.cgi?id=50384 with n=512 compile- time drops from 7.1s to 0.8s without this invalidation. At the same time, removing the invalidation doesn't affect any codegen in test-suite. Differential Revision: https://reviews.llvm.org/D103424
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyIndVar.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index d4f325c..246bc0a 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -772,17 +772,20 @@ bool SimplifyIndvar::strengthenOverflowingOperation(BinaryOperator *BO,
if (!BO->hasNoUnsignedWrap() &&
willNotOverflow(SE, BO->getOpcode(), /* Signed */ false, LHS, RHS)) {
BO->setHasNoUnsignedWrap();
- SE->forgetValue(BO);
Changed = true;
}
if (!BO->hasNoSignedWrap() &&
willNotOverflow(SE, BO->getOpcode(), /* Signed */ true, LHS, RHS)) {
BO->setHasNoSignedWrap();
- SE->forgetValue(BO);
Changed = true;
}
+ // The willNotOverflow() check might infer additional nowrap flags on addrecs
+ // while performing zero/sign extensions. We could call forgetValue() here
+ // to make sure those flags also propagate to any other SCEV expressions
+ // based on the addrec. However, this can have pathological compile-time
+ // impact, see https://bugs.llvm.org/show_bug.cgi?id=50384.
return Changed;
}