Skip to content

Commit f799d08

Browse files
committed
[CodeGen] Remove handling for lifetime.start/end on non-alloca
After llvm#149310 we are guaranteed that the argument is an alloca, so we don't need to look at underlying objects (which was not a correct thing to do anyway). This also drops the offset argumnet for lifetime nodes in SDAG. The offset is fixed to zero now. (Peculiarly, while SDAG pretended to have an offset, it just gets silently dropped during selection.)
1 parent c9fe19a commit f799d08

File tree

8 files changed

+28
-77
lines changed

8 files changed

+28
-77
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,10 +1425,9 @@ class SelectionDAG {
14251425

14261426
/// Creates a LifetimeSDNode that starts (`IsStart==true`) or ends
14271427
/// (`IsStart==false`) the lifetime of the portion of `FrameIndex` between
1428-
/// offsets `Offset` and `Offset + Size`.
1428+
/// offsets `0` and `Size`.
14291429
LLVM_ABI SDValue getLifetimeNode(bool IsStart, const SDLoc &dl, SDValue Chain,
1430-
int FrameIndex, int64_t Size,
1431-
int64_t Offset = -1);
1430+
int FrameIndex, int64_t Size);
14321431

14331432
/// Creates a PseudoProbeSDNode with function GUID `Guid` and
14341433
/// the index of the block `Index` it is probing, as well as the attributes

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,25 +2004,17 @@ class FrameIndexSDNode : public SDNode {
20042004
class LifetimeSDNode : public SDNode {
20052005
friend class SelectionDAG;
20062006
int64_t Size;
2007-
int64_t Offset; // -1 if offset is unknown.
20082007

20092008
LifetimeSDNode(unsigned Opcode, unsigned Order, const DebugLoc &dl,
2010-
SDVTList VTs, int64_t Size, int64_t Offset)
2011-
: SDNode(Opcode, Order, dl, VTs), Size(Size), Offset(Offset) {}
2009+
SDVTList VTs, int64_t Size)
2010+
: SDNode(Opcode, Order, dl, VTs), Size(Size) {}
2011+
20122012
public:
20132013
int64_t getFrameIndex() const {
20142014
return cast<FrameIndexSDNode>(getOperand(1))->getIndex();
20152015
}
20162016

2017-
bool hasOffset() const { return Offset >= 0; }
2018-
int64_t getOffset() const {
2019-
assert(hasOffset() && "offset is unknown");
2020-
return Offset;
2021-
}
2022-
int64_t getSize() const {
2023-
assert(hasOffset() && "offset is unknown");
2024-
return Size;
2025-
}
2017+
int64_t getSize() const { return Size; }
20262018

20272019
// Methods to support isa and dyn_cast
20282020
static bool classof(const SDNode *N) {

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,23 +2189,11 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
21892189
unsigned Op = ID == Intrinsic::lifetime_start ? TargetOpcode::LIFETIME_START
21902190
: TargetOpcode::LIFETIME_END;
21912191

2192-
// Get the underlying objects for the location passed on the lifetime
2193-
// marker.
2194-
SmallVector<const Value *, 4> Allocas;
2195-
getUnderlyingObjects(CI.getArgOperand(1), Allocas);
2196-
2197-
// Iterate over each underlying object, creating lifetime markers for each
2198-
// static alloca. Quit if we find a non-static alloca.
2199-
for (const Value *V : Allocas) {
2200-
const AllocaInst *AI = dyn_cast<AllocaInst>(V);
2201-
if (!AI)
2202-
continue;
2203-
2204-
if (!AI->isStaticAlloca())
2205-
return true;
2192+
const AllocaInst *AI = cast<AllocaInst>(CI.getArgOperand(1));
2193+
if (!AI->isStaticAlloca())
2194+
return true;
22062195

2207-
MIRBuilder.buildInstr(Op).addFrameIndex(getOrCreateFrameIndex(*AI));
2208-
}
2196+
MIRBuilder.buildInstr(Op).addFrameIndex(getOrCreateFrameIndex(*AI));
22092197
return true;
22102198
}
22112199
case Intrinsic::fake_use: {

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22727,11 +22727,7 @@ SDValue DAGCombiner::visitSTORE(SDNode *N) {
2272722727

2272822728
SDValue DAGCombiner::visitLIFETIME_END(SDNode *N) {
2272922729
const auto *LifetimeEnd = cast<LifetimeSDNode>(N);
22730-
if (!LifetimeEnd->hasOffset())
22731-
return SDValue();
22732-
22733-
const BaseIndexOffset LifetimeEndBase(N->getOperand(1), SDValue(),
22734-
LifetimeEnd->getOffset(), false);
22730+
const BaseIndexOffset LifetimeEndBase(N->getOperand(1), SDValue(), 0, false);
2273522731

2273622732
// We walk up the chains to find stores.
2273722733
SmallVector<SDValue, 8> Chains = {N->getOperand(0)};
@@ -29418,9 +29414,8 @@ bool DAGCombiner::mayAlias(SDNode *Op0, SDNode *Op1) const {
2941829414
return {false /*isVolatile*/,
2941929415
/*isAtomic*/ false,
2942029416
LN->getOperand(1),
29421-
(LN->hasOffset()) ? LN->getOffset() : 0,
29422-
(LN->hasOffset()) ? LocationSize::precise(LN->getSize())
29423-
: LocationSize::beforeOrAfterPointer(),
29417+
0,
29418+
LocationSize::precise(LN->getSize()),
2942429419
(MachineMemOperand *)nullptr};
2942529420
// Default.
2942629421
return {false /*isvolatile*/,

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,10 +786,7 @@ static void AddNodeIDCustom(FoldingSetNodeID &ID, const SDNode *N) {
786786
break;
787787
case ISD::LIFETIME_START:
788788
case ISD::LIFETIME_END:
789-
if (cast<LifetimeSDNode>(N)->hasOffset()) {
790-
ID.AddInteger(cast<LifetimeSDNode>(N)->getSize());
791-
ID.AddInteger(cast<LifetimeSDNode>(N)->getOffset());
792-
}
789+
ID.AddInteger(cast<LifetimeSDNode>(N)->getSize());
793790
break;
794791
case ISD::PSEUDO_PROBE:
795792
ID.AddInteger(cast<PseudoProbeSDNode>(N)->getGuid());
@@ -9364,7 +9361,7 @@ SDValue SelectionDAG::getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl,
93649361

93659362
SDValue SelectionDAG::getLifetimeNode(bool IsStart, const SDLoc &dl,
93669363
SDValue Chain, int FrameIndex,
9367-
int64_t Size, int64_t Offset) {
9364+
int64_t Size) {
93689365
const unsigned Opcode = IsStart ? ISD::LIFETIME_START : ISD::LIFETIME_END;
93699366
const auto VTs = getVTList(MVT::Other);
93709367
SDValue Ops[2] = {
@@ -9377,13 +9374,12 @@ SDValue SelectionDAG::getLifetimeNode(bool IsStart, const SDLoc &dl,
93779374
AddNodeIDNode(ID, Opcode, VTs, Ops);
93789375
ID.AddInteger(FrameIndex);
93799376
ID.AddInteger(Size);
9380-
ID.AddInteger(Offset);
93819377
void *IP = nullptr;
93829378
if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
93839379
return SDValue(E, 0);
93849380

9385-
LifetimeSDNode *N = newSDNode<LifetimeSDNode>(
9386-
Opcode, dl.getIROrder(), dl.getDebugLoc(), VTs, Size, Offset);
9381+
LifetimeSDNode *N = newSDNode<LifetimeSDNode>(Opcode, dl.getIROrder(),
9382+
dl.getDebugLoc(), VTs, Size);
93879383
createOperands(N, Ops);
93889384
CSEMap.InsertNode(N, IP);
93899385
InsertNode(N);

llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,7 @@ BaseIndexOffset BaseIndexOffset::match(const SDNode *N,
303303
if (const auto *LS0 = dyn_cast<LSBaseSDNode>(N))
304304
return matchLSNode(LS0, DAG);
305305
if (const auto *LN = dyn_cast<LifetimeSDNode>(N)) {
306-
if (LN->hasOffset())
307-
return BaseIndexOffset(LN->getOperand(1), SDValue(), LN->getOffset(),
308-
false);
309-
return BaseIndexOffset(LN->getOperand(1), SDValue(), false);
306+
return BaseIndexOffset(LN->getOperand(1), SDValue(), 0, false);
310307
}
311308
return BaseIndexOffset();
312309
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7596,32 +7596,17 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
75967596

75977597
const int64_t ObjectSize =
75987598
cast<ConstantInt>(I.getArgOperand(0))->getSExtValue();
7599-
Value *const ObjectPtr = I.getArgOperand(1);
7600-
SmallVector<const Value *, 4> Allocas;
7601-
getUnderlyingObjects(ObjectPtr, Allocas);
7599+
const AllocaInst *LifetimeObject = cast<AllocaInst>(I.getArgOperand(1));
76027600

7603-
for (const Value *Alloca : Allocas) {
7604-
const AllocaInst *LifetimeObject = dyn_cast_or_null<AllocaInst>(Alloca);
7605-
7606-
// Could not find an Alloca.
7607-
if (!LifetimeObject)
7608-
continue;
7609-
7610-
// First check that the Alloca is static, otherwise it won't have a
7611-
// valid frame index.
7612-
auto SI = FuncInfo.StaticAllocaMap.find(LifetimeObject);
7613-
if (SI == FuncInfo.StaticAllocaMap.end())
7614-
return;
7601+
// First check that the Alloca is static, otherwise it won't have a
7602+
// valid frame index.
7603+
auto SI = FuncInfo.StaticAllocaMap.find(LifetimeObject);
7604+
if (SI == FuncInfo.StaticAllocaMap.end())
7605+
return;
76157606

7616-
const int FrameIndex = SI->second;
7617-
int64_t Offset;
7618-
if (GetPointerBaseWithConstantOffset(
7619-
ObjectPtr, Offset, DAG.getDataLayout()) != LifetimeObject)
7620-
Offset = -1; // Cannot determine offset from alloca to lifetime object.
7621-
Res = DAG.getLifetimeNode(IsStart, sdl, getRoot(), FrameIndex, ObjectSize,
7622-
Offset);
7623-
DAG.setRoot(Res);
7624-
}
7607+
const int FrameIndex = SI->second;
7608+
Res = DAG.getLifetimeNode(IsStart, sdl, getRoot(), FrameIndex, ObjectSize);
7609+
DAG.setRoot(Res);
76257610
return;
76267611
}
76277612
case Intrinsic::pseudoprobe: {

llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,7 @@ void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
947947
<< ASC->getDestAddressSpace()
948948
<< ']';
949949
} else if (const LifetimeSDNode *LN = dyn_cast<LifetimeSDNode>(this)) {
950-
if (LN->hasOffset())
951-
OS << "<" << LN->getOffset() << " to " << LN->getOffset() + LN->getSize() << ">";
950+
OS << "<0 to " << LN->getSize() << ">";
952951
} else if (const auto *AA = dyn_cast<AssertAlignSDNode>(this)) {
953952
OS << '<' << AA->getAlign().value() << '>';
954953
}

0 commit comments

Comments
 (0)