Skip to content

Commit ab1f6ce

Browse files
authored
[IR][SDAG] Remove lifetime size handling from SDAG (#150944)
Split out from #150248: Specify that the argument of lifetime.start/lifetime.end is ignored and will be removed in the future. Remove lifetime size handling from SDAG. The size was previously discarded during isel, so was always ignored for stack coloring anyway. Where necessary, obtain the size of the full frame index.
1 parent 6fbc397 commit ab1f6ce

File tree

8 files changed

+31
-46
lines changed

8 files changed

+31
-46
lines changed

llvm/docs/LangRef.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26653,9 +26653,10 @@ object's lifetime.
2665326653
Arguments:
2665426654
""""""""""
2665526655

26656-
The first argument is a constant integer representing the size of the
26657-
object, or -1 if it is variable sized. The second argument is a pointer
26658-
to an ``alloca`` instruction.
26656+
The first argument is a constant integer, which is ignored and will be removed
26657+
in the future.
26658+
26659+
The second argument is a pointer to an ``alloca`` instruction.
2665926660

2666026661
Semantics:
2666126662
""""""""""
@@ -26693,9 +26694,10 @@ The '``llvm.lifetime.end``' intrinsic specifies the end of a
2669326694
Arguments:
2669426695
""""""""""
2669526696

26696-
The first argument is a constant integer representing the size of the
26697-
object, or -1 if it is variable sized. The second argument is a pointer
26698-
to an ``alloca`` instruction.
26697+
The first argument is a constant integer, which is ignored and will be removed
26698+
in the future.
26699+
26700+
The second argument is a pointer to an ``alloca`` instruction.
2669926701

2670026702
Semantics:
2670126703
""""""""""

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,10 +1428,9 @@ class SelectionDAG {
14281428
EVT MemVT, MachineMemOperand *MMO);
14291429

14301430
/// Creates a LifetimeSDNode that starts (`IsStart==true`) or ends
1431-
/// (`IsStart==false`) the lifetime of the portion of `FrameIndex` between
1432-
/// offsets `0` and `Size`.
1431+
/// (`IsStart==false`) the lifetime of the `FrameIndex`.
14331432
LLVM_ABI SDValue getLifetimeNode(bool IsStart, const SDLoc &dl, SDValue Chain,
1434-
int FrameIndex, int64_t Size);
1433+
int FrameIndex);
14351434

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

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,23 +1999,19 @@ class FrameIndexSDNode : public SDNode {
19991999
}
20002000
};
20012001

2002-
/// This SDNode is used for LIFETIME_START/LIFETIME_END values, which indicate
2003-
/// the offet and size that are started/ended in the underlying FrameIndex.
2002+
/// This SDNode is used for LIFETIME_START/LIFETIME_END values.
20042003
class LifetimeSDNode : public SDNode {
20052004
friend class SelectionDAG;
2006-
int64_t Size;
20072005

20082006
LifetimeSDNode(unsigned Opcode, unsigned Order, const DebugLoc &dl,
2009-
SDVTList VTs, int64_t Size)
2010-
: SDNode(Opcode, Order, dl, VTs), Size(Size) {}
2007+
SDVTList VTs)
2008+
: SDNode(Opcode, Order, dl, VTs) {}
20112009

20122010
public:
20132011
int64_t getFrameIndex() const {
20142012
return cast<FrameIndexSDNode>(getOperand(1))->getIndex();
20152013
}
20162014

