[llvm-commits] [llvm] r85206 - in /llvm/trunk: lib/Transforms/Utils/InlineFunction.cpp test/Transforms/Inline/basictest.ll
Chris Lattner
sabre at nondot.org
Mon Oct 26 22:39:42 PDT 2009
Author: lattner
Date: Tue Oct 27 00:39:41 2009
New Revision: 85206
URL: http://llvm.org/viewvc/llvm-project?rev=85206&view=rev
Log:
Fix a pretty serious misfeature of the inliner: if it inlines a function
with multiple return values it inserts a PHI to merge them all together.
However, if the return values are all the same, it ends up with a pointless
PHI and this pointless PHI happens to really block SRoA from happening in
at least a silly C++ example written by Doug, but probably others. This
fixes rdar://7339069.
Modified:
llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
llvm/trunk/test/Transforms/Inline/basictest.ll
Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=85206&r1=85205&r2=85206&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Tue Oct 27 00:39:41 2009
@@ -619,8 +619,17 @@
"Ret value not consistent in function!");
PHI->addIncoming(RI->getReturnValue(), RI->getParent());
}
+
+ // Now that we inserted the PHI, check to see if it has a single value
+ // (e.g. all the entries are the same or undef). If so, remove the PHI so
+ // it doesn't block other optimizations.
+ if (Value *V = PHI->hasConstantValue()) {
+ PHI->replaceAllUsesWith(V);
+ PHI->eraseFromParent();
+ }
}
+
// Add a branch to the merge points and remove return instructions.
for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
ReturnInst *RI = Returns[i];
Modified: llvm/trunk/test/Transforms/Inline/basictest.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/basictest.ll?rev=85206&r1=85205&r2=85206&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Inline/basictest.ll (original)
+++ llvm/trunk/test/Transforms/Inline/basictest.ll Tue Oct 27 00:39:41 2009
@@ -1,4 +1,4 @@
-; RUN: opt < %s -inline -S | FileCheck %s
+; RUN: opt < %s -inline -scalarrepl -S | FileCheck %s
define i32 @test1f(i32 %i) {
ret i32 %i
@@ -13,3 +13,34 @@
; CHECK-NEXT: ret i32 %Y
}
+
+
+; rdar://7339069
+
+%T = type { i32, i32 }
+
+; CHECK-NOT: @test2f
+define internal %T* @test2f(i1 %cond, %T* %P) {
+ br i1 %cond, label %T, label %F
+
+T:
+ %A = getelementptr %T* %P, i32 0, i32 0
+ store i32 42, i32* %A
+ ret %T* %P
+
+F:
+ ret %T* %P
+}
+
+define i32 @test2(i1 %cond) {
+ %A = alloca %T
+
+ %B = call %T* @test2f(i1 %cond, %T* %A)
+ %C = getelementptr %T* %B, i32 0, i32 0
+ %D = load i32* %C
+ ret i32 %D
+
+; CHECK: @test2(
+; CHECK-NOT: = alloca
+; CHECK: ret i32 42
+}
More information about the llvm-commits
mailing list