1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -correlated-propagation -S < %s | FileCheck %s
5 ; test requires a mix of context sensative refinement, and analysis
6 ; of the originating IR pattern. Neither part is enough in isolation.
7 define void @test1(i1 %c, i1 %c2) {
9 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 -1, i64 1
10 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 [[SEL]], i64 0
11 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[SEL2]], 0
12 ; CHECK-NEXT: br i1 [[CMP]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
14 ; CHECK-NEXT: call void @use() [ "deopt"(i64 1) ]
15 ; CHECK-NEXT: ret void
17 ; CHECK-NEXT: ret void
19 %sel = select i1 %c, i64 -1, i64 1
20 %sel2 = select i1 %c2, i64 %sel, i64 0
21 %cmp = icmp sgt i64 %sel2, 0
22 br i1 %cmp, label %taken, label %untaken
24 call void @use() ["deopt" (i64 %sel2)]
30 declare void @llvm.assume(i1)
31 declare void @llvm.experimental.guard(i1,...)
33 ; Same as test1, but with assume not branch
34 define void @test1_assume(i1 %c, i1 %c2) {
35 ; CHECK-LABEL: @test1_assume(
36 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 -1, i64 1
37 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 [[SEL]], i64 0
38 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[SEL2]], 0
39 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
40 ; CHECK-NEXT: call void @use() [ "deopt"(i64 1) ]
41 ; CHECK-NEXT: ret void
43 %sel = select i1 %c, i64 -1, i64 1
44 %sel2 = select i1 %c2, i64 %sel, i64 0
45 %cmp = icmp sgt i64 %sel2, 0
46 call void @llvm.assume(i1 %cmp)
47 call void @use() ["deopt" (i64 %sel2)]
51 ; Same as test1, but with guard not branch
52 define void @test1_guard(i1 %c, i1 %c2) {
53 ; CHECK-LABEL: @test1_guard(
54 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 -1, i64 1
55 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 [[SEL]], i64 0
56 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[SEL2]], 0
57 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[CMP]]) [ "deopt"(i64 [[SEL2]]) ]
58 ; CHECK-NEXT: call void @use() [ "deopt"(i64 1) ]
59 ; CHECK-NEXT: ret void
61 %sel = select i1 %c, i64 -1, i64 1
62 %sel2 = select i1 %c2, i64 %sel, i64 0
63 %cmp = icmp sgt i64 %sel2, 0
64 call void (i1, ...) @llvm.experimental.guard(i1 %cmp) ["deopt" (i64 %sel2)]
65 call void @use() ["deopt" (i64 %sel2)]
69 ;; The rest of these are slight variations on the patterns
70 ;; producing 1 of several adjacent constants to test generality
72 define void @test2(i1 %c, i1 %c2) {
73 ; CHECK-LABEL: @test2(
74 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 0, i64 1
75 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 [[SEL]], i64 -1
76 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[SEL2]], 0
77 ; CHECK-NEXT: br i1 [[CMP]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
79 ; CHECK-NEXT: call void @use() [ "deopt"(i64 1) ]
80 ; CHECK-NEXT: ret void
82 ; CHECK-NEXT: ret void
84 %sel = select i1 %c, i64 0, i64 1
85 %sel2 = select i1 %c2, i64 %sel, i64 -1
86 %cmp = icmp sgt i64 %sel2, 0
87 br i1 %cmp, label %taken, label %untaken
89 call void @use() ["deopt" (i64 %sel2)]
94 define void @test3(i1 %c, i1 %c2) {
95 ; CHECK-LABEL: @test3(
96 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 0, i64 1
97 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 [[SEL]], i64 2
98 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[SEL2]], 1
99 ; CHECK-NEXT: br i1 [[CMP]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
101 ; CHECK-NEXT: call void @use() [ "deopt"(i64 2) ]
102 ; CHECK-NEXT: ret void
104 ; CHECK-NEXT: ret void
106 %sel = select i1 %c, i64 0, i64 1
107 %sel2 = select i1 %c2, i64 %sel, i64 2
108 %cmp = icmp sgt i64 %sel2, 1
109 br i1 %cmp, label %taken, label %untaken
111 call void @use() ["deopt" (i64 %sel2)]
117 define void @test4(i1 %c, i1 %c2) {
118 ; CHECK-LABEL: @test4(
119 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 0, i64 1
120 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 0, i64 1
121 ; CHECK-NEXT: [[ADD1:%.*]] = add nuw nsw i64 0, [[SEL]]
122 ; CHECK-NEXT: [[ADD2:%.*]] = add nuw nsw i64 [[ADD1]], [[SEL2]]
123 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[ADD2]], 1
124 ; CHECK-NEXT: br i1 [[CMP]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
126 ; CHECK-NEXT: call void @use() [ "deopt"(i64 2) ]
127 ; CHECK-NEXT: ret void
129 ; CHECK-NEXT: ret void
131 %sel = select i1 %c, i64 0, i64 1
132 %sel2 = select i1 %c2, i64 0, i64 1
133 %add1 = add i64 0, %sel
134 %add2 = add i64 %add1, %sel2
135 %cmp = icmp sgt i64 %add2, 1
136 br i1 %cmp, label %taken, label %untaken
138 call void @use() ["deopt" (i64 %add2)]