xref: /llvm-project/llvm/test/CodeGen/Thumb/ragreedy-implicit-def.ll (revision e6bf3fa05b3706197143414a56be05ce014ebe01)
1; REQUIRES: asserts
2; RUN: llc -mtriple=thumbv6m -regalloc=greedy -stats < %s 2>&1 | FileCheck %s
3
4; Undef incoming values to phis end up creating IMPLICIT_DEF values. If we don't
5; prefer them to be in a register then we get fewer spilled live ranges (6
6; compared to 7).
7; CHECK: 6 regalloc - Number of spilled live ranges
8
9declare i32 @otherfn(i32)
10define void @fn(i32 %val, ptr %ptr) {
11entry:
12  %gep2 = getelementptr i32, ptr %ptr, i32 1
13  %gep3 = getelementptr i32, ptr %ptr, i32 2
14  %gep4 = getelementptr i32, ptr %ptr, i32 3
15  %gep5 = getelementptr i32, ptr %ptr, i32 4
16  %gep6 = getelementptr i32, ptr %ptr, i32 5
17  %gep7 = getelementptr i32, ptr %ptr, i32 6
18  %gep8 = getelementptr i32, ptr %ptr, i32 7
19  %cmp1 = icmp uge i32 %val, 3
20  br i1 %cmp1, label %if, label %then
21
22if:
23  %val1 = load i32, ptr %ptr, align 4
24  %val2 = load i32, ptr %gep2, align 4
25  %val3 = load i32, ptr %gep3, align 4
26  %val4 = load i32, ptr %gep4, align 4
27  %val5 = load i32, ptr %gep5, align 4
28  %val6 = load i32, ptr %gep6, align 4
29  %val7 = load i32, ptr %gep7, align 4
30  %val8 = load i32, ptr %gep8, align 4
31  br label %then
32
33then:
34  %phi1a = phi i32 [ %val1, %if ], [ undef, %entry ]
35  %phi2a = phi i32 [ %val2, %if ], [ undef, %entry ]
36  %phi3a = phi i32 [ %val3, %if ], [ undef, %entry ]
37  %phi4a = phi i32 [ %val4, %if ], [ undef, %entry ]
38  %phi5a = phi i32 [ %val5, %if ], [ undef, %entry ]
39  %phi6a = phi i32 [ %val6, %if ], [ undef, %entry ]
40  %phi7a = phi i32 [ %val7, %if ], [ undef, %entry ]
41  %phi8a = phi i32 [ %val8, %if ], [ undef, %entry ]
42  %switchval = call i32 @otherfn(i32 %val)
43  switch i32 %switchval, label %default [
44    i32 0, label %case0
45    i32 1, label %case1
46    i32 5, label %case5
47    i32 6, label %case6
48    i32 7, label %case7
49    i32 8, label %case8
50  ]
51
52default:
53  br label %switchend
54
55case0:
56  br label %switchend
57
58case1:
59  br label %switchend
60
61case5:
62  br label %switchend
63
64case6:
65  br label %switchend
66
67case7:
68  br label %switchend
69
70case8:
71  br label %switchend
72
73switchend:
74  %phi1b = phi i32 [ 0, %default ], [ undef, %case0 ], [ undef, %case1 ], [ %phi1a, %case5 ], [ 1, %case6 ], [ 2, %case7 ], [ 1, %case8 ]
75  %phi2b = phi i32 [ 0, %default ], [ undef, %case0 ], [ undef, %case1 ], [ %phi2a, %case5 ], [ 2, %case6 ], [ 2, %case7 ], [ 1, %case8 ]
76  %phi3b = phi i32 [ 0, %default ], [ undef, %case0 ], [ undef, %case1 ], [ %phi3a, %case5 ], [ 3, %case6 ], [ 2, %case7 ], [ 1, %case8 ]
77  %phi4b = phi i32 [ 0, %default ], [ undef, %case0 ], [ undef, %case1 ], [ %phi4a, %case5 ], [ 4, %case6 ], [ 2, %case7 ], [ 1, %case8 ]
78  %phi5b = phi i32 [ 0, %default ], [ undef, %case0 ], [ undef, %case1 ], [ %phi5a, %case5 ], [ 5, %case6 ], [ 2, %case7 ], [ 1, %case8 ]
79  %phi6b = phi i32 [ 0, %default ], [ undef, %case0 ], [ undef, %case1 ], [ %phi6a, %case5 ], [ 6, %case6 ], [ 2, %case7 ], [ 1, %case8 ]
80  %phi7b = phi i32 [ 0, %default ], [ undef, %case0 ], [ undef, %case1 ], [ %phi7a, %case5 ], [ 7, %case6 ], [ 2, %case7 ], [ 1, %case8 ]
81  %phi8b = phi i32 [ 0, %default ], [ undef, %case0 ], [ undef, %case1 ], [ %phi8a, %case5 ], [ 8, %case6 ], [ 2, %case7 ], [ 1, %case8 ]
82  %cmp2 = icmp uge i32 %val, 4
83  br i1 %cmp2, label %if2, label %end
84
85if2:
86  store i32 %phi1b, ptr %ptr, align 4
87  store i32 %phi2b, ptr %gep2, align 4
88  store i32 %phi3b, ptr %gep3, align 4
89  store i32 %phi4b, ptr %gep4, align 4
90  store i32 %phi5b, ptr %gep5, align 4
91  store i32 %phi6b, ptr %gep6, align 4
92  store i32 %phi7b, ptr %gep7, align 4
93  store i32 %phi8b, ptr %gep8, align 4
94  br label %end
95
96end:
97  ret void
98}
99