xref: /llvm-project/llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-casts.mir (revision 2bf4eeeeb60daba9534dd55088067fcf5a65f86b)
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_inttoptr_s32() { ret void }
5  define void @test_ptrtoint_s32() { ret void }
6
7  define void @test_inttoptr_s16() { ret void }
8  define void @test_ptrtoint_s8() { ret void }
9...
10---
11name:            test_inttoptr_s32
12# CHECK-LABEL: name: test_inttoptr_s32
13legalized:       false
14# CHECK: legalized: true
15regBankSelected: false
16selected:        false
17tracksRegLiveness: true
18registers:
19  - { id: 0, class: _ }
20  - { id: 1, class: _ }
21body:             |
22  bb.0:
23    liveins: $r0
24
25    %0(s32) = COPY $r0
26    %1(p0) = G_INTTOPTR %0(s32)
27    ; G_INTTOPTR with s32 is legal, so we should find it unchanged in the output
28    ; CHECK: {{%[0-9]+}}:_(p0) = G_INTTOPTR {{%[0-9]+}}
29    $r0 = COPY %1(p0)
30    BX_RET 14, $noreg, implicit $r0
31...
32---
33name:            test_ptrtoint_s32
34# CHECK-LABEL: name: test_ptrtoint_s32
35legalized:       false
36# CHECK: legalized: true
37regBankSelected: false
38selected:        false
39tracksRegLiveness: true
40registers:
41  - { id: 0, class: _ }
42  - { id: 1, class: _ }
43body:             |
44  bb.0:
45    liveins: $r0
46
47    %0(p0) = COPY $r0
48    %1(s32) = G_PTRTOINT %0(p0)
49    ; G_PTRTOINT with s32 is legal, so we should find it unchanged in the output
50    ; CHECK: {{%[0-9]+}}:_(s32) = G_PTRTOINT {{%[0-9]+}}
51    $r0 = COPY %1(s32)
52    BX_RET 14, $noreg, implicit $r0
53...
54---
55name:            test_inttoptr_s16
56# CHECK-LABEL: name: test_inttoptr_s16
57legalized:       false
58# CHECK: legalized: true
59regBankSelected: false
60selected:        false
61tracksRegLiveness: true
62registers:
63  - { id: 0, class: _ }
64  - { id: 1, class: _ }
65  - { id: 2, class: _ }
66body:             |
67  bb.0:
68    liveins: $r0
69
70    %0(s32) = COPY $r0
71    %1(s16) = G_TRUNC %0(s32)
72    %2(p0) = G_INTTOPTR %1(s16)
73    ; G_INTTOPTR with s16 should zero extend
74    ; CHECK-NOT: G_INTTOPTR {{%[0-9]+}}(s16)
75    ; CHECK: [[BITS:%[0-9]+]]:_(s32) = G_CONSTANT i32 65535
76    ; CHECK: [[X32:%[0-9]+]]:_(s32) = G_AND {{%[0-9]+}}, [[BITS]]
77    ; CHECK: {{%[0-9]+}}:_(p0) = G_INTTOPTR [[X32]](s32)
78    ; CHECK-NOT: G_INTTOPTR {{%[0-9]+}}(s16)
79    $r0 = COPY %2(p0)
80    BX_RET 14, $noreg, implicit $r0
81...
82---
83name:            test_ptrtoint_s8
84# CHECK-LABEL: name: test_ptrtoint_s8
85legalized:       false
86# CHECK: legalized: true
87regBankSelected: false
88selected:        false
89tracksRegLiveness: true
90registers:
91  - { id: 0, class: _ }
92  - { id: 1, class: _ }
93  - { id: 2, class: _ }
94body:             |
95  bb.0:
96    liveins: $r0
97
98    %0(p0) = COPY $r0
99    %1(s8) = G_PTRTOINT %0(p0)
100    ; G_PTRTOINT with s8 should truncate
101    ; CHECK-NOT: {{%[0-9]+}}(s8) = G_PTRTOINT
102    ; CHECK: [[X32:%[0-9]+]]:_(s32) = G_PTRTOINT {{%[0-9]+}}(p0)
103    ; CHECK: [[BITS:%[0-9]+]]:_(s32) = G_CONSTANT i32 255
104    ; CHECK: {{%[0-9]+}}:_(s32) = G_AND [[X32]], [[BITS]]
105    ; CHECK-NOT: {{%[0-9]+}}(s8) = G_PTRTOINT
106    %2(s32) = G_ZEXT %1(s8)
107    $r0 = COPY %2(s32)
108    BX_RET 14, $noreg, implicit $r0
109...
110