[llvm-commits] [PATCH] Remove tail marker when changing an argument to an alloca.
Rafael Espíndola
rafael.espindola at gmail.com
Thu Dec 27 12:39:27 PST 2012
Just noticed we need a CHECK-NOT in the test to avoid the tail.
Updated patch attached.
On 27 December 2012 15:28, Rafael Ávila de Espíndola
<rafael.espindola at gmail.com> wrote:
> 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: application/octet-stream
Size: 1507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121227/ec6ad42e/attachment.obj>
More information about the llvm-commits
mailing list