summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Hahn <florian.hahn@arm.com>2018-05-22 17:38:22 +0000
committerFlorian Hahn <florian.hahn@arm.com>2018-05-22 17:38:22 +0000
commita6e63f176cdf2d7555938fcbb01781d29363feea (patch)
tree6743f63183d605fb8ec685fd51ec2a6210cc6ced
parent63eca15e95adb8e4049cd5b88eeaa37bd9175b6a (diff)
downloadbcm5719-llvm-a6e63f176cdf2d7555938fcbb01781d29363feea.tar.gz
bcm5719-llvm-a6e63f176cdf2d7555938fcbb01781d29363feea.zip
[NewGVN] Fix handling of assumes
This patch fixes two bugs: * test1: Previously assume(a >= 5) concluded that a == 5. That's only valid for assume(a == 5)... * test2: If operands were swapped, additional users were added to the wrong cmp operand. This resulted in an "unsettled iteration" assertion failure. Patch by Nikita Popov Differential Revision: https://reviews.llvm.org/D46974 llvm-svn: 333007
-rw-r--r--llvm/lib/Transforms/Scalar/NewGVN.cpp8
-rw-r--r--llvm/test/Transforms/NewGVN/assumes.ll26
2 files changed, 30 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index 0cf9979b40a..94973c986e9 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -1585,11 +1585,11 @@ NewGVN::performSymbolicPredicateInfoEvaluation(Instruction *I) const {
SwappedOps ? Cmp->getSwappedPredicate() : Cmp->getPredicate();
if (isa<PredicateAssume>(PI)) {
- // If the comparison is true when the operands are equal, then we know the
- // operands are equal, because assumes must always be true.
- if (CmpInst::isTrueWhenEqual(Predicate)) {
+ // If we assume the operands are equal, then they are equal.
+ if (Predicate == CmpInst::ICMP_EQ) {
addPredicateUsers(PI, I);
- addAdditionalUsers(Cmp->getOperand(0), I);
+ addAdditionalUsers(SwappedOps ? Cmp->getOperand(1) : Cmp->getOperand(0),
+ I);
return createVariableOrConstant(FirstOp);
}
}
diff --git a/llvm/test/Transforms/NewGVN/assumes.ll b/llvm/test/Transforms/NewGVN/assumes.ll
new file mode 100644
index 00000000000..065cc0fb62e
--- /dev/null
+++ b/llvm/test/Transforms/NewGVN/assumes.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -newgvn -S | FileCheck %s
+
+; CHECK-LABEL: @test1
+; CHECK: ret i32 %arg
+define i32 @test1(i32 %arg) {
+ %cmp = icmp sge i32 %arg, 5
+ call void @llvm.assume(i1 %cmp)
+ ret i32 %arg
+}
+
+; CHECK-LABEL: @test2
+; CHECK: ret i32 %arg
+define i32 @test2(i32 %arg, i1 %b) {
+ br label %bb
+
+bb:
+ %a = phi i32 [ 1, %0 ], [ 2, %bb ]
+ %cmp = icmp eq i32 %arg, %a
+ call void @llvm.assume(i1 %cmp)
+ br i1 %b, label %bb, label %end
+
+end:
+ ret i32 %arg
+}
+
+declare void @llvm.assume(i1 %cond)
OpenPOWER on IntegriCloud