@@ -128,6 +128,106 @@ func.func @selToArith(%arg0: i1, %arg1 : i1, %arg2 : i1) -> i1 {
128128 return %res : i1
129129}
130130
131+ // CHECK-LABEL: @redundantSelectTrue
132+ // CHECK-NEXT: %[[res:.+]] = arith.select %arg0, %arg1, %arg3
133+ // CHECK-NEXT: return %[[res]]
134+ func.func @redundantSelectTrue (%arg0: i1 , %arg1 : i32 , %arg2 : i32 , %arg3 : i32 ) -> i32 {
135+ %0 = arith.select %arg0 , %arg1 , %arg2 : i32
136+ %res = arith.select %arg0 , %0 , %arg3 : i32
137+ return %res : i32
138+ }
139+
140+ // CHECK-LABEL: @redundantSelectFalse
141+ // CHECK-NEXT: %[[res:.+]] = arith.select %arg0, %arg3, %arg2
142+ // CHECK-NEXT: return %[[res]]
143+ func.func @redundantSelectFalse (%arg0: i1 , %arg1 : i32 , %arg2 : i32 , %arg3 : i32 ) -> i32 {
144+ %0 = arith.select %arg0 , %arg1 , %arg2 : i32
145+ %res = arith.select %arg0 , %arg3 , %0 : i32
146+ return %res : i32
147+ }
148+
149+ // CHECK-LABEL: @selNotCond
150+ // CHECK-NEXT: %[[res1:.+]] = arith.select %arg0, %arg2, %arg1
151+ // CHECK-NEXT: %[[res2:.+]] = arith.select %arg0, %arg4, %arg3
152+ // CHECK-NEXT: return %[[res1]], %[[res2]]
153+ func.func @selNotCond (%arg0: i1 , %arg1 : i32 , %arg2 : i32 , %arg3 : i32 , %arg4 : i32 ) -> (i32 , i32 ) {
154+ %one = arith.constant 1 : i1
155+ %cond1 = arith.xori %arg0 , %one : i1
156+ %cond2 = arith.xori %one , %arg0 : i1
157+
158+ %res1 = arith.select %cond1 , %arg1 , %arg2 : i32
159+ %res2 = arith.select %cond2 , %arg3 , %arg4 : i32
160+ return %res1 , %res2 : i32 , i32
161+ }
162+
163+ // CHECK-LABEL: @selAndCond
164+ // CHECK-NEXT: %[[and:.+]] = arith.andi %arg1, %arg0
165+ // CHECK-NEXT: %[[res:.+]] = arith.select %[[and]], %arg2, %arg3
166+ // CHECK-NEXT: return %[[res]]
167+ func.func @selAndCond (%arg0: i1 , %arg1: i1 , %arg2 : i32 , %arg3 : i32 ) -> i32 {
168+ %sel = arith.select %arg0 , %arg2 , %arg3 : i32
169+ %res = arith.select %arg1 , %sel , %arg3 : i32
170+ return %res : i32
171+ }
172+
173+ // CHECK-LABEL: @selAndNotCond
174+ // CHECK-NEXT: %[[one:.+]] = arith.constant true
175+ // CHECK-NEXT: %[[not:.+]] = arith.xori %arg0, %[[one]]
176+ // CHECK-NEXT: %[[and:.+]] = arith.andi %arg1, %[[not]]
177+ // CHECK-NEXT: %[[res:.+]] = arith.select %[[and]], %arg3, %arg2
178+ // CHECK-NEXT: return %[[res]]
179+ func.func @selAndNotCond (%arg0: i1 , %arg1: i1 , %arg2 : i32 , %arg3 : i32 ) -> i32 {
180+ %sel = arith.select %arg0 , %arg2 , %arg3 : i32
181+ %res = arith.select %arg1 , %sel , %arg2 : i32
182+ return %res : i32
183+ }
184+
185+ // CHECK-LABEL: @selAndNotCondVec
186+ // CHECK-NEXT: %[[one:.+]] = arith.constant dense<true> : vector<4xi1>
187+ // CHECK-NEXT: %[[not:.+]] = arith.xori %arg0, %[[one]]
188+ // CHECK-NEXT: %[[and:.+]] = arith.andi %arg1, %[[not]]
189+ // CHECK-NEXT: %[[res:.+]] = arith.select %[[and]], %arg3, %arg2
190+ // CHECK-NEXT: return %[[res]]
191+ func.func @selAndNotCondVec (%arg0: vector <4 xi1 >, %arg1: vector <4 xi1 >, %arg2 : vector <4 xi32 >, %arg3 : vector <4 xi32 >) -> vector <4 xi32 > {
192+ %sel = arith.select %arg0 , %arg2 , %arg3 : vector <4 xi1 >, vector <4 xi32 >
193+ %res = arith.select %arg1 , %sel , %arg2 : vector <4 xi1 >, vector <4 xi32 >
194+ return %res : vector <4 xi32 >
195+ }
196+
197+ // CHECK-LABEL: @selOrCond
198+ // CHECK-NEXT: %[[or:.+]] = arith.ori %arg1, %arg0
199+ // CHECK-NEXT: %[[res:.+]] = arith.select %[[or]], %arg2, %arg3
200+ // CHECK-NEXT: return %[[res]]
201+ func.func @selOrCond (%arg0: i1 , %arg1: i1 , %arg2 : i32 , %arg3 : i32 ) -> i32 {
202+ %sel = arith.select %arg0 , %arg2 , %arg3 : i32
203+ %res = arith.select %arg1 , %arg2 , %sel : i32
204+ return %res : i32
205+ }
206+
207+ // CHECK-LABEL: @selOrNotCond
208+ // CHECK-NEXT: %[[one:.+]] = arith.constant true
209+ // CHECK-NEXT: %[[not:.+]] = arith.xori %arg0, %[[one]]
210+ // CHECK-NEXT: %[[or:.+]] = arith.ori %arg1, %[[not]]
211+ // CHECK-NEXT: %[[res:.+]] = arith.select %[[or]], %arg3, %arg2
212+ // CHECK-NEXT: return %[[res]]
213+ func.func @selOrNotCond (%arg0: i1 , %arg1: i1 , %arg2 : i32 , %arg3 : i32 ) -> i32 {
214+ %sel = arith.select %arg0 , %arg2 , %arg3 : i32
215+ %res = arith.select %arg1 , %arg3 , %sel : i32
216+ return %res : i32
217+ }
218+
219+ // CHECK-LABEL: @selOrNotCondVec
220+ // CHECK-NEXT: %[[one:.+]] = arith.constant dense<true> : vector<4xi1>
221+ // CHECK-NEXT: %[[not:.+]] = arith.xori %arg0, %[[one]]
222+ // CHECK-NEXT: %[[or:.+]] = arith.ori %arg1, %[[not]]
223+ // CHECK-NEXT: %[[res:.+]] = arith.select %[[or]], %arg3, %arg2
224+ // CHECK-NEXT: return %[[res]]
225+ func.func @selOrNotCondVec (%arg0: vector <4 xi1 >, %arg1: vector <4 xi1 >, %arg2 : vector <4 xi32 >, %arg3 : vector <4 xi32 >) -> vector <4 xi32 > {
226+ %sel = arith.select %arg0 , %arg2 , %arg3 : vector <4 xi1 >, vector <4 xi32 >
227+ %res = arith.select %arg1 , %arg3 , %sel : vector <4 xi1 >, vector <4 xi32 >
228+ return %res : vector <4 xi32 >
229+ }
230+
131231// Test case: Folding of comparisons with equal operands.
132232// CHECK-LABEL: @cmpi_equal_operands
133233// CHECK-DAG: %[[T:.*]] = arith.constant true
0 commit comments