xref: /llvm-project/llvm/test/Transforms/IRCE/bug-mismatched-types.ll (revision 0ec421d024fe47fb43afdaa625309b0f799e9a59)
1; RUN: opt -verify-loop-info -passes=irce -S < %s
2; RUN: opt -verify-loop-info -passes='require<branch-prob>,irce' -S < %s
3
4; These test cases don't check the correctness of the transform, but
5; that -passes=irce does not crash in the presence of certain things in
6; the IR:
7
8define void @mismatched_types_1() {
9; In this test case, the safe range for the only range check in the
10; loop is of type [i32, i32) while the backedge taken count is of type
11; i64.
12
13; CHECK-LABEL: @mismatched_types_1(
14entry:
15  br label %for.body
16
17for.body:
18  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.inc ]
19  %0 = trunc i64 %indvars.iv to i32
20  %1 = icmp ult i32 %0, 7
21  br i1 %1, label %switch.lookup, label %for.inc
22
23switch.lookup:
24  br label %for.inc
25
26for.inc:
27  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
28  %cmp55 = icmp slt i64 %indvars.iv.next, 11
29  br i1 %cmp55, label %for.body, label %for.end
30
31for.end:
32  unreachable
33}
34
35define void @mismatched_types_2() {
36; In this test case, there are two range check in the loop, one with a
37; safe range of type [i32, i32) and one with a safe range of type
38; [i64, i64).
39
40; CHECK-LABEL: @mismatched_types_2(
41entry:
42  br label %for.body.a
43
44for.body.a:
45  %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.inc ]
46  %cond.a = icmp ult i64 %indvars.iv, 7
47  br i1 %cond.a, label %switch.lookup.a, label %for.body.b
48
49switch.lookup.a:
50  br label %for.body.b
51
52for.body.b:
53  %truncated = trunc i64 %indvars.iv to i32
54  %cond.b = icmp ult i32 %truncated, 7
55  br i1 %cond.b, label %switch.lookup.b, label %for.inc
56
57switch.lookup.b:
58  br label %for.inc
59
60for.inc:
61  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
62  %cmp55 = icmp slt i64 %indvars.iv.next, 11
63  br i1 %cmp55, label %for.body.a, label %for.end
64
65for.end:
66  unreachable
67}
68