Skip to content

Commit fb33270

Browse files
committed
[SelectionDAG] Refactor use of getMemBasePlusOffset() where applicable
Reduce complexity of PTRADD usage logic by harnessing getMemBasePlusOffset(). Not all uses are applicable, as ADD's order of operands might be inverted (PTRADD should always have pointer first, offset second).
1 parent b99a0b9 commit fb33270

File tree

1 file changed

+10
-27
lines changed

1 file changed

+10
-27
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,12 +4304,6 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) {
43044304
SDLoc dl = getCurSDLoc();
43054305
auto &TLI = DAG.getTargetLoweringInfo();
43064306
GEPNoWrapFlags NW = cast<GEPOperator>(I).getNoWrapFlags();
4307-
unsigned int AddOpcode = ISD::PTRADD;
4308-
4309-
if (!DAG.getTarget().shouldPreservePtrArith(
4310-
DAG.getMachineFunction().getFunction())) {
4311-
AddOpcode = ISD::ADD;
4312-
}
43134307

43144308
// Normalize Vector GEP - all scalar operands should be converted to the
43154309
// splat vector.
@@ -4341,8 +4335,8 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) {
43414335
(int64_t(Offset) >= 0 && NW.hasNoUnsignedSignedWrap()))
43424336
Flags |= SDNodeFlags::NoUnsignedWrap;
43434337

4344-
N = DAG.getNode(AddOpcode, dl, N.getValueType(), N,
4345-
DAG.getConstant(Offset, dl, N.getValueType()), Flags);
4338+
N = DAG.getMemBasePlusOffset(
4339+
N, DAG.getConstant(Offset, dl, N.getValueType()), dl, Flags);
43464340
}
43474341
} else {
43484342
// IdxSize is the width of the arithmetic according to IR semantics.
@@ -4386,7 +4380,7 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) {
43864380

43874381
OffsVal = DAG.getSExtOrTrunc(OffsVal, dl, N.getValueType());
43884382

4389-
N = DAG.getNode(AddOpcode, dl, N.getValueType(), N, OffsVal, Flags);
4383+
N = DAG.getMemBasePlusOffset(N, OffsVal, dl, Flags);
43904384
continue;
43914385
}
43924386

@@ -4446,7 +4440,7 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) {
44464440
SDNodeFlags AddFlags;
44474441
AddFlags.setNoUnsignedWrap(NW.hasNoUnsignedWrap());
44484442

4449-
N = DAG.getNode(AddOpcode, dl, N.getValueType(), N, IdxN, AddFlags);
4443+
N = DAG.getMemBasePlusOffset(N, IdxN, dl, AddFlags);
44504444
}
44514445
}
44524446

@@ -4515,7 +4509,7 @@ void SelectionDAGBuilder::visitAlloca(const AllocaInst &I) {
45154509
} else {
45164510
AllocSize = DAG.getNode(ISD::ADD, dl, AllocSize.getValueType(), AllocSize,
45174511
DAG.getConstant(StackAlignMask, dl, IntPtr),
4518-
SDNodeFlags::NoUnsignedWrap);
4512+
SDNodeFlags::NoUnsignedWrap);
45194513
}
45204514

45214515
// Mask out the low bits for alignment purposes.
@@ -9214,13 +9208,8 @@ bool SelectionDAGBuilder::visitMemPCpyCall(const CallInst &I) {
92149208
Size = DAG.getSExtOrTrunc(Size, sdl, Dst.getValueType());
92159209

92169210
// Adjust return pointer to point just past the last dst byte.
9217-
unsigned int AddOpcode = ISD::PTRADD;
9218-
if (!DAG.getTarget().shouldPreservePtrArith(
9219-
DAG.getMachineFunction().getFunction())) {
9220-
AddOpcode = ISD::ADD;
9221-
}
9222-
SDValue DstPlusSize =
9223-
DAG.getNode(AddOpcode, sdl, Dst.getValueType(), Dst, Size);
9211+
SDNodeFlags Flags;
9212+
SDValue DstPlusSize = DAG.getMemBasePlusOffset(Dst, Size, sdl, Flags);
92249213
setValue(&I, DstPlusSize);
92259214
return true;
92269215
}
@@ -11317,15 +11306,9 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
1131711306
MachineFunction &MF = CLI.DAG.getMachineFunction();
1131811307
Align HiddenSRetAlign = MF.getFrameInfo().getObjectAlign(DemoteStackIdx);
1131911308
for (unsigned i = 0; i < NumValues; ++i) {
11320-
unsigned int AddOpcode = ISD::PTRADD;
11321-
if (!CLI.DAG.getTarget().shouldPreservePtrArith(
11322-
CLI.DAG.getMachineFunction().getFunction())) {
11323-
AddOpcode = ISD::ADD;
11324-
}
11325-
SDValue Add = CLI.DAG.getNode(
11326-
AddOpcode, CLI.DL, PtrVT, DemoteStackSlot,
11327-
CLI.DAG.getConstant(Offsets[i], CLI.DL, PtrVT),
11328-
SDNodeFlags::NoUnisgnedWrap);
11309+
SDValue Add = CLI.DAG.getMemBasePlusOffset(
11310+
DemoteStackSlot, CLI.DAG.getConstant(Offsets[i], CLI.DL, PtrVT),
11311+
CLI.DL, SDNodeFlags::NoUnsignedWrap);
1132911312
SDValue L = CLI.DAG.getLoad(
1133011313
RetTys[i], CLI.DL, CLI.Chain, Add,
1133111314
MachinePointerInfo::getFixedStack(CLI.DAG.getMachineFunction(),

0 commit comments

Comments
 (0)