1 ; RUN: opt < %s -correlated-propagation -S | FileCheck %s
3 ; Check that debug locations are preserved. For more info see:
4 ; https://llvm.org/docs/SourceLevelDebugging.html#fixing-errors
5 ; RUN: opt < %s -enable-debugify -correlated-propagation -S 2>&1 | \
6 ; RUN: FileCheck %s -check-prefix=DEBUG
7 ; DEBUG: CheckModuleDebugify: PASS
10 define void @test1(i32 %n) {
14 for.cond: ; preds = %for.body, %entry
15 %a = phi i32 [ %n, %entry ], [ %shr, %for.body ]
16 %cmp = icmp sgt i32 %a, 1
17 br i1 %cmp, label %for.body, label %for.end
19 for.body: ; preds = %for.cond
20 ; CHECK: lshr i32 %a, 5
24 for.end: ; preds = %for.cond
28 ;; Negative test to show transform doesn't happen unless n > 0.
30 define void @test2(i32 %n) {
34 for.cond: ; preds = %for.body, %entry
35 %a = phi i32 [ %n, %entry ], [ %shr, %for.body ]
36 %cmp = icmp sgt i32 %a, -2
37 br i1 %cmp, label %for.body, label %for.end
39 for.body: ; preds = %for.cond
40 ; CHECK: ashr i32 %a, 2
44 for.end: ; preds = %for.cond
48 ;; Non looping test case.
50 define void @test3(i32 %n) {
52 %cmp = icmp sgt i32 %n, 0
53 br i1 %cmp, label %bb, label %exit
56 ; CHECK: lshr exact i32 %n, 4
57 %shr = ashr exact i32 %n, 4
64 ; looping case where loop has exactly one block
65 ; at the point of ashr, we know that the operand is always greater than 0,
66 ; because of the guard before it, so we can transform it to lshr.
67 declare void @llvm.experimental.guard(i1,...)
69 define void @test4(i32 %n) {
71 %cmp = icmp sgt i32 %n, 0
72 br i1 %cmp, label %loop, label %exit
75 ; CHECK: lshr i32 %a, 1
76 %a = phi i32 [ %n, %entry ], [ %shr, %loop ]
77 %cond = icmp sgt i32 %a, 2
78 call void(i1,...) @llvm.experimental.guard(i1 %cond) [ "deopt"() ]
80 br i1 %cond, label %loop, label %exit
86 ; same test as above with assume instead of guard.
87 declare void @llvm.assume(i1)
89 define void @test5(i32 %n) {
91 %cmp = icmp sgt i32 %n, 0
92 br i1 %cmp, label %loop, label %exit
95 ; CHECK: lshr i32 %a, 1
96 %a = phi i32 [ %n, %entry ], [ %shr, %loop ]
97 %cond = icmp sgt i32 %a, 4
98 call void @llvm.assume(i1 %cond)
100 %loopcond = icmp sgt i32 %shr, 8
101 br i1 %loopcond, label %loop, label %exit