Skip to content

Commit e74c5b9

Browse files
committed
[globalisel] Rename G_GEP to G_PTR_ADD
Summary: G_GEP is rather poorly named. It's a simple pointer+scalar addition and doesn't support any of the complexities of getelementptr. I therefore propose that we rename it. There's a G_PTR_MASK so let's follow that convention and go with G_PTR_ADD Reviewers: volkan, aditya_nandakumar, bogner, rovka, arsenm Subscribers: sdardis, jvesely, wdng, nhaehnle, hiraditya, jrtc27, atanasyan, arphaman, Petar.Avramovic, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69734
1 parent de56a89 commit e74c5b9

File tree

125 files changed

+7224
-7222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+7224
-7222
lines changed

llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class CombinerHelper {
134134
///
135135
/// For example (pre-indexed):
136136
///
137-
/// $addr = G_GEP $base, $offset
137+
/// $addr = G_PTR_ADD $base, $offset
138138
/// [...]
139139
/// $val = G_LOAD $addr
140140
/// [...]
@@ -150,7 +150,7 @@ class CombinerHelper {
150150
///
151151
/// G_STORE $val, $base
152152
/// [...]
153-
/// $addr = G_GEP $base, $offset
153+
/// $addr = G_PTR_ADD $base, $offset
154154
/// [...]
155155
/// $whatever = COPY $addr
156156
///

llvm/include/llvm/CodeGen/GlobalISel/InstructionSelector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ class InstructionSelector {
487487
bool isOperandImmEqual(const MachineOperand &MO, int64_t Value,
488488
const MachineRegisterInfo &MRI) const;
489489

490-
/// Return true if the specified operand is a G_GEP with a G_CONSTANT on the
490+
/// Return true if the specified operand is a G_PTR_ADD with a G_CONSTANT on the
491491
/// right-hand side. GlobalISel's separation of pointer and integer types
492492
/// means that we don't need to worry about G_OR with equivalent semantics.
493493
bool isBaseWithConstantOffset(const MachineOperand &Root,

llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ class LegalizerInfo {
11781178
/// {65, NarrowScalar} // bit sizes [65, +inf[
11791179
/// });
11801180
/// It may be that only 64-bit pointers are supported on your target:
1181-
/// setPointerAction(G_GEP, 0, LLT:pointer(1),
1181+
/// setPointerAction(G_PTR_ADD, 0, LLT:pointer(1),
11821182
/// {{1, Unsupported}, // bit sizes [ 1, 63[
11831183
/// {64, Legal}, // bit sizes [64, 65[
11841184
/// {65, Unsupported}, // bit sizes [65, +inf[

llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ class MachineIRBuilder {
404404
/// \return a MachineInstrBuilder for the newly created instruction.
405405
MachineInstrBuilder buildGlobalValue(const DstOp &Res, const GlobalValue *GV);
406406

407-
/// Build and insert \p Res = G_GEP \p Op0, \p Op1
407+
/// Build and insert \p Res = G_PTR_ADD \p Op0, \p Op1
408408
///
409-
/// G_GEP adds \p Op1 bytes to the pointer specified by \p Op0,
409+
/// G_PTR_ADD adds \p Op1 bytes to the pointer specified by \p Op0,
410410
/// storing the resulting pointer in \p Res.
411411
///
412412
/// \pre setBasicBlock or setMI must have been called.
@@ -415,28 +415,28 @@ class MachineIRBuilder {
415415
/// \pre \p Op1 must be a generic virtual register with scalar type.
416416
///
417417
/// \return a MachineInstrBuilder for the newly created instruction.
418-
MachineInstrBuilder buildGEP(const DstOp &Res, const SrcOp &Op0,
419-
const SrcOp &Op1);
418+
MachineInstrBuilder buildPtrAdd(const DstOp &Res, const SrcOp &Op0,
419+
const SrcOp &Op1);
420420

421-
/// Materialize and insert \p Res = G_GEP \p Op0, (G_CONSTANT \p Value)
421+
/// Materialize and insert \p Res = G_PTR_ADD \p Op0, (G_CONSTANT \p Value)
422422
///
423-
/// G_GEP adds \p Value bytes to the pointer specified by \p Op0,
423+
/// G_PTR_ADD adds \p Value bytes to the pointer specified by \p Op0,
424424
/// storing the resulting pointer in \p Res. If \p Value is zero then no
425-
/// G_GEP or G_CONSTANT will be created and \pre Op0 will be assigned to
425+
/// G_PTR_ADD or G_CONSTANT will be created and \pre Op0 will be assigned to
426426
/// \p Res.
427427
///
428428
/// \pre setBasicBlock or setMI must have been called.
429429
/// \pre \p Op0 must be a generic virtual register with pointer type.
430430
/// \pre \p ValueTy must be a scalar type.
431431
/// \pre \p Res must be 0. This is to detect confusion between
432-
/// materializeGEP() and buildGEP().
432+
/// materializePtrAdd() and buildPtrAdd().
433433
/// \post \p Res will either be a new generic virtual register of the same
434434
/// type as \p Op0 or \p Op0 itself.
435435
///
436436
/// \return a MachineInstrBuilder for the newly created instruction.
437-
Optional<MachineInstrBuilder> materializeGEP(Register &Res, Register Op0,
438-
const LLT &ValueTy,
439-
uint64_t Value);
437+
Optional<MachineInstrBuilder> materializePtrAdd(Register &Res, Register Op0,
438+
const LLT &ValueTy,
439+
uint64_t Value);
440440

441441
/// Build and insert \p Res = G_PTR_MASK \p Op0, \p NumBits
442442
///

llvm/include/llvm/Support/TargetOpcodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ HANDLE_TARGET_OPCODE(G_FMINIMUM)
524524
HANDLE_TARGET_OPCODE(G_FMAXIMUM)
525525

526526
/// Generic pointer offset
527-
HANDLE_TARGET_OPCODE(G_GEP)
527+
HANDLE_TARGET_OPCODE(G_PTR_ADD)
528528

529529
/// Clear the specified number of low bits in a pointer. This rounds the value
530530
/// *down* to the given alignment.

llvm/include/llvm/Target/GenericOpcodes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def G_SELECT : GenericInstruction {
330330
}
331331

332332
// Generic pointer offset.
333-
def G_GEP : GenericInstruction {
333+
def G_PTR_ADD : GenericInstruction {
334334
let OutOperandList = (outs type0:$dst);
335335
let InOperandList = (ins type0:$src1, type1:$src2);
336336
let hasSideEffects = 0;

llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool CSEConfigFull::shouldCSEOpc(unsigned Opc) {
5252
case TargetOpcode::G_ANYEXT:
5353
case TargetOpcode::G_UNMERGE_VALUES:
5454
case TargetOpcode::G_TRUNC:
55-
case TargetOpcode::G_GEP:
55+
case TargetOpcode::G_PTR_ADD:
5656
return true;
5757
}
5858
return false;

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ bool CombinerHelper::findPostIndexCandidate(MachineInstr &MI, Register &Addr,
571571
LLVM_DEBUG(dbgs() << "Searching for post-indexing opportunity for: " << MI);
572572

573573
for (auto &Use : MRI.use_instructions(Base)) {
574-
if (Use.getOpcode() != TargetOpcode::G_GEP)
574+
if (Use.getOpcode() != TargetOpcode::G_PTR_ADD)
575575
continue;
576576

577577
Offset = Use.getOperand(2).getReg();
@@ -597,8 +597,8 @@ bool CombinerHelper::findPostIndexCandidate(MachineInstr &MI, Register &Addr,
597597
// forming an indexed one.
598598

599599
bool MemOpDominatesAddrUses = true;
600-
for (auto &GEPUse : MRI.use_instructions(Use.getOperand(0).getReg())) {
601-
if (!dominates(MI, GEPUse)) {
600+
for (auto &PtrAddUse : MRI.use_instructions(Use.getOperand(0).getReg())) {
601+
if (!dominates(MI, PtrAddUse)) {
602602
MemOpDominatesAddrUses = false;
603603
break;
604604
}
@@ -631,7 +631,7 @@ bool CombinerHelper::findPreIndexCandidate(MachineInstr &MI, Register &Addr,
631631
#endif
632632

633633
Addr = MI.getOperand(1).getReg();
634-
MachineInstr *AddrDef = getOpcodeDef(TargetOpcode::G_GEP, Addr, MRI);
634+
MachineInstr *AddrDef = getOpcodeDef(TargetOpcode::G_PTR_ADD, Addr, MRI);
635635
if (!AddrDef || MRI.hasOneUse(Addr))
636636
return false;
637637

@@ -667,8 +667,8 @@ bool CombinerHelper::findPreIndexCandidate(MachineInstr &MI, Register &Addr,
667667
}
668668
}
669669

670-
// FIXME: check whether all uses of the base pointer are constant GEPs. That
671-
// might allow us to end base's liveness here by adjusting the constant.
670+
// FIXME: check whether all uses of the base pointer are constant PtrAdds.
671+
// That might allow us to end base's liveness here by adjusting the constant.
672672

673673
for (auto &UseMI : MRI.use_instructions(Addr)) {
674674
if (!dominates(MI, UseMI)) {
@@ -1016,7 +1016,7 @@ bool CombinerHelper::optimizeMemset(MachineInstr &MI, Register Dst, Register Val
10161016
if (DstOff != 0) {
10171017
auto Offset =
10181018
MIB.buildConstant(LLT::scalar(PtrTy.getSizeInBits()), DstOff);
1019-
Ptr = MIB.buildGEP(PtrTy, Dst, Offset).getReg(0);
1019+
Ptr = MIB.buildPtrAdd(PtrTy, Dst, Offset).getReg(0);
10201020
}
10211021

10221022
MIB.buildStore(Value, Ptr, *StoreMMO);
@@ -1121,13 +1121,13 @@ bool CombinerHelper::optimizeMemcpy(MachineInstr &MI, Register Dst,
11211121
if (CurrOffset != 0) {
11221122
Offset = MIB.buildConstant(LLT::scalar(PtrTy.getSizeInBits()), CurrOffset)
11231123
.getReg(0);
1124-
LoadPtr = MIB.buildGEP(PtrTy, Src, Offset).getReg(0);
1124+
LoadPtr = MIB.buildPtrAdd(PtrTy, Src, Offset).getReg(0);
11251125
}
11261126
auto LdVal = MIB.buildLoad(CopyTy, LoadPtr, *LoadMMO);
11271127

11281128
// Create the store.
11291129
Register StorePtr =
1130-
CurrOffset == 0 ? Dst : MIB.buildGEP(PtrTy, Dst, Offset).getReg(0);
1130+
CurrOffset == 0 ? Dst : MIB.buildPtrAdd(PtrTy, Dst, Offset).getReg(0);
11311131
MIB.buildStore(LdVal, StorePtr, *StoreMMO);
11321132
CurrOffset += CopyTy.getSizeInBytes();
11331133
Size -= CopyTy.getSizeInBytes();
@@ -1218,7 +1218,7 @@ bool CombinerHelper::optimizeMemmove(MachineInstr &MI, Register Dst,
12181218
if (CurrOffset != 0) {
12191219
auto Offset =
12201220
MIB.buildConstant(LLT::scalar(PtrTy.getSizeInBits()), CurrOffset);
1221-
LoadPtr = MIB.buildGEP(PtrTy, Src, Offset).getReg(0);
1221+
LoadPtr = MIB.buildPtrAdd(PtrTy, Src, Offset).getReg(0);
12221222
}
12231223
LoadVals.push_back(MIB.buildLoad(CopyTy, LoadPtr, *LoadMMO).getReg(0));
12241224
CurrOffset += CopyTy.getSizeInBytes();
@@ -1235,7 +1235,7 @@ bool CombinerHelper::optimizeMemmove(MachineInstr &MI, Register Dst,
12351235
if (CurrOffset != 0) {
12361236
auto Offset =
12371237
MIB.buildConstant(LLT::scalar(PtrTy.getSizeInBits()), CurrOffset);
1238-
StorePtr = MIB.buildGEP(PtrTy, Dst, Offset).getReg(0);
1238+
StorePtr = MIB.buildPtrAdd(PtrTy, Dst, Offset).getReg(0);
12391239
}
12401240
MIB.buildStore(LoadVals[I], StorePtr, *StoreMMO);
12411241
CurrOffset += CopyTy.getSizeInBytes();

llvm/lib/CodeGen/GlobalISel/GISelKnownBits.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ void GISelKnownBits::computeKnownBitsImpl(Register R, KnownBits &Known,
179179
Known.Zero = KnownZeroOut;
180180
break;
181181
}
182-
case TargetOpcode::G_GEP: {
183-
// G_GEP is like G_ADD. FIXME: Is this true for all targets?
182+
case TargetOpcode::G_PTR_ADD: {
183+
// G_PTR_ADD is like G_ADD. FIXME: Is this true for all targets?
184184
LLT Ty = MRI.getType(MI.getOperand(1).getReg());
185185
if (DL.isNonIntegralAddressSpace(Ty.getAddressSpace()))
186186
break;

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ bool IRTranslator::translateLoad(const User &U, MachineIRBuilder &MIRBuilder) {
885885
Regs.size() == 1 ? LI.getMetadata(LLVMContext::MD_range) : nullptr;
886886
for (unsigned i = 0; i < Regs.size(); ++i) {
887887
Register Addr;
888-
MIRBuilder.materializeGEP(Addr, Base, OffsetTy, Offsets[i] / 8);
888+
MIRBuilder.materializePtrAdd(Addr, Base, OffsetTy, Offsets[i] / 8);
889889

890890
MachinePointerInfo Ptr(LI.getPointerOperand(), Offsets[i] / 8);
891891
unsigned BaseAlign = getMemOpAlignment(LI);
@@ -926,7 +926,7 @@ bool IRTranslator::translateStore(const User &U, MachineIRBuilder &MIRBuilder) {
926926

927927
for (unsigned i = 0; i < Vals.size(); ++i) {
928928
Register Addr;
929-
MIRBuilder.materializeGEP(Addr, Base, OffsetTy, Offsets[i] / 8);
929+
MIRBuilder.materializePtrAdd(Addr, Base, OffsetTy, Offsets[i] / 8);
930930

931931
MachinePointerInfo Ptr(SI.getPointerOperand(), Offsets[i] / 8);
932932
unsigned BaseAlign = getMemOpAlignment(SI);
@@ -1080,8 +1080,8 @@ bool IRTranslator::translateGetElementPtr(const User &U,
10801080
if (Offset != 0) {
10811081
LLT OffsetTy = getLLTForType(*OffsetIRTy, *DL);
10821082
auto OffsetMIB = MIRBuilder.buildConstant({OffsetTy}, Offset);
1083-
BaseReg =
1084-
MIRBuilder.buildGEP(PtrTy, BaseReg, OffsetMIB.getReg(0)).getReg(0);
1083+
BaseReg = MIRBuilder.buildPtrAdd(PtrTy, BaseReg, OffsetMIB.getReg(0))
1084+
.getReg(0);
10851085
Offset = 0;
10861086
}
10871087

@@ -1100,14 +1100,14 @@ bool IRTranslator::translateGetElementPtr(const User &U,
11001100
} else
11011101
GepOffsetReg = IdxReg;
11021102

1103-
BaseReg = MIRBuilder.buildGEP(PtrTy, BaseReg, GepOffsetReg).getReg(0);
1103+
BaseReg = MIRBuilder.buildPtrAdd(PtrTy, BaseReg, GepOffsetReg).getReg(0);
11041104
}
11051105
}
11061106

11071107
if (Offset != 0) {
11081108
auto OffsetMIB =
11091109
MIRBuilder.buildConstant(getLLTForType(*OffsetIRTy, *DL), Offset);
1110-
MIRBuilder.buildGEP(getOrCreateVReg(U), BaseReg, OffsetMIB.getReg(0));
1110+
MIRBuilder.buildPtrAdd(getOrCreateVReg(U), BaseReg, OffsetMIB.getReg(0));
11111111
return true;
11121112
}
11131113

0 commit comments

Comments
 (0)