[llvm-commits] [llvm] r157800 - in /llvm/trunk: lib/CodeGen/Analysis.cpp test/CodeGen/X86/tailcall-64.ll
Chris Lattner
sabre at nondot.org
Thu May 31 22:29:15 PDT 2012
Author: lattner
Date: Fri Jun 1 00:29:15 2012
New Revision: 157800
URL: http://llvm.org/viewvc/llvm-project?rev=157800&view=rev
Log:
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.
Modified:
llvm/trunk/lib/CodeGen/Analysis.cpp
llvm/trunk/test/CodeGen/X86/tailcall-64.ll
Modified: llvm/trunk/lib/CodeGen/Analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Analysis.cpp?rev=157800&r1=157799&r2=157800&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/Analysis.cpp (original)
+++ llvm/trunk/lib/CodeGen/Analysis.cpp Fri Jun 1 00:29:15 2012
@@ -322,7 +322,27 @@
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,
Modified: llvm/trunk/test/CodeGen/X86/tailcall-64.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcall-64.ll?rev=157800&r1=157799&r2=157800&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcall-64.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tailcall-64.ll Fri Jun 1 00:29:15 2012
@@ -41,3 +41,49 @@
}
; CHECK: test_vectorbitcast:
; CHECK: jmp _testv ## TAILCALL
+
+
+declare { i64, i64 } @testp()
+
+define {i64, i64} @test_pair_trivial() {
+ %A = tail call { i64, i64} @testp()
+ ret { i64, i64} %A
+}
+; CHECK: test_pair_trivial:
+; CHECK: jmp _testp ## TAILCALL
+
+
+
+define {i64, i64} @test_pair_trivial_extract() {
+ %A = tail call { i64, i64} @testp()
+ %x = extractvalue { i64, i64} %A, 0
+ %y = extractvalue { i64, i64} %A, 1
+
+ %b = insertvalue {i64, i64} undef, i64 %x, 0
+ %c = insertvalue {i64, i64} %b, i64 %y, 1
+
+ ret { i64, i64} %c
+}
+
+; CHECK: test_pair_trivial_extract:
+; CHECK: jmp _testp ## TAILCALL
+
+define {i8*, i64} @test_pair_conv_extract() {
+ %A = tail call { i64, i64} @testp()
+ %x = extractvalue { i64, i64} %A, 0
+ %y = extractvalue { i64, i64} %A, 1
+
+ %x1 = inttoptr i64 %x to i8*
+
+ %b = insertvalue {i8*, i64} undef, i8* %x1, 0
+ %c = insertvalue {i8*, i64} %b, i64 %y, 1
+
+ ret { i8*, i64} %c
+}
+
+; CHECK: test_pair_conv_extract:
+; CHECK: jmp _testp ## TAILCALL
+
+
+
+
More information about the llvm-commits
mailing list