diff options
author | Hal Finkel <hfinkel@anl.gov> | 2013-07-16 17:10:55 +0000 |
---|---|---|
committer | Hal Finkel <hfinkel@anl.gov> | 2013-07-16 17:10:55 +0000 |
commit | 5a5ebb7f9fa7fa82c0c466a36a90e5c18bb13073 (patch) | |
tree | a78ba9387b19f55633afbc1fee33bae754514e0a /lib/Transforms/IPO | |
parent | 95779b65cf7b7d7c22bf2d22d03c661c8130cbe2 (diff) | |
download | external_llvm-5a5ebb7f9fa7fa82c0c466a36a90e5c18bb13073.zip external_llvm-5a5ebb7f9fa7fa82c0c466a36a90e5c18bb13073.tar.gz external_llvm-5a5ebb7f9fa7fa82c0c466a36a90e5c18bb13073.tar.bz2 |
When the inliner merges allocas, it must keep the larger alignment
For safety, the inliner cannot decrease the allignment on an alloca when
merging it with another.
I've included two variants of the test case for this: one with DataLayout
available, and one without. When DataLayout is not available, if only one of
the allocas uses the default alignment (getAlignment() == 0), then they cannot
be safely merged.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186425 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r-- | lib/Transforms/IPO/Inliner.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/Transforms/IPO/Inliner.cpp b/lib/Transforms/IPO/Inliner.cpp index 663ddb7..f72121d 100644 --- a/lib/Transforms/IPO/Inliner.cpp +++ b/lib/Transforms/IPO/Inliner.cpp @@ -116,7 +116,8 @@ static void AdjustCallerSSPLevel(Function *Caller, Function *Callee) { /// any new allocas to the set if not possible. static bool InlineCallIfPossible(CallSite CS, InlineFunctionInfo &IFI, InlinedArrayAllocasTy &InlinedArrayAllocas, - int InlineHistory, bool InsertLifetime) { + int InlineHistory, bool InsertLifetime, + const DataLayout *TD) { Function *Callee = CS.getCalledFunction(); Function *Caller = CS.getCaller(); @@ -189,6 +190,14 @@ static bool InlineCallIfPossible(CallSite CS, InlineFunctionInfo &IFI, bool MergedAwayAlloca = false; for (unsigned i = 0, e = AllocasForType.size(); i != e; ++i) { AllocaInst *AvailableAlloca = AllocasForType[i]; + + unsigned Align1 = AI->getAlignment(), + Align2 = AvailableAlloca->getAlignment(); + // If we don't have data layout information, and only one alloca is using + // the target default, then we can't safely merge them because we can't + // pick the greater alignment. + if (!TD && (!Align1 || !Align2) && Align1 != Align2) + continue; // The available alloca has to be in the right function, not in some other // function in this SCC. @@ -206,6 +215,11 @@ static bool InlineCallIfPossible(CallSite CS, InlineFunctionInfo &IFI, << *AvailableAlloca << '\n'); AI->replaceAllUsesWith(AvailableAlloca); + + if (Align1 > Align2 || (!Align1 && TD && + TD->getABITypeAlignment(AI->getAllocatedType()) > Align2)) + AvailableAlloca->setAlignment(Align1); + AI->eraseFromParent(); MergedAwayAlloca = true; ++NumMergedAllocas; @@ -482,7 +496,7 @@ bool Inliner::runOnSCC(CallGraphSCC &SCC) { // Attempt to inline the function. if (!InlineCallIfPossible(CS, InlineInfo, InlinedArrayAllocas, - InlineHistoryID, InsertLifetime)) + InlineHistoryID, InsertLifetime, TD)) continue; ++NumInlined; |