summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/IPO/Inliner.cpp
diff options
context:
space:
mode:
authorHal Finkel <hfinkel@anl.gov>2013-07-16 17:10:55 +0000
committerHal Finkel <hfinkel@anl.gov>2013-07-16 17:10:55 +0000
commit9caa8f7ba7b74bce41dc37b4e9ac61096c65683e (patch)
tree413b23e1c53e9404373af0ccf4ef4740235ac408 /llvm/lib/Transforms/IPO/Inliner.cpp
parentd4060fd281388cf7bcb917472f20fc4b858471e9 (diff)
downloadbcm5719-llvm-9caa8f7ba7b74bce41dc37b4e9ac61096c65683e.tar.gz
bcm5719-llvm-9caa8f7ba7b74bce41dc37b4e9ac61096c65683e.zip
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. llvm-svn: 186425
Diffstat (limited to 'llvm/lib/Transforms/IPO/Inliner.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/Inliner.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp
index 663ddb75f42..f72121d822f 100644
--- a/llvm/lib/Transforms/IPO/Inliner.cpp
+++ b/llvm/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;
OpenPOWER on IntegriCloud