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

Duncan Sands baldrick at free.fr
Tue Jan 1 09:26:58 PST 2013


Hi Rafael, if a call uses a 'byval' parameter, should it be marked as a tail
call in the first place?  After all, byval implicitly places a copy of the
passed argument on the stack, so the call is implicitly using the stack.
There is the question of who puts the copy on the stack: the caller or the
callee?  If the former, maybe there isn't a problem after all...

Ciao, Duncan.

On 27/12/12 21:28, Rafael Ávila de Espíndola 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
> +}
>




More information about the llvm-commits mailing list