2017-07-28 10:57:43 +08:00
|
|
|
; RUN: opt < %s -jump-threading -print-lvi-after-jump-threading -disable-output 2>&1 | FileCheck %s
|
2017-03-23 03:27:12 +08:00
|
|
|
|
|
|
|
; Testing LVI cache after jump-threading
|
|
|
|
|
|
|
|
; Jump-threading transforms the IR below to one where
|
|
|
|
; loop and backedge basic blocks are merged into one.
|
|
|
|
; basic block (named backedge) with the branch being:
|
|
|
|
; %cont = icmp slt i32 %iv.next, 400
|
|
|
|
; br i1 %cont, label %backedge, label %exit
|
|
|
|
define i8 @test1(i32 %a, i32 %length) {
|
|
|
|
; CHECK-LABEL: LVI for function 'test1':
|
|
|
|
entry:
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-LABEL: entry:
|
|
|
|
; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: overdefined
|
|
|
|
; CHECK-NEXT: ; LatticeVal for: 'i32 %length' is: overdefined
|
2017-03-23 03:27:12 +08:00
|
|
|
br label %loop
|
2017-06-07 03:25:31 +08:00
|
|
|
|
2017-03-23 03:27:12 +08:00
|
|
|
; CHECK-LABEL: backedge:
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: 'i32 %a' is: overdefined
|
|
|
|
; CHECK-NEXT: ; LatticeVal for: 'i32 %length' is: overdefined
|
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%backedge' is: constantrange<0, 400>
|
2018-01-13 05:06:48 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%exit' is: constantrange<399, 400>
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
|
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %iv.next = add nsw i32 %iv, 1' in BB: '%backedge' is: constantrange<1, 401>
|
2018-01-13 05:06:48 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %iv.next = add nsw i32 %iv, 1' in BB: '%exit' is: constantrange<400, 401>
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: %iv.next = add nsw i32 %iv, 1
|
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %cont = icmp slt i32 %iv.next, 400' in BB: '%backedge' is: overdefined
|
2018-01-13 05:06:48 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %cont = icmp slt i32 %iv.next, 400' in BB: '%exit' is: constantrange<0, -1>
|
2017-03-23 03:27:12 +08:00
|
|
|
; CHECK-NEXT: %cont = icmp slt i32 %iv.next, 400
|
|
|
|
; CHECK-NOT: loop
|
|
|
|
loop:
|
|
|
|
%iv = phi i32 [0, %entry], [%iv.next, %backedge]
|
|
|
|
%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
|
|
|
|
}
|
|
|
|
|
|
|
|
; Here JT does not transform the code, but LVICache is populated during the processing of blocks.
|
|
|
|
define i8 @test2(i32 %n) {
|
|
|
|
; CHECK-LABEL: LVI for function 'test2':
|
|
|
|
; CHECK-LABEL: entry:
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: 'i32 %n' is: overdefined
|
2017-03-23 03:27:12 +08:00
|
|
|
; CHECK-NEXT: br label %loop
|
|
|
|
entry:
|
|
|
|
br label %loop
|
|
|
|
|
|
|
|
; CHECK-LABEL: loop:
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: 'i32 %n' is: overdefined
|
2019-10-23 23:38:34 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%loop' is: constantrange<0, 400>
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-DAG: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%backedge' is: constantrange<0, -2147483648>
|
2019-10-23 23:38:34 +08:00
|
|
|
; CHECK-DAG: ; LatticeVal for: ' %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]' in BB: '%exit' is: constantrange<0, -2147483648>
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: %iv = phi i32 [ 0, %entry ], [ %iv.next, %backedge ]
|
2017-03-23 03:27:12 +08:00
|
|
|
loop:
|
|
|
|
%iv = phi i32 [0, %entry], [%iv.next, %backedge]
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %iv2 = phi i32 [ %n, %entry ], [ %iv2.next, %backedge ]' in BB: '%loop' is: overdefined
|
|
|
|
; CHECK-DAG: ; LatticeVal for: ' %iv2 = phi i32 [ %n, %entry ], [ %iv2.next, %backedge ]' in BB: '%backedge' is: constantrange<1, -2147483648>
|
|
|
|
; CHECK-DAG: ; LatticeVal for: ' %iv2 = phi i32 [ %n, %entry ], [ %iv2.next, %backedge ]' in BB: '%exit' is: overdefined
|
|
|
|
; CHECK-NEXT: %iv2 = phi i32 [ %n, %entry ], [ %iv2.next, %backedge ]
|
2017-03-23 03:27:12 +08:00
|
|
|
%iv2 = phi i32 [%n, %entry], [%iv2.next, %backedge]
|
2017-06-07 03:25:31 +08:00
|
|
|
|
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %cnd1 = icmp sge i32 %iv, 0' in BB: '%loop' is: overdefined
|
|
|
|
; CHECK-DAG: ; LatticeVal for: ' %cnd1 = icmp sge i32 %iv, 0' in BB: '%backedge' is: overdefined
|
|
|
|
; CHECK-DAG: ; LatticeVal for: ' %cnd1 = icmp sge i32 %iv, 0' in BB: '%exit' is: overdefined
|
|
|
|
; CHECK-NEXT: %cnd1 = icmp sge i32 %iv, 0
|
2017-03-23 03:27:12 +08:00
|
|
|
%cnd1 = icmp sge i32 %iv, 0
|
|
|
|
%cnd2 = icmp sgt i32 %iv2, 0
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK: %cnd2 = icmp sgt i32 %iv2, 0
|
2018-11-21 13:24:12 +08:00
|
|
|
; CHECK: ; LatticeVal for: ' %cnd = and i1 %cnd1, %cnd2' in BB: '%loop' is: constantrange<-1, -1>
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-DAG: ; LatticeVal for: ' %cnd = and i1 %cnd1, %cnd2' in BB: '%backedge' is: constantrange<-1, 0>
|
|
|
|
; CHECK-DAG: ; LatticeVal for: ' %cnd = and i1 %cnd1, %cnd2' in BB: '%exit' is: overdefined
|
|
|
|
; CHECK-NEXT: %cnd = and i1 %cnd1, %cnd2
|
2017-03-23 03:27:12 +08:00
|
|
|
%cnd = and i1 %cnd1, %cnd2
|
|
|
|
br i1 %cnd, label %backedge, label %exit
|
|
|
|
|
|
|
|
; CHECK-LABEL: backedge:
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: 'i32 %n' is: overdefined
|
2019-10-23 23:38:34 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %iv.next = add nsw i32 %iv, 1' in BB: '%backedge' is: constantrange<1, -2147483648>
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: %iv.next = add nsw i32 %iv, 1
|
2017-03-23 03:27:12 +08:00
|
|
|
backedge:
|
|
|
|
%iv.next = add nsw i32 %iv, 1
|
|
|
|
%iv2.next = sub nsw i32 %iv2, 1
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK: ; LatticeVal for: ' %cont1 = icmp slt i32 %iv.next, 400' in BB: '%backedge' is: overdefined
|
|
|
|
; CHECK-NEXT: %cont1 = icmp slt i32 %iv.next, 400
|
2017-03-23 03:27:12 +08:00
|
|
|
%cont1 = icmp slt i32 %iv.next, 400
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %cont2 = icmp sgt i32 %iv2.next, 0' in BB: '%backedge' is: overdefined
|
|
|
|
; CHECK-NEXT: %cont2 = icmp sgt i32 %iv2.next, 0
|
2017-03-23 03:27:12 +08:00
|
|
|
%cont2 = icmp sgt i32 %iv2.next, 0
|
2018-11-21 13:24:12 +08:00
|
|
|
; CHECK-NEXT: ; LatticeVal for: ' %cont = and i1 %cont1, %cont2' in BB: '%backedge' is: constantrange<-1, -1>
|
2017-06-07 03:25:31 +08:00
|
|
|
; CHECK-NEXT: %cont = and i1 %cont1, %cont2
|
2017-03-23 03:27:12 +08:00
|
|
|
%cont = and i1 %cont1, %cont2
|
|
|
|
br i1 %cont, label %loop, label %exit
|
|
|
|
|
|
|
|
exit:
|
|
|
|
ret i8 0
|
|
|
|
}
|
2017-06-19 23:23:33 +08:00
|
|
|
|
|
|
|
; Merging cont block into do block. Make sure that we do not incorrectly have the cont
|
|
|
|
; LVI info as LVI info for the beginning of do block. LVI info for %i is Range[0,1)
|
|
|
|
; at beginning of cont Block, which is incorrect at the beginning of do block.
|
|
|
|
define i32 @test3(i32 %i, i1 %f, i32 %n) {
|
|
|
|
; CHECK-LABEL: LVI for function 'test3':
|
|
|
|
; CHECK-LABEL: entry
|
|
|
|
; CHECK: ; LatticeVal for: 'i32 %i' is: overdefined
|
2019-10-23 23:38:34 +08:00
|
|
|
; CHECK: %c = icmp ne i32 %i, -2134
|
2017-06-19 23:23:33 +08:00
|
|
|
; CHECK: br i1 %c, label %cont, label %exit
|
|
|
|
entry:
|
|
|
|
%c = icmp ne i32 %i, -2134
|
|
|
|
br i1 %c, label %do, label %exit
|
|
|
|
|
|
|
|
exit:
|
|
|
|
%c1 = icmp ne i32 %i, -42
|
|
|
|
br i1 %c1, label %exit2, label %exit
|
|
|
|
|
|
|
|
; CHECK-LABEL: cont:
|
|
|
|
; Here cont is merged to do and i is any value except -2134.
|
|
|
|
; i is not the single value: zero.
|
|
|
|
; CHECK-NOT: ; LatticeVal for: 'i32 %i' is: constantrange<0, 1>
|
|
|
|
; CHECK: ; LatticeVal for: 'i32 %i' is: constantrange<-2133, -2134>
|
|
|
|
; CHECK: ; LatticeVal for: ' %cond.0 = icmp sgt i32 %i, 0' in BB: '%cont' is: overdefined
|
|
|
|
; CHECK: %cond.0 = icmp sgt i32 %i, 0
|
|
|
|
; CHECK: %consume = call i32 @consume
|
|
|
|
; CHECK: %cond = icmp eq i32 %i, 0
|
|
|
|
; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 %cond)
|
|
|
|
; CHECK: %cond.3 = icmp sgt i32 %i, %n
|
|
|
|
; CHECK: br i1 %cond.3, label %exit2, label %exit
|
|
|
|
cont:
|
|
|
|
%cond.3 = icmp sgt i32 %i, %n
|
|
|
|
br i1 %cond.3, label %exit2, label %exit
|
|
|
|
|
|
|
|
do:
|
|
|
|
%cond.0 = icmp sgt i32 %i, 0
|
|
|
|
%consume = call i32 @consume(i1 %cond.0)
|
|
|
|
%cond = icmp eq i32 %i, 0
|
|
|
|
call void (i1, ...) @llvm.experimental.guard(i1 %cond) [ "deopt"() ]
|
|
|
|
%cond.2 = icmp sgt i32 %i, 0
|
|
|
|
br i1 %cond.2, label %exit, label %cont
|
2019-10-23 23:38:34 +08:00
|
|
|
|
2017-06-19 23:23:33 +08:00
|
|
|
exit2:
|
|
|
|
; CHECK-LABEL: exit2:
|
|
|
|
; LatticeVal for: 'i32 %i' is: constantrange<-2134, 1>
|
|
|
|
ret i32 30
|
|
|
|
}
|
|
|
|
|
|
|
|
; FIXME: We should be able to merge cont into do.
|
|
|
|
; When we do so, LVI for cont cannot be the one for the merged do block.
|
|
|
|
define i32 @test4(i32 %i, i1 %f, i32 %n) {
|
|
|
|
; CHECK-LABEL: LVI for function 'test4':
|
|
|
|
entry:
|
|
|
|
%c = icmp ne i32 %i, -2134
|
|
|
|
br i1 %c, label %do, label %exit
|
|
|
|
|
|
|
|
exit: ; preds = %do, %cont, %exit, %entry
|
|
|
|
%c1 = icmp ne i32 %i, -42
|
|
|
|
br i1 %c1, label %exit2, label %exit
|
|
|
|
|
|
|
|
cont: ; preds = %do
|
|
|
|
; CHECK-LABEL: cont:
|
|
|
|
; CHECK: ; LatticeVal for: 'i1 %f' is: constantrange<-1, 0>
|
|
|
|
; CHECK: call void @dummy(i1 %f)
|
|
|
|
call void @dummy(i1 %f)
|
|
|
|
br label %exit2
|
|
|
|
|
|
|
|
do: ; preds = %entry
|
|
|
|
; CHECK-LABEL: do:
|
|
|
|
; CHECK: ; LatticeVal for: 'i1 %f' is: overdefined
|
|
|
|
; CHECK: call void @dummy(i1 %f)
|
|
|
|
; CHECK: br i1 %cond, label %exit, label %cont
|
|
|
|
call void @dummy(i1 %f)
|
|
|
|
%consume = call i32 @exit()
|
|
|
|
call void @llvm.assume(i1 %f)
|
|
|
|
%cond = icmp eq i1 %f, false
|
|
|
|
br i1 %cond, label %exit, label %cont
|
|
|
|
|
|
|
|
exit2: ; preds = %cont, %exit
|
|
|
|
ret i32 30
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i32 @exit()
|
|
|
|
declare i32 @consume(i1)
|
|
|
|
declare void @llvm.assume(i1) nounwind
|
|
|
|
declare void @dummy(i1) nounwind
|
|
|
|
declare void @llvm.experimental.guard(i1, ...)
|