[PATCH] D46974: [NewGVN] Fix handling of assumes
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 22 10:42:44 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL333007: [NewGVN] Fix handling of assumes (authored by fhahn, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D46974?vs=147160&id=148053#toc
Repository:
rL LLVM
https://reviews.llvm.org/D46974
Files:
llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
llvm/trunk/test/Transforms/NewGVN/assumes.ll
Index: llvm/trunk/test/Transforms/NewGVN/assumes.ll
===================================================================
--- llvm/trunk/test/Transforms/NewGVN/assumes.ll
+++ llvm/trunk/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)
Index: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
@@ -1585,11 +1585,11 @@
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);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46974.148053.patch
Type: text/x-patch
Size: 1657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180522/37365e0e/attachment.bin>
More information about the llvm-commits
mailing list