1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=correlated-propagation -S < %s | FileCheck %s
5 declare void @use_ptr(ptr)
7 ; test requires a mix of context sensative refinement, and analysis
8 ; of the originating IR pattern. Neither part is enough in isolation.
9 define void @test1(i1 %c, i1 %c2) {
10 ; CHECK-LABEL: @test1(
11 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 -1, i64 1
12 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 [[SEL]], i64 0
13 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[SEL2]], 0
14 ; CHECK-NEXT: br i1 [[CMP]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
16 ; CHECK-NEXT: call void @use() [ "deopt"(i64 1) ]
17 ; CHECK-NEXT: ret void
19 ; CHECK-NEXT: ret void
21 %sel = select i1 %c, i64 -1, i64 1
22 %sel2 = select i1 %c2, i64 %sel, i64 0
23 %cmp = icmp sgt i64 %sel2, 0
24 br i1 %cmp, label %taken, label %untaken
26 call void @use() ["deopt" (i64 %sel2)]
32 declare void @llvm.assume(i1)
33 declare void @llvm.experimental.guard(i1,...)
35 ; Same as test1, but with assume not branch
36 define void @test1_assume(i1 %c, i1 %c2) {
37 ; CHECK-LABEL: @test1_assume(
38 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 -1, i64 1
39 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 [[SEL]], i64 0
40 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[SEL2]], 0
41 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
42 ; CHECK-NEXT: call void @use() [ "deopt"(i64 1) ]
43 ; CHECK-NEXT: ret void
45 %sel = select i1 %c, i64 -1, i64 1
46 %sel2 = select i1 %c2, i64 %sel, i64 0
47 %cmp = icmp sgt i64 %sel2, 0
48 call void @llvm.assume(i1 %cmp)
49 call void @use() ["deopt" (i64 %sel2)]
53 ; Same as test1, but with guard not branch
54 define void @test1_guard(i1 %c, i1 %c2) {
55 ; CHECK-LABEL: @test1_guard(
56 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 -1, i64 1
57 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 [[SEL]], i64 0
58 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[SEL2]], 0
59 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 [[CMP]]) [ "deopt"(i64 [[SEL2]]) ]
60 ; CHECK-NEXT: call void @use() [ "deopt"(i64 1) ]
61 ; CHECK-NEXT: ret void
63 %sel = select i1 %c, i64 -1, i64 1
64 %sel2 = select i1 %c2, i64 %sel, i64 0
65 %cmp = icmp sgt i64 %sel2, 0
66 call void (i1, ...) @llvm.experimental.guard(i1 %cmp) ["deopt" (i64 %sel2)]
67 call void @use() ["deopt" (i64 %sel2)]
71 ;; The rest of these are slight variations on the patterns
72 ;; producing 1 of several adjacent constants to test generality
74 define void @test2(i1 %c, i1 %c2) {
75 ; CHECK-LABEL: @test2(
76 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 0, i64 1
77 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 [[SEL]], i64 -1
78 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i64 [[SEL2]], 0
79 ; CHECK-NEXT: br i1 [[CMP]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
81 ; CHECK-NEXT: call void @use() [ "deopt"(i64 1) ]
82 ; CHECK-NEXT: ret void
84 ; CHECK-NEXT: ret void
86 %sel = select i1 %c, i64 0, i64 1
87 %sel2 = select i1 %c2, i64 %sel, i64 -1
88 %cmp = icmp sgt i64 %sel2, 0
89 br i1 %cmp, label %taken, label %untaken
91 call void @use() ["deopt" (i64 %sel2)]
96 define void @test3(i1 %c, i1 %c2) {
97 ; CHECK-LABEL: @test3(
98 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 0, i64 1
99 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 [[SEL]], i64 2
100 ; CHECK-NEXT: [[CMP:%.*]] = icmp samesign ugt i64 [[SEL2]], 1
101 ; CHECK-NEXT: br i1 [[CMP]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
103 ; CHECK-NEXT: call void @use() [ "deopt"(i64 2) ]
104 ; CHECK-NEXT: ret void
106 ; CHECK-NEXT: ret void
108 %sel = select i1 %c, i64 0, i64 1
109 %sel2 = select i1 %c2, i64 %sel, i64 2
110 %cmp = icmp sgt i64 %sel2, 1
111 br i1 %cmp, label %taken, label %untaken
113 call void @use() ["deopt" (i64 %sel2)]
119 define void @test4(i1 %c, i1 %c2) {
120 ; CHECK-LABEL: @test4(
121 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[C:%.*]], i64 0, i64 1
122 ; CHECK-NEXT: [[SEL2:%.*]] = select i1 [[C2:%.*]], i64 0, i64 1
123 ; CHECK-NEXT: [[ADD1:%.*]] = add nuw nsw i64 0, [[SEL]]
124 ; CHECK-NEXT: [[ADD2:%.*]] = add nuw nsw i64 [[ADD1]], [[SEL2]]
125 ; CHECK-NEXT: [[CMP:%.*]] = icmp samesign ugt i64 [[ADD2]], 1
126 ; CHECK-NEXT: br i1 [[CMP]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
128 ; CHECK-NEXT: call void @use() [ "deopt"(i64 2) ]
129 ; CHECK-NEXT: ret void
131 ; CHECK-NEXT: ret void
133 %sel = select i1 %c, i64 0, i64 1
134 %sel2 = select i1 %c2, i64 0, i64 1
135 %add1 = add i64 0, %sel
136 %add2 = add i64 %add1, %sel2
137 %cmp = icmp sgt i64 %add2, 1
138 br i1 %cmp, label %taken, label %untaken
140 call void @use() ["deopt" (i64 %add2)]
147 define void @test5(i64 %a, ptr nonnull %p) {
148 ; CHECK-LABEL: @test5(
149 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[A:%.*]], 0
150 ; CHECK-NEXT: br i1 [[CMP]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
152 ; CHECK-NEXT: call void @use_ptr(ptr nonnull [[P:%.*]]) [ "deopt"(i64 0) ]
153 ; CHECK-NEXT: ret void
155 ; CHECK-NEXT: ret void
157 %cmp = icmp eq i64 %a, 0
158 br i1 %cmp, label %taken, label %untaken
160 call void @use_ptr(ptr %p) ["deopt" (i64 %a)]