summaryrefslogtreecommitdiff
path: root/lib/CodeGen/Analysis.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2012-06-01 05:29:15 +0000
committerChris Lattner <sabre@nondot.org>2012-06-01 05:29:15 +0000
commitf59e4e34528a078c2db57ee72b2814b495989124 (patch)
tree8a31b5a8b9cc32c3a37bd94c6c191af5d511eb95 /lib/CodeGen/Analysis.cpp
parentd9567223e852c48b4022345ed130000810521438 (diff)
downloadllvm-f59e4e34528a078c2db57ee72b2814b495989124.tar.gz
llvm-f59e4e34528a078c2db57ee72b2814b495989124.tar.bz2
llvm-f59e4e34528a078c2db57ee72b2814b495989124.tar.xz
enhance the logic for looking through tailcalls to look through transparent casts
in multiple-return value scenarios, like what happens on X86-64 when returning small structs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157800 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/Analysis.cpp')
-rw-r--r--lib/CodeGen/Analysis.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/CodeGen/Analysis.cpp b/lib/CodeGen/Analysis.cpp
index dd11d15975..1a8968dd28 100644
--- a/lib/CodeGen/Analysis.cpp
+++ b/lib/CodeGen/Analysis.cpp
@@ -322,7 +322,27 @@ bool llvm::isInTailCallPosition(ImmutableCallSite CS, Attributes CalleeRetAttr,
return false;
// Otherwise, make sure the unmodified return value of I is the return value.
- return getNoopInput(Ret->getOperand(0), TLI) == I;
+ // We handle two cases: multiple return values + scalars.
+ Value *RetVal = Ret->getOperand(0);
+ if (!isa<InsertValueInst>(RetVal) || !isa<StructType>(RetVal->getType()))
+ // Handle scalars first.
+ return getNoopInput(Ret->getOperand(0), TLI) == I;
+
+ // If this is an aggregate return, look through the insert/extract values and
+ // see if each is transparent.
+ for (unsigned i = 0, e =cast<StructType>(RetVal->getType())->getNumElements();
+ i != e; ++i) {
+ const Value *InScalar = getNoopInput(FindInsertedValue(RetVal, i), TLI);
+
+ // If the scalar value being inserted is an extractvalue of the right index
+ // from the call, then everything is good.
+ const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(InScalar);
+ if (EVI == 0 || EVI->getOperand(0) != I || EVI->getNumIndices() != 1 ||
+ EVI->getIndices()[0] != i)
+ return false;
+ }
+
+ return true;
}
bool llvm::isInTailCallPosition(SelectionDAG &DAG, SDNode *Node,