llvm/test/Transforms/IRCE/bad-loop-structure.ll
Sanjoy Das 541d77cf0d [IRCE] Add a missing invariant check
Currently IRCE relies on the loops it transforms to be (semantically) of
the form:

  for (i = START; i < END; i++)
    ...

or

  for (i = START; i > END; i--)
    ...

However, we were not verifying the presence of the START < END entry
check (i.e. check before the first iteration).  We were only verifying
that the backedge was guarded by (i + 1) < END.

Usually this would work "fine" since (especially in Java) most loops do
actually have the START < END check, but of course that is not
guaranteed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294375 91177308-0d34-0410-b5e6-96231b3b80d8
2017-02-07 23:59:07 +00:00

46 lines
1.0 KiB
LLVM

; RUN: opt -S -irce -irce-print-changed-loops=true < %s | FileCheck %s
; CHECK-NOT: irce
define void @bad_loop_structure_increasing(i64 %iv.start) {
entry:
br label %for.body
for.body:
%indvars.iv = phi i64 [ %iv.start, %entry ], [ %indvars.iv.next, %for.inc ]
%cmp = icmp ult i64 %indvars.iv, 100
br i1 %cmp, label %switch.lookup, label %for.inc
switch.lookup:
br label %for.inc
for.inc:
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
%cmp55 = icmp slt i64 %indvars.iv.next, 11
br i1 %cmp55, label %for.body, label %for.end
for.end:
ret void
}
define void @bad_loop_structure_decreasing(i64 %iv.start) {
entry:
br label %for.body
for.body:
%indvars.iv = phi i64 [ %iv.start, %entry ], [ %indvars.iv.next, %for.inc ]
%cmp = icmp ult i64 %indvars.iv, 100
br i1 %cmp, label %switch.lookup, label %for.inc
switch.lookup:
br label %for.inc
for.inc:
%indvars.iv.next = add nuw nsw i64 %indvars.iv, -1
%cmp55 = icmp sgt i64 %indvars.iv.next, 11
br i1 %cmp55, label %for.body, label %for.end
for.end:
ret void
}