-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[StackLifetime] Remove handling for lifetime size mismatch #151965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+6
−70
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Split out from llvm#150248: Since llvm#150944 the size passed to lifetime.start/end is considered meaningless. The lifetime always applies to the whole alloca. Accordingly remove handling for size mismatch in the StackLifetime analysis.
@llvm/pr-subscribers-llvm-analysis Author: Nikita Popov (nikic) ChangesSplit out from #150248: Since #150944 the size passed to lifetime.start/end is considered meaningless. The lifetime always applies to the whole alloca. Accordingly remove handling for size mismatch in the StackLifetime analysis. Full diff: https://github.com/llvm/llvm-project/pull/151965.diff 4 Files Affected:
diff --git a/llvm/include/llvm/Analysis/StackLifetime.h b/llvm/include/llvm/Analysis/StackLifetime.h
index 438407fb70561..13f837a22281a 100644
--- a/llvm/include/llvm/Analysis/StackLifetime.h
+++ b/llvm/include/llvm/Analysis/StackLifetime.h
@@ -121,8 +121,6 @@ class StackLifetime {
DenseMap<const BasicBlock *, SmallVector<std::pair<unsigned, Marker>, 4>>
BBMarkers;
- bool HasUnknownLifetimeStartOrEnd = false;
-
void dumpAllocas() const;
void dumpBlockLiveness() const;
void dumpLiveRanges() const;
diff --git a/llvm/lib/Analysis/StackLifetime.cpp b/llvm/lib/Analysis/StackLifetime.cpp
index b3f999400f154..abe4985544e40 100644
--- a/llvm/lib/Analysis/StackLifetime.cpp
+++ b/llvm/lib/Analysis/StackLifetime.cpp
@@ -59,47 +59,20 @@ bool StackLifetime::isAliveAfter(const AllocaInst *AI,
return getLiveRange(AI).test(InstNum);
}
-// Returns unique alloca annotated by lifetime marker only if
-// markers has the same size and points to the alloca start.
-static const AllocaInst *findMatchingAlloca(const IntrinsicInst &II,
- const DataLayout &DL) {
- const AllocaInst *AI = dyn_cast<AllocaInst>(II.getArgOperand(1));
- if (!AI)
- return nullptr;
-
- auto AllocaSize = AI->getAllocationSize(DL);
- if (!AllocaSize)
- return nullptr;
-
- auto *Size = dyn_cast<ConstantInt>(II.getArgOperand(0));
- if (!Size)
- return nullptr;
- int64_t LifetimeSize = Size->getSExtValue();
-
- if (LifetimeSize != -1 && uint64_t(LifetimeSize) != *AllocaSize)
- return nullptr;
-
- return AI;
-}
-
void StackLifetime::collectMarkers() {
InterestingAllocas.resize(NumAllocas);
DenseMap<const BasicBlock *, SmallDenseMap<const IntrinsicInst *, Marker>>
BBMarkerSet;
- const DataLayout &DL = F.getDataLayout();
-
// Compute the set of start/end markers per basic block.
for (const BasicBlock *BB : depth_first(&F)) {
for (const Instruction &I : *BB) {
const IntrinsicInst *II = dyn_cast<IntrinsicInst>(&I);
if (!II || !II->isLifetimeStartOrEnd())
continue;
- const AllocaInst *AI = findMatchingAlloca(*II, DL);
- if (!AI) {
- HasUnknownLifetimeStartOrEnd = true;
+ const AllocaInst *AI = dyn_cast<AllocaInst>(II->getArgOperand(1));
+ if (!AI)
continue;
- }
auto It = AllocaNumbering.find(AI);
if (It == AllocaNumbering.end())
continue;
@@ -328,20 +301,6 @@ StackLifetime::StackLifetime(const Function &F,
}
void StackLifetime::run() {
- if (HasUnknownLifetimeStartOrEnd) {
- // There is marker which we can't assign to a specific alloca, so we
- // fallback to the most conservative results for the type.
- switch (Type) {
- case LivenessType::May:
- LiveRanges.resize(NumAllocas, getFullLiveRange());
- break;
- case LivenessType::Must:
- LiveRanges.resize(NumAllocas, LiveRange(Instructions.size()));
- break;
- }
- return;
- }
-
LiveRanges.resize(NumAllocas, LiveRange(Instructions.size()));
for (unsigned I = 0; I < NumAllocas; ++I)
if (!InterestingAllocas.test(I))
diff --git a/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll b/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
index 7fa1cf47f06be..6c3dec9fadac7 100644
--- a/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
+++ b/llvm/test/Analysis/StackSafetyAnalysis/lifetime.ll
@@ -786,27 +786,6 @@ end:
ret void
}
-define void @alloca_size() {
-; CHECK-LABEL: define void @alloca_size
-entry:
-; CHECK: entry:
-; MAY-NEXT: Alive: <x>
-; MUST-NEXT: Alive: <>
- %x = alloca [5 x i32], align 4
-
- call void @llvm.lifetime.start.p0(i64 15, ptr %x)
-; CHECK: call void @llvm.lifetime.start.p0(i64 15, ptr %x)
-; MAY-NEXT: Alive: <x>
-; MUST-NEXT: Alive: <>
-
- call void @llvm.lifetime.end.p0(i64 15, ptr %x)
-; CHECK: call void @llvm.lifetime.end.p0(i64 15, ptr %x)
-; MAY-NEXT: Alive: <x>
-; MUST-NEXT: Alive: <>
-
- ret void
-}
-
define void @multiple_start_end() {
; CHECK-LABEL: define void @multiple_start_end
entry:
diff --git a/llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll b/llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll
index a40dad526a14d..3685d8d530bed 100644
--- a/llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll
+++ b/llvm/test/Instrumentation/AddressSanitizer/lifetime-uar-uas.ll
@@ -18,11 +18,11 @@ entry:
%retval = alloca i32, align 4
%c = alloca [2 x i8], align 1
- ; Memory is poisoned in prologue: F1F1F1F104F3F8F2
- ; CHECK-UAS: store i64 -866676825215864335, ptr %{{[0-9]+}}
+ ; Memory is poisoned in prologue: F1F1F1F1F8F3F3F3
+ ; CHECK-UAS: store i64 -868082052615769615, ptr %{{[0-9]+}}
; CHECK-UAS-SS-NOT: store i64
- call void @llvm.lifetime.start.p0(i64 1, ptr %c)
+ call void @llvm.lifetime.start.p0(i64 2, ptr %c)
; Memory is unpoisoned at llvm.lifetime.start: 01
; CHECK-UAS: store i8 2, ptr %{{[0-9]+}}
@@ -30,7 +30,7 @@ entry:
store volatile i32 0, ptr %retval
store volatile i8 0, ptr %ci, align 1
- call void @llvm.lifetime.end.p0(i64 1, ptr %c)
+ call void @llvm.lifetime.end.p0(i64 2, ptr %c)
; Memory is poisoned at llvm.lifetime.end: F8
; CHECK-UAS: store i8 -8, ptr %{{[0-9]+}}
; CHECK-UAS-SS-NOT: store i8 -8,
|
fmayer
approved these changes
Aug 4, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Split out from #150248:
Since #150944 the size passed to lifetime.start/end is considered meaningless. The lifetime always applies to the whole alloca.
Accordingly remove handling for size mismatch in the StackLifetime analysis.