summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/SCCP.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2017-11-22 03:04:55 +0000
committerDavide Italiano <davide@freebsd.org>2017-11-22 03:04:55 +0000
commit882fbe3d4ca592cdc6be84327ff21d691df5d0d3 (patch)
treedd5d7f7a347b40db530d22e190e12ecdd50c984a /lib/Transforms/Scalar/SCCP.cpp
parentbb324a11f87d8a0542b6c30117e6f4e3c8608031 (diff)
[SCCP] Pick the right lattice value for constants.
After the dataflow algorithm proves that an argument is constant, it replaces it value with the integer constant and drops the lattice value associated to the DEF. e.g. in the example we have @f() that's called twice: call @f(undef, ...) call @f(2, ...) `undef` MEET 2 = 2 so we replace the argument and all its uses with the constant 2. Shortly after, tryToReplaceWithConstantRange() tries to get the lattice value for the argument we just replaced, causing an assertion. This function is a little peculiar as it runs when we're doing replacement and not as part of the solver but still queries the solver. The fix is that of checking whether we replaced the value already and get a temporary lattice value for the constant. Thanks to Zhendong Su for the report! Fixes PR35357. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318817 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 192ba13c598..e5866b4718d 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -1615,8 +1615,15 @@ static bool tryToReplaceWithConstantRange(SCCPSolver &Solver, Value *V) {
if (!Icmp || !Solver.isBlockExecutable(Icmp->getParent()))
continue;
- auto A = Solver.getLatticeValueFor(Icmp->getOperand(0));
- auto B = Solver.getLatticeValueFor(Icmp->getOperand(1));
+ auto getIcmpLatticeValue = [&](Value *Op) {
+ if (auto *C = dyn_cast<Constant>(Op))
+ return ValueLatticeElement::get(C);
+ return Solver.getLatticeValueFor(Op);
+ };
+
+ ValueLatticeElement A = getIcmpLatticeValue(Icmp->getOperand(0));
+ ValueLatticeElement B = getIcmpLatticeValue(Icmp->getOperand(1));
+
Constant *C = nullptr;
if (A.satisfiesPredicate(Icmp->getPredicate(), B))
C = ConstantInt::getTrue(Icmp->getType());