1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 declare void @use(i32,...)
6 define i1 @both_sides_fold_slt(i32 %param, i1 %cond) {
7 ; CHECK-LABEL: define i1 @both_sides_fold_slt
8 ; CHECK-SAME: (i32 [[PARAM:%.*]], i1 [[COND:%.*]]) {
10 ; CHECK-NEXT: ret i1 false
13 %cond1 = select i1 %cond, i32 1, i32 %param
14 %cond6 = select i1 %cond, i32 9, i32 %param
15 %cmp = icmp slt i32 %cond6, %cond1
19 define i1 @both_sides_fold_eq(i32 %param, i1 %cond) {
20 ; CHECK-LABEL: define i1 @both_sides_fold_eq
21 ; CHECK-SAME: (i32 [[PARAM:%.*]], i1 [[COND:%.*]]) {
23 ; CHECK-NEXT: [[NOT_COND:%.*]] = xor i1 [[COND]], true
24 ; CHECK-NEXT: ret i1 [[NOT_COND]]
27 %cond1 = select i1 %cond, i32 1, i32 %param
28 %cond6 = select i1 %cond, i32 9, i32 %param
29 %cmp = icmp eq i32 %cond6, %cond1
33 define i1 @one_side_fold_slt(i32 %val1, i32 %val2, i32 %param, i1 %cond) {
34 ; CHECK-LABEL: define i1 @one_side_fold_slt
35 ; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[PARAM:%.*]], i1 [[COND:%.*]]) {
37 ; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[VAL2]], [[VAL1]]
38 ; CHECK-NEXT: [[CMP:%.*]] = select i1 [[COND]], i1 [[TMP0]], i1 false
39 ; CHECK-NEXT: ret i1 [[CMP]]
42 %cond1 = select i1 %cond, i32 %val1, i32 %param
43 %cond6 = select i1 %cond, i32 %val2, i32 %param
44 %cmp = icmp slt i32 %cond6, %cond1
48 define i1 @one_side_fold_sgt(i32 %val1, i32 %val2, i32 %param, i1 %cond) {
49 ; CHECK-LABEL: define i1 @one_side_fold_sgt
50 ; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[PARAM:%.*]], i1 [[COND:%.*]]) {
52 ; CHECK-NEXT: [[TMP0:%.*]] = icmp sgt i32 [[VAL2]], [[VAL1]]
53 ; CHECK-NEXT: [[NOT_COND:%.*]] = xor i1 [[COND]], true
54 ; CHECK-NEXT: [[CMP:%.*]] = select i1 [[NOT_COND]], i1 [[TMP0]], i1 false
55 ; CHECK-NEXT: ret i1 [[CMP]]
58 %cond1 = select i1 %cond, i32 %param, i32 %val1
59 %cond6 = select i1 %cond, i32 %param, i32 %val2
60 %cmp = icmp sgt i32 %cond6, %cond1
64 define i1 @one_side_fold_eq(i32 %val1, i32 %val2, i32 %param, i1 %cond) {
65 ; CHECK-LABEL: define i1 @one_side_fold_eq
66 ; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[PARAM:%.*]], i1 [[COND:%.*]]) {
68 ; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[VAL2]], [[VAL1]]
69 ; CHECK-NEXT: [[NOT_COND:%.*]] = xor i1 [[COND]], true
70 ; CHECK-NEXT: [[CMP:%.*]] = select i1 [[NOT_COND]], i1 true, i1 [[TMP0]]
71 ; CHECK-NEXT: ret i1 [[CMP]]
74 %cond1 = select i1 %cond, i32 %val1, i32 %param
75 %cond6 = select i1 %cond, i32 %val2, i32 %param
76 %cmp = icmp eq i32 %cond6, %cond1
80 define i1 @no_side_fold_cond(i32 %val1, i32 %val2, i32 %param, i1 %cond1, i1 %cond2) {
81 ; CHECK-LABEL: define i1 @no_side_fold_cond
82 ; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[PARAM:%.*]], i1 [[COND1:%.*]], i1 [[COND2:%.*]]) {
84 ; CHECK-NEXT: [[COND3:%.*]] = select i1 [[COND1]], i32 [[VAL1]], i32 [[PARAM]]
85 ; CHECK-NEXT: [[COND6:%.*]] = select i1 [[COND2]], i32 [[VAL2]], i32 [[PARAM]]
86 ; CHECK-NEXT: [[CMP:%.*]] = icmp sle i32 [[COND6]], [[COND3]]
87 ; CHECK-NEXT: ret i1 [[CMP]]
90 %cond3 = select i1 %cond1, i32 %val1, i32 %param
91 %cond6 = select i1 %cond2, i32 %val2, i32 %param
92 %cmp = icmp sle i32 %cond6, %cond3
96 define i1 @no_side_fold_op(i32 %val1, i32 %val2, i32 %val3, i1 %cond) {
97 ; CHECK-LABEL: define i1 @no_side_fold_op
98 ; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[VAL3:%.*]], i1 [[COND:%.*]]) {
100 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[COND]], i32 [[VAL1]], i32 [[VAL2]]
101 ; CHECK-NEXT: [[COND6:%.*]] = select i1 [[COND]], i32 [[VAL2]], i32 [[VAL3]]
102 ; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[COND6]], [[COND1]]
103 ; CHECK-NEXT: ret i1 [[CMP]]
106 %cond1 = select i1 %cond, i32 %val1, i32 %val2
107 %cond6 = select i1 %cond, i32 %val2, i32 %val3
108 %cmp = icmp sge i32 %cond6, %cond1
112 define i1 @one_select_mult_use(i32 %val1, i32 %val2, i32 %param, i1 %cond) {
113 ; CHECK-LABEL: define i1 @one_select_mult_use
114 ; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[PARAM:%.*]], i1 [[COND:%.*]]) {
116 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[COND]], i32 [[VAL1]], i32 [[PARAM]]
117 ; CHECK-NEXT: call void @use(i32 [[COND1]])
118 ; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[VAL2]], [[VAL1]]
119 ; CHECK-NEXT: [[CMP:%.*]] = select i1 [[COND]], i1 [[TMP0]], i1 false
120 ; CHECK-NEXT: ret i1 [[CMP]]
123 %cond1 = select i1 %cond, i32 %val1, i32 %param
124 %cond6 = select i1 %cond, i32 %val2, i32 %param
125 call void @use(i32 %cond1)
126 %cmp = icmp slt i32 %cond6, %cond1
130 define i1 @both_select_mult_use(i32 %val1, i32 %val2, i32 %param, i1 %cond) {
131 ; CHECK-LABEL: define i1 @both_select_mult_use
132 ; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[PARAM:%.*]], i1 [[COND:%.*]]) {
134 ; CHECK-NEXT: [[COND1:%.*]] = select i1 [[COND]], i32 [[VAL1]], i32 [[PARAM]]
135 ; CHECK-NEXT: [[COND6:%.*]] = select i1 [[COND]], i32 [[VAL2]], i32 [[PARAM]]
136 ; CHECK-NEXT: call void @use(i32 [[COND1]], i32 [[COND6]])
137 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[COND6]], [[COND1]]
138 ; CHECK-NEXT: ret i1 [[CMP]]
141 %cond1 = select i1 %cond, i32 %val1, i32 %param
142 %cond6 = select i1 %cond, i32 %val2, i32 %param
143 call void @use(i32 %cond1, i32 %cond6)
144 %cmp = icmp slt i32 %cond6, %cond1
148 define <4 x i1> @fold_vector_ops(<4 x i32> %val1, <4 x i32> %val2, <4 x i32> %param, i1 %cond) {
149 ; CHECK-LABEL: define <4 x i1> @fold_vector_ops
150 ; CHECK-SAME: (<4 x i32> [[VAL1:%.*]], <4 x i32> [[VAL2:%.*]], <4 x i32> [[PARAM:%.*]], i1 [[COND:%.*]]) {
152 ; CHECK-NEXT: [[TMP0:%.*]] = icmp eq <4 x i32> [[VAL2]], [[VAL1]]
153 ; CHECK-NEXT: [[CMP:%.*]] = select i1 [[COND]], <4 x i1> [[TMP0]], <4 x i1> <i1 true, i1 true, i1 true, i1 true>
154 ; CHECK-NEXT: ret <4 x i1> [[CMP]]
157 %cond1 = select i1 %cond, <4 x i32> %val1, <4 x i32> %param
158 %cond6 = select i1 %cond, <4 x i32> %val2, <4 x i32> %param
159 %cmp = icmp eq <4 x i32> %cond6, %cond1
163 define <8 x i1> @fold_vector_cond_ops(<8 x i32> %val1, <8 x i32> %val2, <8 x i32> %param, <8 x i1> %cond) {
164 ; CHECK-LABEL: define <8 x i1> @fold_vector_cond_ops
165 ; CHECK-SAME: (<8 x i32> [[VAL1:%.*]], <8 x i32> [[VAL2:%.*]], <8 x i32> [[PARAM:%.*]], <8 x i1> [[COND:%.*]]) {
167 ; CHECK-NEXT: [[TMP0:%.*]] = icmp sgt <8 x i32> [[VAL2]], [[VAL1]]
168 ; CHECK-NEXT: [[CMP:%.*]] = select <8 x i1> [[COND]], <8 x i1> [[TMP0]], <8 x i1> zeroinitializer
169 ; CHECK-NEXT: ret <8 x i1> [[CMP]]
172 %cond1 = select <8 x i1> %cond, <8 x i32> %val1, <8 x i32> %param
173 %cond6 = select <8 x i1> %cond, <8 x i32> %val2, <8 x i32> %param
174 %cmp = icmp sgt <8 x i32> %cond6, %cond1