[llvm-commits] [llvm] r106947 - in /llvm/trunk: lib/Transforms/Scalar/TailRecursionElimination.cpp test/Transforms/TailCallElim/2010-06-26-MultipleReturnValues.ll
Duncan Sands
baldrick at free.fr
Sat Jun 26 05:53:31 PDT 2010
Author: baldrick
Date: Sat Jun 26 07:53:31 2010
New Revision: 106947
URL: http://llvm.org/viewvc/llvm-project?rev=106947&view=rev
Log:
Fix PR7328: when turning a tail recursion into a loop, need to preserve
the returned value after the tail call if it differs from other return
values. The optimal thing to do would be to introduce a phi node for
the return value, but for the moment just fix the miscompile.
Added:
llvm/trunk/test/Transforms/TailCallElim/2010-06-26-MultipleReturnValues.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp?rev=106947&r1=106946&r2=106947&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp Sat Jun 26 07:53:31 2010
@@ -270,16 +270,16 @@
}
// getCommonReturnValue - Check to see if the function containing the specified
-// return instruction and tail call consistently returns the same
-// runtime-constant value at all exit points. If so, return the returned value.
+// tail call consistently returns the same runtime-constant value at all exit
+// points except for IgnoreRI. If so, return the returned value.
//
-static Value *getCommonReturnValue(ReturnInst *TheRI, CallInst *CI) {
- Function *F = TheRI->getParent()->getParent();
+static Value *getCommonReturnValue(ReturnInst *IgnoreRI, CallInst *CI) {
+ Function *F = CI->getParent()->getParent();
Value *ReturnedValue = 0;
for (Function::iterator BBI = F->begin(), E = F->end(); BBI != E; ++BBI)
if (ReturnInst *RI = dyn_cast<ReturnInst>(BBI->getTerminator()))
- if (RI != TheRI) {
+ if (RI != IgnoreRI) {
Value *RetOp = RI->getOperand(0);
// We can only perform this transformation if the value returned is
@@ -404,7 +404,7 @@
if (Ret->getNumOperands() == 1 && Ret->getReturnValue() != CI &&
!isa<UndefValue>(Ret->getReturnValue()) &&
AccumulatorRecursionEliminationInitVal == 0 &&
- !getCommonReturnValue(Ret, CI))
+ !getCommonReturnValue(0, CI))
return false;
// OK! We can transform this tail call. If this is the first one found,
Added: llvm/trunk/test/Transforms/TailCallElim/2010-06-26-MultipleReturnValues.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/TailCallElim/2010-06-26-MultipleReturnValues.ll?rev=106947&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/TailCallElim/2010-06-26-MultipleReturnValues.ll (added)
+++ llvm/trunk/test/Transforms/TailCallElim/2010-06-26-MultipleReturnValues.ll Sat Jun 26 07:53:31 2010
@@ -0,0 +1,17 @@
+; RUN: opt < %s -tailcallelim -S | FileCheck %s
+; PR7328
+define i32 @foo(i32 %x) {
+; CHECK: define i32 @foo
+entry:
+ %cond = icmp ugt i32 %x, 0 ; <i1> [#uses=1]
+ br i1 %cond, label %return, label %body
+
+body: ; preds = %entry
+ %y = add i32 %x, 1 ; <i32> [#uses=1]
+ %tmp = call i32 @foo(i32 %y) ; <i32> [#uses=0]
+ ret i32 0
+; CHECK: ret i32 0
+
+return: ; preds = %entry
+ ret i32 1
+}
More information about the llvm-commits
mailing list