[llvm-commits] [PATCH] Remove tail marker when changing an argument to an alloca.

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Thu Dec 27 12:28:09 PST 2012


Argument promotion can replace an argument of a call with an alloca. This
requires clearing the tail marker as it is very likely that the callee is now
using an alloca in the caller.

This fixes pr14710.
---
 lib/Transforms/IPO/ArgumentPromotion.cpp  | 10 ++++++++++
 test/Transforms/ArgumentPromotion/tail.ll | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 test/Transforms/ArgumentPromotion/tail.ll

diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp
index 8fb19b0..12cbf57 100644
--- a/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -808,6 +808,16 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
       I->replaceAllUsesWith(TheAlloca);
       TheAlloca->takeName(I);
       AA.replaceWithNewValue(I, TheAlloca);
+
+      // If the alloca is used in a call, we must clear the tail flag since
+      // the callee now uses an alloca from the caller.
+      for (Value::use_iterator UI = TheAlloca->use_begin(),
+             E = TheAlloca->use_end(); UI != E; ++UI) {
+        CallInst *Call = dyn_cast<CallInst>(*UI);
+        if (!Call)
+          continue;
+        Call->setTailCall(false);
+      }
       continue;
     }
 
diff --git a/test/Transforms/ArgumentPromotion/tail.ll b/test/Transforms/ArgumentPromotion/tail.ll
new file mode 100644
index 0000000..a12bb94
--- /dev/null
+++ b/test/Transforms/ArgumentPromotion/tail.ll
@@ -0,0 +1,18 @@
+; RUN: opt %s -argpromotion -S -o - | FileCheck %s
+
+%pair = type { i32, i32 }
+
+declare i8* @foo(%pair*)
+
+define internal void @bar(%pair* byval %Data) {
+; CHECK: define internal void @bar(i32 %Data.0, i32 %Data.1)
+; CHECK: %Data = alloca %pair
+; CHECK: call i8* @foo(%pair* %Data)
+  tail call i8* @foo(%pair* %Data)
+  ret void
+}
+
+define void @zed(%pair* byval %Data) {
+  call void @bar(%pair* byval %Data)
+  ret void
+}
-- 
1.7.11.7




More information about the llvm-commits mailing list