Skip to content

Commit 3ea4bc7

Browse files
committed
[IRCE] Add tests for conservative bound check
Prevent cases in which the start value of IV is bigger than bound for increasing. Prevent cases in which the start value of IV is smaller than bound for decreasing. Differential Revision: https://reviews.llvm.org/D101174
1 parent 7e5682e commit 3ea4bc7

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

llvm/test/Transforms/IRCE/variable-loop-bounds.ll

+48
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
; CHECK: irce: in function signed_var_imm_dec_sge: constrained Loop at depth 1 containing: %for.body<header>,%if.else,%for.inc<latch><exiting>
1010
; CHECK: irce: in function signed_var_imm_dec_ne: constrained Loop at depth 1 containing: %for.body<header>,%if.else,%for.inc<latch><exiting>
1111
; CHECK-NOT: irce: in function signed_var_imm_dec_eq: constrained Loop at depth 1 containing: %for.body<header>,%if.else,%for.inc<latch><exiting>
12+
; CHECK-NOT: irce: in function test_dec_bound_with_smaller_start_than_bound: constrained Loop at depth 1 containing: %for.body<header>,%if.else,%for.dec<latch><exiting>
13+
; CHECK-NOT: irce: in function test_inc_bound_with_bigger_start_than_bound: constrained Loop at depth 1 containing: %for.body<header>,%if.else,%for.dec<latch><exiting>
1214

1315
; CHECK-LABEL: test_inc_eq(
1416
; CHECK: main.exit.selector:
@@ -352,3 +354,49 @@ for.inc: ; preds = %for.body, %if.else
352354
%cmp = icmp eq i32 %dec, %M
353355
br i1 %cmp, label %for.cond.cleanup, label %for.body
354356
}
357+
358+
; CHECK-LABEL: @test_dec_bound_with_smaller_start_than_bound(
359+
; CHECK-NOT: preloop.exit.selector:
360+
define void @test_dec_bound_with_smaller_start_than_bound(i64 %0) {
361+
entry:
362+
br label %for.body
363+
364+
for.body: ; preds = %for.dec, %entry
365+
%iv = phi i64 [ %dec, %for.dec ], [ 0, %entry ]
366+
%1 = icmp slt i64 %iv, %0
367+
br i1 %1, label %if.else, label %for.dec
368+
369+
if.else: ; preds = %for.body
370+
br label %for.dec
371+
372+
for.dec: ; preds = %if.else, %for.body
373+
%dec = sub nuw nsw i64 %iv, 1
374+
%2 = icmp slt i64 %dec, 1
375+
br i1 %2, label %exit, label %for.body
376+
377+
exit: ; preds = %for.dec
378+
ret void
379+
}
380+
381+
; CHECK-LABEL: @test_inc_bound_with_bigger_start_than_bound(
382+
; CHECK-NOT: main.exit.selector:
383+
define void @test_inc_bound_with_bigger_start_than_bound(i32 %0) {
384+
entry:
385+
br label %for.body
386+
387+
for.body: ; preds = %for.inc, %entry
388+
%iv = phi i32 [ %inc, %for.inc ], [ 200, %entry ]
389+
%1 = icmp slt i32 %iv, %0
390+
br i1 %1, label %if.else, label %for.inc
391+
392+
if.else: ; preds = %for.body
393+
br label %for.inc
394+
395+
for.inc: ; preds = %if.else, %for.body
396+
%inc = add nsw i32 %iv, 1
397+
%2 = icmp sgt i32 %inc, 100
398+
br i1 %2, label %exit, label %for.body
399+
400+
exit: ; preds = %for.inc
401+
ret void
402+
}

0 commit comments

Comments
 (0)