Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LVI] Introduce an intersect operation on lattice values
LVI has several separate sources of facts - edge local conditions, recursive queries, assumes, and control independent value facts - which all apply to the same value at the same location. The existing implementation was very conservative about exploiting all of these facts at once. This change introduces an "intersect" function specifically to abstract the action of picking a good set of facts from all of the separate facts given. At the moment, this function is relatively simple (i.e. mostly just reuses the bits which were already there), but even the minor additions reveal the inherent power. For example, JumpThreading is now capable of doing an inductive proof that a particular value is always positive and removing a half range check. I'm currently only using the new intersect function in one place. If folks are happy with the direction of the work, I plan on making a series of small changes without review to replace mergeIn with intersect at all the appropriate places. Differential Revision: http://reviews.llvm.org/D14476 llvm-svn: 259461
- Loading branch information
Showing
3 changed files
with
160 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
llvm/test/Transforms/CorrelatedValuePropagation/conflict.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
; RUN: opt -correlated-propagation -S < %s | FileCheck %s | ||
; Checks that we don't crash on conflicting facts about a value | ||
; (i.e. unreachable code) | ||
|
||
; Test that we can handle conflict edge facts | ||
define i8 @test(i8 %a) { | ||
; CHECK-LABEL: @test | ||
%cmp1 = icmp eq i8 %a, 5 | ||
br i1 %cmp1, label %next, label %exit | ||
next: | ||
%cmp2 = icmp eq i8 %a, 3 | ||
; CHECK: br i1 false, label %dead, label %exit | ||
br i1 %cmp2, label %dead, label %exit | ||
dead: | ||
; CHECK-LABEL: dead: | ||
; CHECK: ret i8 5 | ||
; NOTE: undef, or 3 would be equal valid | ||
ret i8 %a | ||
exit: | ||
ret i8 0 | ||
} | ||
|
||
declare void @llvm.assume(i1) | ||
|
||
; Test that we can handle conflicting assume vs edge facts | ||
define i8 @test2(i8 %a) { | ||
; CHECK-LABEL: @test2 | ||
%cmp1 = icmp eq i8 %a, 5 | ||
call void @llvm.assume(i1 %cmp1) | ||
%cmp2 = icmp eq i8 %a, 3 | ||
; CHECK: br i1 false, label %dead, label %exit | ||
br i1 %cmp2, label %dead, label %exit | ||
dead: | ||
ret i8 %a | ||
exit: | ||
ret i8 0 | ||
} | ||
|
||
define i8 @test3(i8 %a) { | ||
; CHECK-LABEL: @test3 | ||
%cmp1 = icmp eq i8 %a, 5 | ||
br i1 %cmp1, label %dead, label %exit | ||
dead: | ||
%cmp2 = icmp eq i8 %a, 3 | ||
; CHECK: call void @llvm.assume(i1 false) | ||
call void @llvm.assume(i1 %cmp2) | ||
ret i8 %a | ||
exit: | ||
ret i8 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
; RUN: opt -S -jump-threading < %s | FileCheck %s | ||
|
||
define i8 @test(i32 %a, i32 %length) { | ||
; CHECK-LABEL: @test | ||
entry: | ||
; CHECK: br label %backedge | ||
br label %loop | ||
|
||
loop: | ||
; CHECK-LABEL: backedge: | ||
; CHECK: phi i32 | ||
; CHECK: br i1 %cont, label %backedge, label %exit | ||
%iv = phi i32 [0, %entry], [%iv.next, %backedge] | ||
;; We can use an inductive argument to prove %iv is always positive | ||
%cnd = icmp sge i32 %iv, 0 | ||
br i1 %cnd, label %backedge, label %exit | ||
|
||
backedge: | ||
%iv.next = add nsw i32 %iv, 1 | ||
%cont = icmp slt i32 %iv.next, 400 | ||
br i1 %cont, label %loop, label %exit | ||
exit: | ||
ret i8 0 | ||
} | ||
|