xref: /llvm-project/llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-exts.mir (revision 3fee8b346928a24975ebbd6984b583c01ec82955)
1# RUN: llc -mtriple arm-- -run-pass=legalizer %s -o - | FileCheck %s
2# RUN: llc -mtriple thumb-- -mattr=+v6t2 -run-pass=legalizer %s -o - | FileCheck %s
3--- |
4  define void @test_zext_s16_to_s32() { ret void }
5  define void @test_sext_s8_to_s32() { ret void }
6  define void @test_sext_inreg_s8_to_s32() { ret void }
7  define void @test_anyext_s1_to_s32() { ret void }
8
9  define void @test_zext_s8_to_s16() { ret void }
10  define void @test_sext_s1_to_s16() { ret void }
11
12  define void @test_anyext_s1_to_s8() { ret void }
13
14  define void @test_ext_combine() { ret void }
15...
16---
17name:            test_zext_s16_to_s32
18# CHECK-LABEL: name: test_zext_s16_to_s32
19legalized:       false
20# CHECK: legalized: true
21regBankSelected: false
22selected:        false
23tracksRegLiveness: true
24registers:
25  - { id: 0, class: _ }
26  - { id: 1, class: _ }
27  - { id: 2, class: _ }
28body:             |
29  bb.0:
30    liveins: $r0
31
32    %0(p0) = COPY $r0
33    %1(s16) = G_LOAD %0 :: (load (s16))
34    %2(s32) = G_ZEXT %1
35    ; G_ZEXT with s16 is legal, so we should find it unchanged in the output
36    ; CHECK: {{%[0-9]+}}:_(s32) = G_ZEXT {{%[0-9]+}}
37    $r0 = COPY %2(s32)
38    BX_RET 14, $noreg, implicit $r0
39...
40---
41name:            test_sext_s8_to_s32
42# CHECK-LABEL: name: test_sext_s8_to_s32
43legalized:       false
44# CHECK: legalized: true
45regBankSelected: false
46selected:        false
47tracksRegLiveness: true
48registers:
49  - { id: 0, class: _ }
50  - { id: 1, class: _ }
51  - { id: 2, class: _ }
52body:             |
53  bb.0:
54    liveins: $r0
55
56    %0(p0) = COPY $r0
57    %1(s8) = G_LOAD %0(p0) :: (load (s8))
58    %2(s32) = G_SEXT %1
59    ; G_SEXT with s8 is legal, so we should find it unchanged in the output
60    ; CHECK: {{%[0-9]+}}:_(s32) = G_SEXT {{%[0-9]+}}
61    $r0 = COPY %2(s32)
62    BX_RET 14, $noreg, implicit $r0
63...
64---
65name:            test_sext_inreg_s8_to_s32
66# CHECK-LABEL: name: test_sext_inreg_s8_to_s32
67legalized:       false
68# CHECK: legalized: true
69regBankSelected: false
70selected:        false
71tracksRegLiveness: true
72registers:
73  - { id: 0, class: _ }
74  - { id: 1, class: _ }
75  - { id: 2, class: _ }
76body:             |
77  bb.0:
78    liveins: $r0
79
80    %0(p0) = COPY $r0
81    %1(s32) = G_LOAD %0(p0) :: (load (s32))
82    %2(s32) = G_SEXT_INREG %1, 8
83    ; G_SEXT_INREG should be lowered to a shift pair
84    ; CHECK: [[T1:%[0-9]+]]:_(s32) = G_CONSTANT i32 24
85    ; CHECK: [[T2:%[0-9]+]]:_(s32) = G_SHL {{%[0-9]+}}, [[T1]]
86    ; CHECK: {{%[0-9]+}}:_(s32) = G_ASHR [[T2]], [[T1]]
87    $r0 = COPY %2(s32)
88    BX_RET 14, $noreg, implicit $r0
89...
90---
91name:            test_anyext_s1_to_s32
92# CHECK-LABEL: name: test_anyext_s1_to_s32
93legalized:       false
94# CHECK: legalized: true
95regBankSelected: false
96selected:        false
97tracksRegLiveness: true
98registers:
99  - { id: 0, class: _ }
100  - { id: 1, class: _ }
101  - { id: 2, class: _ }
102body:             |
103  bb.0:
104    liveins: $r0
105
106    %0(p0) = COPY $r0
107    %1(s1) = G_LOAD %0(p0) :: (load (s1))
108    %2(s32) = G_ANYEXT %1
109    ; G_ANYEXT with s1 is legal, so we should find it unchanged in the output
110    ; CHECK: {{%[0-9]+}}:_(s32) = G_ANYEXT {{%[0-9]+}}
111    $r0 = COPY %2(s32)
112    BX_RET 14, $noreg, implicit $r0
113...
114---
115name:            test_zext_s8_to_s16
116# CHECK-LABEL: name: test_zext_s8_to_s16
117legalized:       false
118# CHECK: legalized: true
119regBankSelected: false
120selected:        false
121tracksRegLiveness: true
122registers:
123  - { id: 0, class: _ }
124  - { id: 1, class: _ }
125  - { id: 2, class: _ }
126body:             |
127  bb.0:
128    liveins: $r0
129
130    %0(p0) = COPY $r0
131    %1(s8) = G_LOAD %0(p0) :: (load (s8))
132    %2(s16) = G_ZEXT %1
133    ; G_ZEXT from s8 to s16 is legal, so we should find it unchanged in the output
134    ; CHECK: {{%[0-9]+}}:_(s16) = G_ZEXT {{%[0-9]+}}(s8)
135    G_STORE %2(s16), %0(p0) :: (store (s16))
136    BX_RET 14, $noreg
137...
138---
139name:            test_sext_s1_to_s16
140# CHECK-LABEL: name: test_sext_s1_to_s16
141legalized:       false
142# CHECK: legalized: true
143regBankSelected: false
144selected:        false
145tracksRegLiveness: true
146body:             |
147  bb.0:
148    liveins: $r0, $r1
149
150    %0:_(p0) = COPY $r0
151    %1:_(s32) = COPY $r1
152    %2:_(s32) = G_CONSTANT i32 0
153    %3:_(s1) = G_ICMP intpred(eq), %1, %2
154    %4:_(s16) = G_SEXT %3(s1)
155    ; G_SEXT from s1 to s16 is legal, so we should find it unchanged in the output
156    ; CHECK: {{%[0-9]+}}:_(s16) = G_SEXT {{%[0-9]+}}(s1)
157    G_STORE %4(s16), %0(p0) :: (store (s16))
158    BX_RET 14, $noreg
159...
160---
161name:            test_anyext_s1_to_s8
162# CHECK-LABEL: name: test_anyext_s1_to_s8
163legalized:       false
164# CHECK: legalized: true
165regBankSelected: false
166selected:        false
167tracksRegLiveness: true
168body:             |
169  bb.0:
170    liveins: $r0, $r1
171
172    %0:_(p0) = COPY $r0
173    %1:_(s32) = COPY $r1
174    %2:_(s32) = G_CONSTANT i32 0
175    %3:_(s1) = G_ICMP intpred(eq), %1, %2
176    %4:_(s8) = G_ANYEXT %3
177    ; G_ANYEXT from s1 to s8 is legal, so we should find it unchanged in the output
178    ; CHECK: {{%[0-9]+}}:_(s8) = G_ANYEXT {{%[0-9]+}}(s1)
179    G_STORE %4(s8), %0(p0) :: (store (s8))
180    BX_RET 14, $noreg
181...
182---
183name:            test_ext_combine
184# CHECK-LABEL: name: test_ext_combine
185legalized:       false
186# CHECK: legalized: true
187regBankSelected: false
188selected:        false
189tracksRegLiveness: true
190registers:
191  - { id: 0, class: _ }
192  - { id: 1, class: _ }
193  - { id: 2, class: _ }
194  - { id: 3, class: _ }
195  - { id: 4, class: _ }
196  - { id: 5, class: _ }
197body:             |
198  bb.0:
199    liveins: $r0
200
201    %0(p0) = COPY $r0
202    %1(s8) = G_LOAD %0(p0) :: (load (s8))
203    ; CHECK: [[V8:%[0-9]+]]:_(s8) = G_LOAD
204
205    %2(s16) = G_ZEXT %1
206    %3(s16) = G_SEXT %1
207
208    %4(s16) = G_OR %2, %3
209    ; G_OR is going to widen to 32 bits and the extensions/truncs should combine
210    ; with the already existing ones
211    ; CHECK: [[ZEXT:%[0-9]+]]:_(s32) = G_ZEXT [[V8]](s8)
212    ; CHECK: [[SEXT:%[0-9]+]]:_(s32) = G_SEXT [[V8]](s8)
213    ; CHECK: [[OR:%[0-9]+]]:_(s32) = G_OR [[ZEXT]], [[SEXT]]
214    ; CHECK: $r0 = COPY [[OR]]
215
216    %5(s32) = G_SEXT %4(s16)
217    $r0 = COPY %5
218
219    BX_RET 14, $noreg, implicit $r0
220...
221