@@ -242,6 +242,36 @@ exit:
242242 ret i32 %iv
243243}
244244
245+ define i32 @test_sgt_samesign (i32 %start , i32 %inv_1 , i32 %inv_2 ) {
246+ ; CHECK-LABEL: @test_sgt_samesign(
247+ ; CHECK-NEXT: entry:
248+ ; CHECK-NEXT: br label [[LOOP:%.*]]
249+ ; CHECK: loop:
250+ ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
251+ ; CHECK-NEXT: [[CMP_1:%.*]] = icmp samesign ugt i32 [[IV]], [[INV_1:%.*]]
252+ ; CHECK-NEXT: [[CMP_2:%.*]] = icmp sgt i32 [[IV]], [[INV_2:%.*]]
253+ ; CHECK-NEXT: [[LOOP_COND:%.*]] = and i1 [[CMP_1]], [[CMP_2]]
254+ ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
255+ ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[EXIT:%.*]]
256+ ; CHECK: exit:
257+ ; CHECK-NEXT: [[IV_LCSSA:%.*]] = phi i32 [ [[IV]], [[LOOP]] ]
258+ ; CHECK-NEXT: ret i32 [[IV_LCSSA]]
259+ ;
260+ entry:
261+ br label %loop
262+
263+ loop:
264+ %iv = phi i32 [%start , %entry ], [%iv.next , %loop ]
265+ %cmp_1 = icmp samesign ugt i32 %iv , %inv_1
266+ %cmp_2 = icmp sgt i32 %iv , %inv_2
267+ %loop_cond = and i1 %cmp_1 , %cmp_2
268+ %iv.next = add i32 %iv , 1
269+ br i1 %loop_cond , label %loop , label %exit
270+
271+ exit:
272+ ret i32 %iv
273+ }
274+
245275; turn to %iv >=s smax(inv_1, inv_2) and hoist it out of loop.
246276define i32 @test_sge (i32 %start , i32 %inv_1 , i32 %inv_2 ) {
247277; CHECK-LABEL: @test_sge(
@@ -272,6 +302,36 @@ exit:
272302 ret i32 %iv
273303}
274304
305+ define i32 @test_sge_samesign (i32 %start , i32 %inv_1 , i32 %inv_2 ) {
306+ ; CHECK-LABEL: @test_sge_samesign(
307+ ; CHECK-NEXT: entry:
308+ ; CHECK-NEXT: br label [[LOOP:%.*]]
309+ ; CHECK: loop:
310+ ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
311+ ; CHECK-NEXT: [[CMP_1:%.*]] = icmp sge i32 [[IV]], [[INV_1:%.*]]
312+ ; CHECK-NEXT: [[CMP_2:%.*]] = icmp samesign uge i32 [[IV]], [[INV_2:%.*]]
313+ ; CHECK-NEXT: [[LOOP_COND:%.*]] = and i1 [[CMP_1]], [[CMP_2]]
314+ ; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
315+ ; CHECK-NEXT: br i1 [[LOOP_COND]], label [[LOOP]], label [[EXIT:%.*]]
316+ ; CHECK: exit:
317+ ; CHECK-NEXT: [[IV_LCSSA:%.*]] = phi i32 [ [[IV]], [[LOOP]] ]
318+ ; CHECK-NEXT: ret i32 [[IV_LCSSA]]
319+ ;
320+ entry:
321+ br label %loop
322+
323+ loop:
324+ %iv = phi i32 [%start , %entry ], [%iv.next , %loop ]
325+ %cmp_1 = icmp sge i32 %iv , %inv_1
326+ %cmp_2 = icmp samesign uge i32 %iv , %inv_2
327+ %loop_cond = and i1 %cmp_1 , %cmp_2
328+ %iv.next = add i32 %iv , 1
329+ br i1 %loop_cond , label %loop , label %exit
330+
331+ exit:
332+ ret i32 %iv
333+ }
334+
275335; Turn OR to AND and handle accordingly.
276336define i32 @test_ult_inv (i32 %start , i32 %inv_1 , i32 %inv_2 ) {
277337; CHECK-LABEL: @test_ult_inv(
0 commit comments