diff options
author | Vedant Kumar <vsk@apple.com> | 2019-02-15 18:46:58 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2019-02-15 18:46:58 +0000 |
commit | 5f5cac3ae29d44869f64d9629d9443656199fc1d (patch) | |
tree | 0542e88813f57a5604aebe6b6962c80791b1f9b7 /llvm/lib/Transforms/Utils/CodeExtractor.cpp | |
parent | 47a0c9b69cd7aaebbbf9c9b6b86e37fa892a6191 (diff) | |
download | bcm5719-llvm-5f5cac3ae29d44869f64d9629d9443656199fc1d.tar.gz bcm5719-llvm-5f5cac3ae29d44869f64d9629d9443656199fc1d.zip |
[CodeExtractor] Do not lift lifetime.end markers for region inputs
If a lifetime.end marker occurs along one path through the extraction
region, but not another, then it's still incorrect to lift the marker,
because there is some path through the extracted function which would
ordinarily not reach the marker. If the call to the extracted function
is in a loop, unrolling can cause inputs to the function to become
optimized out as undef after the first iteration.
To prevent incorrect stack slot merging in the calling function, it
should be sufficient to lift lifetime.start markers for region inputs.
I've tested this theory out by doing a stage2 check-all with randomized
splitting enabled.
This is a follow-up to r353973, and there's additional context for this
change in https://reviews.llvm.org/D57834.
rdar://47896986
Differential Revision: https://reviews.llvm.org/D58253
llvm-svn: 354159
Diffstat (limited to 'llvm/lib/Transforms/Utils/CodeExtractor.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/CodeExtractor.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index 2e073e89dde..023ab76d001 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -886,16 +886,14 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs, } /// Erase lifetime.start markers which reference inputs to the extraction -/// region, and insert the referenced memory into \p LifetimesStart. Do the same -/// with lifetime.end markers (but insert them into \p LifetimesEnd). +/// region, and insert the referenced memory into \p LifetimesStart. /// /// The extraction region is defined by a set of blocks (\p Blocks), and a set /// of allocas which will be moved from the caller function into the extracted /// function (\p SunkAllocas). static void eraseLifetimeMarkersOnInputs(const SetVector<BasicBlock *> &Blocks, const SetVector<Value *> &SunkAllocas, - SetVector<Value *> &LifetimesStart, - SetVector<Value *> &LifetimesEnd) { + SetVector<Value *> &LifetimesStart) { for (BasicBlock *BB : Blocks) { for (auto It = BB->begin(), End = BB->end(); It != End;) { auto *II = dyn_cast<IntrinsicInst>(&*It); @@ -912,8 +910,6 @@ static void eraseLifetimeMarkersOnInputs(const SetVector<BasicBlock *> &Blocks, if (II->getIntrinsicID() == Intrinsic::lifetime_start) LifetimesStart.insert(Mem); - else - LifetimesEnd.insert(Mem); II->eraseFromParent(); } } @@ -1421,12 +1417,11 @@ Function *CodeExtractor::extractCodeRegion() { } // Collect objects which are inputs to the extraction region and also - // referenced by lifetime start/end markers within it. The effects of these + // referenced by lifetime start markers within it. The effects of these // markers must be replicated in the calling function to prevent the stack // coloring pass from merging slots which store input objects. - ValueSet LifetimesStart, LifetimesEnd; - eraseLifetimeMarkersOnInputs(Blocks, SinkingCands, LifetimesStart, - LifetimesEnd); + ValueSet LifetimesStart; + eraseLifetimeMarkersOnInputs(Blocks, SinkingCands, LifetimesStart); // Construct new function based on inputs/outputs & add allocas for all defs. Function *newFunction = @@ -1449,9 +1444,8 @@ Function *CodeExtractor::extractCodeRegion() { // Replicate the effects of any lifetime start/end markers which referenced // input objects in the extraction region by placing markers around the call. - insertLifetimeMarkersSurroundingCall(oldFunction->getParent(), - LifetimesStart.getArrayRef(), - LifetimesEnd.getArrayRef(), TheCall); + insertLifetimeMarkersSurroundingCall( + oldFunction->getParent(), LifetimesStart.getArrayRef(), {}, TheCall); // Propagate personality info to the new function if there is one. if (oldFunction->hasPersonalityFn()) |