1 ; RUN: opt < %s -correlated-propagation -S | FileCheck %s
3 ; CHECK-LABEL: @simple(
4 define i8 @simple(i1) {
6 %s = select i1 %0, i8 0, i8 1
7 br i1 %0, label %then, label %else
11 %a = phi i8 [ %s, %entry ]
16 %b = phi i8 [ %s, %entry ]
21 define void @loop(i32) {
26 %idx = phi i32 [ %0, %entry ], [ %sel, %loop ]
27 ; CHECK: %idx = phi i32 [ %0, %entry ], [ %2, %loop ]
28 %1 = icmp eq i32 %idx, 0
30 %sel = select i1 %1, i32 0, i32 %2
31 br i1 %1, label %out, label %loop
37 ; CHECK-LABEL: @not_correlated(
38 define i8 @not_correlated(i1, i1) {
40 %s = select i1 %0, i8 0, i8 1
41 br i1 %1, label %then, label %else
45 %a = phi i8 [ %s, %entry ]
50 %b = phi i8 [ %s, %entry ]
54 @c = global i32 0, align 4
55 @b = global i32 0, align 4
57 ; CHECK-LABEL: @PR23752(
58 define i32 @PR23752() {
63 %phi = phi i32 [ 0, %entry ], [ %sel, %for.body ]
64 %sel = select i1 icmp sgt (i32* @b, i32* @c), i32 %phi, i32 1
65 %cmp = icmp ne i32 %sel, 1
66 br i1 %cmp, label %for.body, label %if.end
68 ; CHECK: %[[sel:.*]] = select i1 icmp sgt (i32* @b, i32* @c), i32 0, i32 1
69 ; CHECK-NEXT: %[[cmp:.*]] = icmp ne i32 %[[sel]], 1
70 ; CHECK-NEXT: br i1 %[[cmp]]
77 define i1 @test1(i32* %p, i1 %unknown) {
79 %pval = load i32, i32* %p
80 %cmp1 = icmp slt i32 %pval, 255
81 br i1 %cmp1, label %next, label %exit
84 %min = select i1 %unknown, i32 %pval, i32 5
85 ;; TODO: This pointless branch shouldn't be neccessary
90 %res = icmp eq i32 %min, 255
99 ; Check that we take a conservative meet
100 define i1 @test2(i32* %p, i32 %qval, i1 %unknown) {
102 %pval = load i32, i32* %p
103 %cmp1 = icmp slt i32 %pval, 255
104 br i1 %cmp1, label %next, label %exit
107 %min = select i1 %unknown, i32 %pval, i32 %qval
108 ;; TODO: This pointless branch shouldn't be neccessary
113 %res = icmp eq i32 %min, 255
122 ; Same as @test2, but for the opposite select input
123 define i1 @test3(i32* %p, i32 %qval, i1 %unknown) {
125 %pval = load i32, i32* %p
126 %cmp1 = icmp slt i32 %pval, 255
127 br i1 %cmp1, label %next, label %exit
130 %min = select i1 %unknown, i32 %qval, i32 %pval
131 ;; TODO: This pointless branch shouldn't be neccessary
136 %res = icmp eq i32 %min, 255
145 ; Conflicting constants (i.e. isOverdefined result)
146 ; NOTE: Using doubles in this version is a bit of a hack. This
147 ; is to get around the fact that all integers (including constants
148 ; and non-constants) are actually represented as constant-ranges.
149 define i1 @test4(i32* %p, i32 %qval, i1 %unknown) {
151 %pval = load i32, i32* %p
152 %cmp1 = icmp slt i32 %pval, 255
153 br i1 %cmp1, label %next, label %exit
156 %min = select i1 %unknown, double 1.0, double 0.0
157 ;; TODO: This pointless branch shouldn't be neccessary
162 %res = fcmp oeq double %min, 300.0
171 ;; Using the condition to clamp the result
174 define i1 @test5(i32* %p, i1 %unknown) {
175 ; CHECK-LABEL: @test5
176 %pval = load i32, i32* %p
177 %cmp1 = icmp slt i32 %pval, 255
178 br i1 %cmp1, label %next, label %exit
181 %cond = icmp sgt i32 %pval, 0
182 %min = select i1 %cond, i32 %pval, i32 5
183 ;; TODO: This pointless branch shouldn't be neccessary
186 ; CHECK-LABEL: next2:
187 ; CHECK: ret i1 false
188 %res = icmp eq i32 %min, -1
197 define i1 @test6(i32* %p, i1 %unknown) {
198 ; CHECK-LABEL: @test6
199 %pval = load i32, i32* %p
200 %cmp1 = icmp ult i32 %pval, 255
201 br i1 %cmp1, label %next, label %exit
204 %cond = icmp ne i32 %pval, 254
205 %sel = select i1 %cond, i32 %pval, i32 1
206 ;; TODO: This pointless branch shouldn't be neccessary
209 ; CHECK-LABEL: next2:
211 %res = icmp slt i32 %sel, 254