1414#include " ARMSubtarget.h"
1515#include " ARMTargetMachine.h"
1616#include " llvm/CodeGen/GlobalISel/GIMatchTableExecutorImpl.h"
17+ #include " llvm/CodeGen/GlobalISel/GenericMachineInstrs.h"
1718#include " llvm/CodeGen/GlobalISel/InstructionSelector.h"
1819#include " llvm/CodeGen/MachineConstantPool.h"
1920#include " llvm/CodeGen/MachineRegisterInfo.h"
@@ -1088,7 +1089,7 @@ bool ARMInstructionSelector::select(MachineInstr &I) {
10881089 return selectGlobal (MIB, MRI);
10891090 case G_STORE:
10901091 case G_LOAD: {
1091- const auto &MemOp = **I.memoperands_begin ();
1092+ auto &MemOp = **I.memoperands_begin ();
10921093 if (MemOp.isAtomic ()) {
10931094 LLVM_DEBUG (dbgs () << " Atomic load/store not supported yet\n " );
10941095 return false ;
@@ -1103,24 +1104,28 @@ bool ARMInstructionSelector::select(MachineInstr &I) {
11031104 assert ((ValSize != 64 || STI.hasVFP2Base ()) &&
11041105 " Don't know how to load/store 64-bit value without VFP" );
11051106
1106- MachineInstr *Ptr = MRI.getVRegDef (I.getOperand (1 ).getReg ());
1107- if (Ptr->getOpcode () == TargetOpcode::G_CONSTANT_POOL) {
1108- unsigned Opcode;
1109- if (Subtarget->isThumb ())
1110- Opcode = ARM::tLDRpci;
1111- else
1112- Opcode = ARM::LDRcp;
1113-
1114- auto Instr = BuildMI (MBB, I, I.getDebugLoc (), TII.get (Opcode))
1115- .addDef (Reg)
1116- .add (Ptr->getOperand (1 ))
1117- .addImm (0 )
1118- .add (predOps (ARMCC::AL))
1119- .addMemOperand (I.memoperands ().front ());
1120- if (!constrainSelectedInstRegOperands (*Instr, TII, TRI, RBI))
1121- return false ;
1122- I.eraseFromParent ();
1123- return true ;
1107+ if (auto *LoadMI = dyn_cast<GLoad>(&I)) {
1108+ Register PtrReg = LoadMI->getPointerReg ();
1109+ MachineInstr *Ptr = MRI.getVRegDef (PtrReg);
1110+ if (Ptr->getOpcode () == TargetOpcode::G_CONSTANT_POOL) {
1111+ const MachineOperand &Index = Ptr->getOperand (1 );
1112+ unsigned Opcode;
1113+ if (Subtarget->isThumb ())
1114+ Opcode = ARM::tLDRpci;
1115+ else
1116+ Opcode = ARM::LDRcp;
1117+
1118+ auto Instr = BuildMI (MBB, I, I.getDebugLoc (), TII.get (Opcode))
1119+ .addDef (Reg)
1120+ .add (Index)
1121+ .addImm (0 )
1122+ .add (predOps (ARMCC::AL))
1123+ .addMemOperand (&MemOp);
1124+ if (!constrainSelectedInstRegOperands (*Instr, TII, TRI, RBI))
1125+ return false ;
1126+ I.eraseFromParent ();
1127+ return true ;
1128+ }
11241129 }
11251130
11261131 const auto NewOpc = selectLoadStoreOpCode (I.getOpcode (), RegBank, ValSize);
0 commit comments