xref: /llvm-project/llvm/test/Transforms/IRCE/bad-loop-structure.ll (revision 0ec421d024fe47fb43afdaa625309b0f799e9a59)
1*0ec421d0SRoman Lebedev; RUN: opt -S -passes=irce -irce-print-changed-loops=true < %s | FileCheck %s
267904db2SAlina Sbirlea; RUN: opt -S -passes='require<branch-prob>,irce' -irce-print-changed-loops=true < %s | FileCheck %s
3cee313d2SEric Christopher
4cee313d2SEric Christopher; CHECK-NOT: irce
5cee313d2SEric Christopher
6cee313d2SEric Christopherdefine void @bad_loop_structure_increasing(i64 %iv.start) {
7cee313d2SEric Christopherentry:
8cee313d2SEric Christopher  br label %for.body
9cee313d2SEric Christopher
10cee313d2SEric Christopherfor.body:
11cee313d2SEric Christopher  %indvars.iv = phi i64 [ %iv.start, %entry ], [ %indvars.iv.next, %for.inc ]
12cee313d2SEric Christopher  %cmp = icmp ult i64 %indvars.iv, 100
13cee313d2SEric Christopher  br i1 %cmp, label %switch.lookup, label %for.inc
14cee313d2SEric Christopher
15cee313d2SEric Christopherswitch.lookup:
16cee313d2SEric Christopher  br label %for.inc
17cee313d2SEric Christopher
18cee313d2SEric Christopherfor.inc:
19cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
20cee313d2SEric Christopher  %cmp55 = icmp slt i64 %indvars.iv.next, 11
21cee313d2SEric Christopher  br i1 %cmp55, label %for.body, label %for.end
22cee313d2SEric Christopher
23cee313d2SEric Christopherfor.end:
24cee313d2SEric Christopher  ret void
25cee313d2SEric Christopher}
26cee313d2SEric Christopher
27cee313d2SEric Christopherdefine void @bad_loop_structure_decreasing(i64 %iv.start) {
28cee313d2SEric Christopherentry:
29cee313d2SEric Christopher  br label %for.body
30cee313d2SEric Christopher
31cee313d2SEric Christopherfor.body:
32cee313d2SEric Christopher  %indvars.iv = phi i64 [ %iv.start, %entry ], [ %indvars.iv.next, %for.inc ]
33cee313d2SEric Christopher  %cmp = icmp ult i64 %indvars.iv, 100
34cee313d2SEric Christopher  br i1 %cmp, label %switch.lookup, label %for.inc
35cee313d2SEric Christopher
36cee313d2SEric Christopherswitch.lookup:
37cee313d2SEric Christopher  br label %for.inc
38cee313d2SEric Christopher
39cee313d2SEric Christopherfor.inc:
40cee313d2SEric Christopher  %indvars.iv.next = add nuw nsw i64 %indvars.iv, -1
41cee313d2SEric Christopher  %cmp55 = icmp sgt i64 %indvars.iv.next, 11
42cee313d2SEric Christopher  br i1 %cmp55, label %for.body, label %for.end
43cee313d2SEric Christopher
44cee313d2SEric Christopherfor.end:
45cee313d2SEric Christopher  ret void
46cee313d2SEric Christopher}
47