summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/Scalar/SCCP.cpp11
-rw-r--r--llvm/test/Transforms/SCCP/pr35357.ll24
2 files changed, 33 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index 192ba13c598..e5866b4718d 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/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());
diff --git a/llvm/test/Transforms/SCCP/pr35357.ll b/llvm/test/Transforms/SCCP/pr35357.ll
new file mode 100644
index 00000000000..fda123b76f7
--- /dev/null
+++ b/llvm/test/Transforms/SCCP/pr35357.ll
@@ -0,0 +1,24 @@
+; RUN: opt -S %s -ipsccp | FileCheck %s
+
+@a = internal global i32 2
+
+define i32 @patatino() {
+; CHECK: @patatino(
+; CHECK: call void @f(i32 undef, i32 1)
+; CHECK-NEXT: call void @f(i32 2, i32 0)
+; CHECK-NEXT: ret i32 0
+entry:
+ call void @f(i32 undef, i32 1)
+ %0 = load i32, i32* @a
+ call void @f(i32 %0, i32 0)
+ ret i32 0
+}
+
+define internal void @f(i32 %c, i32 %d) {
+; CHECK: @f(
+; CHECK: ret void
+;
+entry:
+ %cmp = icmp ne i32 %c, %d
+ ret void
+}
OpenPOWER on IntegriCloud