2017-
int64_t getSize() const { return Size; }
2018-
20192015
// Methods to support isa and dyn_cast
20202016
static bool classof(const SDNode *N) {
20212017
return N->getOpcode() == ISD::LIFETIME_START ||

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "llvm/CodeGen/ByteProvider.h"
3636
#include "llvm/CodeGen/DAGCombine.h"
3737
#include "llvm/CodeGen/ISDOpcodes.h"
38+
#include "llvm/CodeGen/MachineFrameInfo.h"
3839
#include "llvm/CodeGen/MachineFunction.h"
3940
#include "llvm/CodeGen/MachineMemOperand.h"
4041
#include "llvm/CodeGen/SDPatternMatch.h"
@@ -22778,8 +22779,10 @@ SDValue DAGCombiner::visitLIFETIME_END(SDNode *N) {
2277822779
const BaseIndexOffset StoreBase = BaseIndexOffset::match(ST, DAG);
2277922780
// If we store purely within object bounds just before its lifetime ends,
2278022781
// we can remove the store.
22781-
if (LifetimeEndBase.contains(DAG, LifetimeEnd->getSize() * 8, StoreBase,
22782-
StoreSize.getFixedValue() * 8)) {
22782+
MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
22783+
if (LifetimeEndBase.contains(
22784+
DAG, MFI.getObjectSize(LifetimeEnd->getFrameIndex()) * 8,
22785+
StoreBase, StoreSize.getFixedValue() * 8)) {
2278322786
LLVM_DEBUG(dbgs() << "\nRemoving store:"; StoreBase.dump();
2278422787
dbgs() << "\nwithin LIFETIME_END of : ";
2278522788
LifetimeEndBase.dump(); dbgs() << "\n");
@@ -29415,7 +29418,7 @@ bool DAGCombiner::mayAlias(SDNode *Op0, SDNode *Op1) const {
2941529418
MachineMemOperand *MMO;
2941629419
};
2941729420

29418-
auto getCharacteristics = [](SDNode *N) -> MemUseCharacteristics {
29421+
auto getCharacteristics = [this](SDNode *N) -> MemUseCharacteristics {
2941929422
if (const auto *LSN = dyn_cast<LSBaseSDNode>(N)) {
2942029423
int64_t Offset = 0;
2942129424
if (auto *C = dyn_cast<ConstantSDNode>(LSN->getOffset()))
@@ -29428,13 +29431,15 @@ bool DAGCombiner::mayAlias(SDNode *Op0, SDNode *Op1) const {
2942829431
LSN->getBasePtr(), Offset /*base offset*/,
2942929432
LocationSize::precise(Size), LSN->getMemOperand()};
2943029433
}
29431-
if (const auto *LN = cast<LifetimeSDNode>(N))
29434+
if (const auto *LN = cast<LifetimeSDNode>(N)) {
29435+
MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
2943229436
return {false /*isVolatile*/,
2943329437
/*isAtomic*/ false,
2943429438
LN->getOperand(1),
2943529439
0,
29436-
LocationSize::precise(LN->getSize()),
29440+
LocationSize::precise(MFI.getObjectSize(LN->getFrameIndex())),
2943729441
(MachineMemOperand *)nullptr};
29442+
}
2943829443
// Default.
2943929444
return {false /*isvolatile*/,
2944029445
/*isAtomic*/ false,

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,6 @@ static void AddNodeIDCustom(FoldingSetNodeID &ID, const SDNode *N) {
784784
case ISD::TargetFrameIndex:
785785
ID.AddInteger(cast<FrameIndexSDNode>(N)->getIndex());
786786
break;
787-
case ISD::LIFETIME_START:
788-
case ISD::LIFETIME_END:
789-
ID.AddInteger(cast<LifetimeSDNode>(N)->getSize());
790-
break;
791787
case ISD::PSEUDO_PROBE:
792788
ID.AddInteger(cast<PseudoProbeSDNode>(N)->getGuid());
793789
ID.AddInteger(cast<PseudoProbeSDNode>(N)->getIndex());
@@ -9360,8 +9356,7 @@ SDValue SelectionDAG::getMemIntrinsicNode(unsigned Opcode, const SDLoc &dl,
93609356
}
93619357

93629358
SDValue SelectionDAG::getLifetimeNode(bool IsStart, const SDLoc &dl,
9363-
SDValue Chain, int FrameIndex,
9364-
int64_t Size) {
9359+
SDValue Chain, int FrameIndex) {
93659360
const unsigned Opcode = IsStart ? ISD::LIFETIME_START : ISD::LIFETIME_END;
93669361
const auto VTs = getVTList(MVT::Other);
93679362
SDValue Ops[2] = {
@@ -9373,13 +9368,12 @@ SDValue SelectionDAG::getLifetimeNode(bool IsStart, const SDLoc &dl,
93739368
FoldingSetNodeID ID;
93749369
AddNodeIDNode(ID, Opcode, VTs, Ops);
93759370
ID.AddInteger(FrameIndex);
9376-
ID.AddInteger(Size);
93779371
void *IP = nullptr;
93789372
if (SDNode *E = FindNodeOrInsertPos(ID, dl, IP))
93799373
return SDValue(E, 0);
93809374

9381-
LifetimeSDNode *N = newSDNode<LifetimeSDNode>(Opcode, dl.getIROrder(),
9382-
dl.getDebugLoc(), VTs, Size);
9375+
LifetimeSDNode *N =
9376+
newSDNode<LifetimeSDNode>(Opcode, dl.getIROrder(), dl.getDebugLoc(), VTs);
93839377
createOperands(N, Ops);
93849378
CSEMap.InsertNode(N, IP);
93859379
InsertNode(N);

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7598,8 +7598,6 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
75987598
if (TM.getOptLevel() == CodeGenOptLevel::None)
75997599
return;
76007600

7601-
const int64_t ObjectSize =
7602-
cast<ConstantInt>(I.getArgOperand(0))->getSExtValue();
76037601
const AllocaInst *LifetimeObject = cast<AllocaInst>(I.getArgOperand(1));
76047602

76057603
// First check that the Alloca is static, otherwise it won't have a
@@ -7609,7 +7607,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
76097607
return;
76107608

76117609
const int FrameIndex = SI->second;
7612-
Res = DAG.getLifetimeNode(IsStart, sdl, getRoot(), FrameIndex, ObjectSize);
7610+
Res = DAG.getLifetimeNode(IsStart, sdl, getRoot(), FrameIndex);
76137611
DAG.setRoot(Res);
76147612
return;
76157613
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,6 @@ void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
946946
<< " -> "
947947
<< ASC->getDestAddressSpace()
948948
<< ']';
949-
} else if (const LifetimeSDNode *LN = dyn_cast<LifetimeSDNode>(this)) {
950-
OS << "<0 to " << LN->getSize() << ">";
951949
} else if (const auto *AA = dyn_cast<AssertAlignSDNode>(this)) {
952950
OS << '<' << AA->getAlign().value() << '>';
953951
}

llvm/test/CodeGen/X86/swap.ll

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,17 @@ define dso_local void @onealloc_readback_1(ptr nocapture %a, ptr nocapture %b) l
113113
;
114114
; AA-LABEL: onealloc_readback_1:
115115
; AA: # %bb.0: # %entry
116-
; AA-NEXT: vmovups (%rdi), %xmm0
117-
; AA-NEXT: vmovaps %xmm0, -{{[0-9]+}}(%rsp)
118116
; AA-NEXT: vmovups (%rsi), %xmm0
119117
; AA-NEXT: vmovups %xmm0, (%rdi)
120118
; AA-NEXT: retq
121119
entry:
122120
%alloc = alloca [16 x i8], i8 2, align 1
123121
%part1 = getelementptr inbounds [16 x i8], ptr %alloc, i64 1, i64 0
124-
call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %part1)
125-
call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %alloc)
122+
call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %alloc)
126123
call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %part1, ptr align 1 %a, i64 16, i1 false)
127124
call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %alloc, ptr align 1 %b, i64 16, i1 false)
128-
call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %part1)
129125
tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %a, ptr align 1 %alloc, i64 16, i1 false)
130-
call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %alloc)
126+
call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %alloc)
131127
ret void
132128
}
133129

@@ -144,19 +140,16 @@ define dso_local void @onealloc_readback_2(ptr nocapture %a, ptr nocapture %b) l
144140
; AA-LABEL: onealloc_readback_2:
145141
; AA: # %bb.0: # %entry
146142
; AA-NEXT: vmovups (%rsi), %xmm0
147-
; AA-NEXT: vmovaps %xmm0, -{{[0-9]+}}(%rsp)
148143
; AA-NEXT: vmovups %xmm0, (%rdi)
149144
; AA-NEXT: retq
150145
entry:
151146
%alloc = alloca [16 x i8], i8 2, align 1
152147
%part2 = getelementptr inbounds [16 x i8], ptr %alloc, i64 1, i64 0
153-
call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %alloc)
154-
call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %part2)
148+
call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %alloc)
155149
call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %alloc, ptr align 1 %a, i64 16, i1 false)
156150
call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %part2, ptr align 1 %b, i64 16, i1 false)
157-
call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %alloc)
158151
tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %a, ptr align 1 %part2, i64 16, i1 false)
159-
call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %part2)
152+
call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %alloc)
160153
ret void
161154
}
162155

0 commit comments

Comments
 (0)