1 ; RUN: opt < %s -correlated-propagation -S | FileCheck %s
4 define void @test0(i32 %n) {
8 for.cond: ; preds = %for.body, %entry
9 %j.0 = phi i32 [ %n, %entry ], [ %div, %for.body ]
10 %cmp = icmp sgt i32 %j.0, 1
11 br i1 %cmp, label %for.body, label %for.end
13 for.body: ; preds = %for.cond
14 ; CHECK: %div1 = udiv i32 %j.0, 2
15 %div = sdiv i32 %j.0, 2
18 for.end: ; preds = %for.cond
22 ; CHECK-LABEL: @test1(
23 define void @test1(i32 %n) {
27 for.cond: ; preds = %for.body, %entry
28 %j.0 = phi i32 [ %n, %entry ], [ %div, %for.body ]
29 %cmp = icmp sgt i32 %j.0, -2
30 br i1 %cmp, label %for.body, label %for.end
32 for.body: ; preds = %for.cond
33 ; CHECK: %div = sdiv i32 %j.0, 2
34 %div = sdiv i32 %j.0, 2
37 for.end: ; preds = %for.cond
41 ; CHECK-LABEL: @test2(
42 define void @test2(i32 %n) {
44 %cmp = icmp sgt i32 %n, 1
45 br i1 %cmp, label %bb, label %exit
48 ; CHECK: %div1 = udiv i32 %n, 2
56 ; looping case where loop has exactly one block
57 ; at the point of sdiv, we know that %a is always greater than 0,
58 ; because of the guard before it, so we can transform it to udiv.
59 declare void @llvm.experimental.guard(i1,...)
61 define void @test4(i32 %n) {
63 %cmp = icmp sgt i32 %n, 0
64 br i1 %cmp, label %loop, label %exit
67 ; CHECK: udiv i32 %a, 6
68 %a = phi i32 [ %n, %entry ], [ %div, %loop ]
69 %cond = icmp sgt i32 %a, 4
70 call void(i1,...) @llvm.experimental.guard(i1 %cond) [ "deopt"() ]
72 br i1 %cond, label %loop, label %exit
78 ; same test as above with assume instead of guard.
79 declare void @llvm.assume(i1)
81 define void @test5(i32 %n) {
83 %cmp = icmp sgt i32 %n, 0
84 br i1 %cmp, label %loop, label %exit
87 ; CHECK: udiv i32 %a, 6
88 %a = phi i32 [ %n, %entry ], [ %div, %loop ]
89 %cond = icmp sgt i32 %a, 4
90 call void @llvm.assume(i1 %cond)
92 %loopcond = icmp sgt i32 %div, 8
93 br i1 %loopcond, label %loop, label %exit