llvm.org GIT mirror llvm / eae2e16
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333007 91177308-0d34-0410-b5e6-96231b3b80d8 Florian Hahn 1 year, 6 months ago
2 changed file(s) with 30 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
15841584 SwappedOps ? Cmp->getSwappedPredicate() : Cmp->getPredicate();
15851585
15861586 if (isa(PI)) {
1587 // If the comparison is true when the operands are equal, then we know the
1588 // operands are equal, because assumes must always be true.
1589 if (CmpInst::isTrueWhenEqual(Predicate)) {
1587 // If we assume the operands are equal, then they are equal.
1588 if (Predicate == CmpInst::ICMP_EQ) {
15901589 addPredicateUsers(PI, I);
1591 addAdditionalUsers(Cmp->getOperand(0), I);
1590 addAdditionalUsers(SwappedOps ? Cmp->getOperand(1) : Cmp->getOperand(0),
1591 I);
15921592 return createVariableOrConstant(FirstOp);
15931593 }
15941594 }
0 ; RUN: opt < %s -newgvn -S | FileCheck %s
1
2 ; CHECK-LABEL: @test1
3 ; CHECK: ret i32 %arg
4 define i32 @test1(i32 %arg) {
5 %cmp = icmp sge i32 %arg, 5
6 call void @llvm.assume(i1 %cmp)
7 ret i32 %arg
8 }
9
10 ; CHECK-LABEL: @test2
11 ; CHECK: ret i32 %arg
12 define i32 @test2(i32 %arg, i1 %b) {
13 br label %bb
14
15 bb:
16 %a = phi i32 [ 1, %0 ], [ 2, %bb ]
17 %cmp = icmp eq i32 %arg, %a
18 call void @llvm.assume(i1 %cmp)
19 br i1 %b, label %bb, label %end
20
21 end:
22 ret i32 %arg
23 }
24
25 declare void @llvm.assume(i1 %cond)