@@ -152,6 +152,7 @@ class AArch64FastISel : public FastISel {
152
152
unsigned Emit_LSR_ri (MVT RetVT, unsigned Op0, bool Op0IsKill, uint64_t Imm);
153
153
unsigned Emit_ASR_ri (MVT RetVT, unsigned Op0, bool Op0IsKill, uint64_t Imm);
154
154
155
+ unsigned AArch64MaterializeInt (const ConstantInt *CI, MVT VT);
155
156
unsigned AArch64MaterializeFP (const ConstantFP *CFP, MVT VT);
156
157
unsigned AArch64MaterializeGV (const GlobalValue *GV);
157
158
@@ -213,28 +214,28 @@ unsigned AArch64FastISel::TargetMaterializeAlloca(const AllocaInst *AI) {
213
214
return 0 ;
214
215
}
215
216
217
+ unsigned AArch64FastISel::AArch64MaterializeInt (const ConstantInt *CI, MVT VT) {
218
+ if (VT > MVT::i64 )
219
+ return 0 ;
220
+ return FastEmit_i (VT, VT, ISD::Constant, CI->getZExtValue ());
221
+ }
222
+
216
223
unsigned AArch64FastISel::AArch64MaterializeFP (const ConstantFP *CFP, MVT VT) {
217
224
if (VT != MVT::f32 && VT != MVT::f64 )
218
225
return 0 ;
219
226
220
227
const APFloat Val = CFP->getValueAPF ();
221
- bool is64bit = (VT == MVT::f64 );
228
+ bool Is64Bit = (VT == MVT::f64 );
222
229
223
230
// This checks to see if we can use FMOV instructions to materialize
224
231
// a constant, otherwise we have to materialize via the constant pool.
225
232
if (TLI.isFPImmLegal (Val, VT)) {
226
- int Imm;
227
- unsigned Opc;
228
- if (is64bit) {
229
- Imm = AArch64_AM::getFP64Imm (Val);
230
- Opc = AArch64::FMOVDi;
231
- } else {
232
- Imm = AArch64_AM::getFP32Imm (Val);
233
- Opc = AArch64::FMOVSi;
234
- }
233
+ int Imm = Is64Bit ? AArch64_AM::getFP64Imm (Val)
234
+ : AArch64_AM::getFP32Imm (Val);
235
+ unsigned Opc = Is64Bit ? AArch64::FMOVDi : AArch64::FMOVSi;
235
236
unsigned ResultReg = createResultReg (TLI.getRegClassFor (VT));
236
237
BuildMI (*FuncInfo.MBB , FuncInfo.InsertPt , DbgLoc, TII.get (Opc), ResultReg)
237
- .addImm (Imm);
238
+ .addImm (Imm);
238
239
return ResultReg;
239
240
}
240
241
@@ -244,16 +245,17 @@ unsigned AArch64FastISel::AArch64MaterializeFP(const ConstantFP *CFP, MVT VT) {
244
245
if (Align == 0 )
245
246
Align = DL.getTypeAllocSize (CFP->getType ());
246
247
247
- unsigned Idx = MCP.getConstantPoolIndex (cast<Constant>(CFP), Align);
248
+ unsigned CPI = MCP.getConstantPoolIndex (cast<Constant>(CFP), Align);
248
249
unsigned ADRPReg = createResultReg (&AArch64::GPR64commonRegClass);
249
250
BuildMI (*FuncInfo.MBB , FuncInfo.InsertPt , DbgLoc, TII.get (AArch64::ADRP),
250
- ADRPReg).addConstantPoolIndex (Idx, 0 , AArch64II::MO_PAGE);
251
+ ADRPReg)
252
+ .addConstantPoolIndex (CPI, 0 , AArch64II::MO_PAGE);
251
253
252
- unsigned Opc = is64bit ? AArch64::LDRDui : AArch64::LDRSui;
254
+ unsigned Opc = Is64Bit ? AArch64::LDRDui : AArch64::LDRSui;
253
255
unsigned ResultReg = createResultReg (TLI.getRegClassFor (VT));
254
256
BuildMI (*FuncInfo.MBB , FuncInfo.InsertPt , DbgLoc, TII.get (Opc), ResultReg)
255
- .addReg (ADRPReg)
256
- .addConstantPoolIndex (Idx , 0 , AArch64II::MO_PAGEOFF | AArch64II::MO_NC);
257
+ .addReg (ADRPReg)
258
+ .addConstantPoolIndex (CPI , 0 , AArch64II::MO_PAGEOFF | AArch64II::MO_NC);
257
259
return ResultReg;
258
260
}
259
261
@@ -280,25 +282,26 @@ unsigned AArch64FastISel::AArch64MaterializeGV(const GlobalValue *GV) {
280
282
// ADRP + LDRX
281
283
BuildMI (*FuncInfo.MBB , FuncInfo.InsertPt , DbgLoc, TII.get (AArch64::ADRP),
282
284
ADRPReg)
283
- .addGlobalAddress (GV, 0 , AArch64II::MO_GOT | AArch64II::MO_PAGE);
285
+ .addGlobalAddress (GV, 0 , AArch64II::MO_GOT | AArch64II::MO_PAGE);
284
286
285
287
ResultReg = createResultReg (&AArch64::GPR64RegClass);
286
288
BuildMI (*FuncInfo.MBB , FuncInfo.InsertPt , DbgLoc, TII.get (AArch64::LDRXui),
287
289
ResultReg)
288
- .addReg (ADRPReg)
289
- .addGlobalAddress (GV, 0 , AArch64II::MO_GOT | AArch64II::MO_PAGEOFF |
290
- AArch64II::MO_NC);
290
+ .addReg (ADRPReg)
291
+ .addGlobalAddress (GV, 0 , AArch64II::MO_GOT | AArch64II::MO_PAGEOFF |
292
+ AArch64II::MO_NC);
291
293
} else {
292
294
// ADRP + ADDX
293
295
BuildMI (*FuncInfo.MBB , FuncInfo.InsertPt , DbgLoc, TII.get (AArch64::ADRP),
294
- ADRPReg).addGlobalAddress (GV, 0 , AArch64II::MO_PAGE);
296
+ ADRPReg)
297
+ .addGlobalAddress (GV, 0 , AArch64II::MO_PAGE);
295
298
296
299
ResultReg = createResultReg (&AArch64::GPR64spRegClass);
297
300
BuildMI (*FuncInfo.MBB , FuncInfo.InsertPt , DbgLoc, TII.get (AArch64::ADDXri),
298
301
ResultReg)
299
- .addReg (ADRPReg)
300
- .addGlobalAddress (GV, 0 , AArch64II::MO_PAGEOFF | AArch64II::MO_NC)
301
- .addImm (0 );
302
+ .addReg (ADRPReg)
303
+ .addGlobalAddress (GV, 0 , AArch64II::MO_PAGEOFF | AArch64II::MO_NC)
304
+ .addImm (0 );
302
305
}
303
306
return ResultReg;
304
307
}
@@ -311,8 +314,9 @@ unsigned AArch64FastISel::TargetMaterializeConstant(const Constant *C) {
311
314
return 0 ;
312
315
MVT VT = CEVT.getSimpleVT ();
313
316
314
- // FIXME: Handle ConstantInt.
315
- if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
317
+ if (const auto *CI = dyn_cast<ConstantInt>(C))
318
+ return AArch64MaterializeInt (CI, VT);
319
+ else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
316
320
return AArch64MaterializeFP (CFP, VT);
317
321
else if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
318
322
return AArch64MaterializeGV (GV);
0 commit comments