Skip to content

Commit e7ff716

Browse files
committed
Address review comments
1 parent c0abec3 commit e7ff716

File tree

5 files changed

+27
-35
lines changed

5 files changed

+27
-35
lines changed

llvm/lib/Target/ARM/ARMInstructionSelector.cpp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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);

llvm/lib/Target/ARM/ARMLegalizerInfo.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static bool AEABI(const ARMSubtarget &ST) {
2929
return ST.isTargetAEABI() || ST.isTargetGNUAEABI() || ST.isTargetMuslAEABI();
3030
}
3131

32-
ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) : ST(&ST) {
32+
ARMLegalizerInfo::ARMLegalizerInfo(const ARMSubtarget &ST) : ST(ST) {
3333
using namespace TargetOpcode;
3434

3535
const LLT p0 = LLT::pointer(0, 32);
@@ -440,8 +440,7 @@ bool ARMLegalizerInfo::legalizeCustom(LegalizerHelper &Helper, MachineInstr &MI,
440440
case G_CONSTANT: {
441441
const ConstantInt *ConstVal = MI.getOperand(1).getCImm();
442442
uint64_t ImmVal = ConstVal->getZExtValue();
443-
if (ConstantMaterializationCost(ImmVal, ST) > 2 &&
444-
!ST->genExecuteOnly())
443+
if (ConstantMaterializationCost(ImmVal, &ST) > 2 && !ST.genExecuteOnly())
445444
return Helper.lowerConstant(MI) == LegalizerHelper::Legalized;
446445
return true;
447446
}

llvm/lib/Target/ARM/ARMLegalizerInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ARMLegalizerInfo : public LegalizerInfo {
6060
// bits.
6161
FCmpLibcallsList getFCmpLibcalls(CmpInst::Predicate, unsigned Size) const;
6262

63-
const ARMSubtarget *ST;
63+
const ARMSubtarget &ST;
6464
};
6565
} // End llvm namespace.
6666
#endif

llvm/test/CodeGen/ARM/GlobalISel/arm-legalize-const.mir

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
22
# RUN: llc -mtriple arm-- -run-pass=legalizer %s -o - | FileCheck %s
33

4-
--- |
5-
define i32 @get_const() {
6-
entry:
7-
ret i32 287454020
8-
}
9-
...
104
---
115
name: get_const
126
legalized: false

llvm/test/CodeGen/ARM/GlobalISel/select-constpool.mir

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
22
# RUN: llc -mtriple arm-- -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
33

4-
--- |
5-
define i32 @get_const() {
6-
entry:
7-
ret i32 287454020
8-
}
9-
...
104
---
115
name: get_const
126
legalized: true

0 commit comments

Comments
 (0)