1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -mtriple=aarch64-unknown-unknown -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
4 # Test using the xro addressing mode with immediates. This should be done for
5 # wide constants which are preferably selected using a mov rather than an add.
9 name: use_xro_cannot_encode_add_lsl
13 tracksRegLiveness: true
17 ; Check that we use the XRO addressing mode when the constant cannot be
18 ; represented using an add + lsl.
20 ; cst = 0000000111000000
21 ; cst & 000fffffff000000 != 0
23 ; CHECK-LABEL: name: use_xro_cannot_encode_add_lsl
26 ; CHECK-NEXT: %copy:gpr64sp = COPY $x0
27 ; CHECK-NEXT: %cst:gpr64 = MOVi64imm 4580179968
28 ; CHECK-NEXT: %load:gpr64 = LDRXroX %copy, %cst, 0, 0 :: (volatile load (s64))
29 ; CHECK-NEXT: RET_ReallyLR
30 %copy:gpr(p0) = COPY $x0
31 %cst:gpr(s64) = G_CONSTANT i64 4580179968
32 %addr:gpr(p0) = G_PTR_ADD %copy, %cst(s64)
33 %load:gpr(s64) = G_LOAD %addr(p0) :: (volatile load (s64))
38 name: use_xro_preferred_mov
42 tracksRegLiveness: true
46 ; Check that we use the XRO addressing mode when the constant can be
47 ; represented using a single movk.
49 ; cst = 000000000000f000
50 ; cst & 000fffffff000000 == 0
51 ; cst & ffffffffffff0fff != 0
53 ; CHECK-LABEL: name: use_xro_preferred_mov
56 ; CHECK-NEXT: %copy:gpr64sp = COPY $x0
57 ; CHECK-NEXT: [[MOVi32imm:%[0-9]+]]:gpr32 = MOVi32imm 61440
58 ; CHECK-NEXT: %cst:gpr64 = SUBREG_TO_REG 0, [[MOVi32imm]], %subreg.sub_32
59 ; CHECK-NEXT: %load:gpr64 = LDRXroX %copy, %cst, 0, 0 :: (volatile load (s64))
60 ; CHECK-NEXT: RET_ReallyLR
61 %copy:gpr(p0) = COPY $x0
62 %cst:gpr(s64) = G_CONSTANT i64 61440
63 %addr:gpr(p0) = G_PTR_ADD %copy, %cst(s64)
64 %load:gpr(s64) = G_LOAD %addr(p0) :: (volatile load (s64))
69 name: use_xro_negative_imm
73 tracksRegLiveness: true
77 ; Check that this works even if we have a negative immediate.
79 ; CHECK-LABEL: name: use_xro_negative_imm
82 ; CHECK-NEXT: %copy:gpr64sp = COPY $x0
83 ; CHECK-NEXT: %cst:gpr64 = MOVi64imm -61440
84 ; CHECK-NEXT: %load:gpr64 = LDRXroX %copy, %cst, 0, 0 :: (volatile load (s64))
85 ; CHECK-NEXT: RET_ReallyLR
86 %copy:gpr(p0) = COPY $x0
87 %cst:gpr(s64) = G_CONSTANT i64 -61440
88 %addr:gpr(p0) = G_PTR_ADD %copy, %cst(s64)
89 %load:gpr(s64) = G_LOAD %addr(p0) :: (volatile load (s64))
94 name: dont_use_xro_selectable_imm
98 tracksRegLiveness: true
102 ; Immediates that can be encoded in a LDRXui should be skipped.
104 ; CHECK-LABEL: name: dont_use_xro_selectable_imm
105 ; CHECK: liveins: $x0
107 ; CHECK-NEXT: %copy:gpr64sp = COPY $x0
108 ; CHECK-NEXT: %load:gpr64 = LDRXui %copy, 2 :: (volatile load (s64))
109 ; CHECK-NEXT: RET_ReallyLR
110 %copy:gpr(p0) = COPY $x0
111 %cst:gpr(s64) = G_CONSTANT i64 16
112 %addr:gpr(p0) = G_PTR_ADD %copy, %cst(s64)
113 %load:gpr(s64) = G_LOAD %addr(p0) :: (volatile load (s64))
118 name: dont_use_xro_selectable_negative_imm
121 regBankSelected: true
122 tracksRegLiveness: true
126 ; Immediates that can be encoded in a LDRXui should be skipped.
128 ; CHECK-LABEL: name: dont_use_xro_selectable_negative_imm
129 ; CHECK: liveins: $x0
131 ; CHECK-NEXT: %copy:gpr64sp = COPY $x0
132 ; CHECK-NEXT: %load:gpr64 = LDURXi %copy, -16 :: (volatile load (s64))
133 ; CHECK-NEXT: RET_ReallyLR
134 %copy:gpr(p0) = COPY $x0
135 %cst:gpr(s64) = G_CONSTANT i64 -16
136 %addr:gpr(p0) = G_PTR_ADD %copy, %cst(s64)
137 %load:gpr(s64) = G_LOAD %addr(p0) :: (volatile load (s64))
142 name: dont_use_xro_zero
145 regBankSelected: true
146 tracksRegLiveness: true
150 ; Immediates that can be encoded in a LDRXui should be skipped.
152 ; CHECK-LABEL: name: dont_use_xro_zero
153 ; CHECK: liveins: $x0
155 ; CHECK-NEXT: %copy:gpr64sp = COPY $x0
156 ; CHECK-NEXT: %load:gpr64 = LDRXui %copy, 0 :: (volatile load (s64))
157 ; CHECK-NEXT: RET_ReallyLR
158 %copy:gpr(p0) = COPY $x0
159 %cst:gpr(s64) = G_CONSTANT i64 0
160 %addr:gpr(p0) = G_PTR_ADD %copy, %cst(s64)
161 %load:gpr(s64) = G_LOAD %addr(p0) :: (volatile load (s64))
166 name: dont_use_xro_in_range
169 regBankSelected: true
170 tracksRegLiveness: true
174 ; Check that we skip constants which can be encoded in an add.
175 ; 17 is in [0x0, 0xfff]
177 ; CHECK-LABEL: name: dont_use_xro_in_range
178 ; CHECK: liveins: $x0
180 ; CHECK-NEXT: %copy:gpr64sp = COPY $x0
181 ; CHECK-NEXT: %load:gpr64 = LDURXi %copy, 17 :: (volatile load (s64))
182 ; CHECK-NEXT: RET_ReallyLR
183 %copy:gpr(p0) = COPY $x0
184 %cst:gpr(s64) = G_CONSTANT i64 17
185 %addr:gpr(p0) = G_PTR_ADD %copy, %cst(s64)
186 %load:gpr(s64) = G_LOAD %addr(p0) :: (volatile load (s64))
191 name: dont_use_xro_add_lsl
194 regBankSelected: true
195 tracksRegLiveness: true
199 ; Check that we skip when we have an add with an lsl which cannot be
200 ; represented as a movk.
202 ; cst = 0x0000000000111000
203 ; cst & 000fffffff000000 = 0
204 ; cst & ffffffffff00ffff != 0
205 ; cst & ffffffffffff0fff != 0
207 ; CHECK-LABEL: name: dont_use_xro_add_lsl
208 ; CHECK: liveins: $x0
210 ; CHECK-NEXT: %copy:gpr64 = COPY $x0
211 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr64common = COPY %copy
212 ; CHECK-NEXT: %addr:gpr64sp = ADDXri [[COPY]], 273, 12
213 ; CHECK-NEXT: %load:gpr64 = LDRXui %addr, 0 :: (volatile load (s64))
214 ; CHECK-NEXT: RET_ReallyLR
215 %copy:gpr(p0) = COPY $x0
216 %cst:gpr(s64) = G_CONSTANT i64 1118208
217 %addr:gpr(p0) = G_PTR_ADD %copy, %cst(s64)
218 %load:gpr(s64) = G_LOAD %addr(p0) :: (volatile load (s64))