[PATCH] Sink: Don't sink allocas
Tom Stellard
tom at stellard.net
Mon Jan 20 12:53:24 PST 2014
Looks like I forgot the patch...
On Mon, Jan 20, 2014 at 12:49:23PM -0800, Tom Stellard wrote:
> Hi,
>
> Attached is an updated patch.
>
> -Tom
>
> On Mon, Dec 16, 2013 at 10:21:25AM -0800, Matt Arsenault wrote:
> > On 12/16/2013 07:17 AM, Tom Stellard wrote:
> > >From: Tom Stellard <thomas.stellard at amd.com>
> > >
> > >CodeGen treats allocas outside the entry block as dynamically sized
> > >stack objects.
> > >---
> > > lib/Transforms/Scalar/Sink.cpp | 6 ++++++
> > > test/Transforms/Sink/basic.ll | 23 +++++++++++++++++++++++
> > > 2 files changed, 29 insertions(+)
> > >
> > >diff --git a/lib/Transforms/Scalar/Sink.cpp b/lib/Transforms/Scalar/Sink.cpp
> > >index d4595bb..c7f9e97 100644
> > >--- a/lib/Transforms/Scalar/Sink.cpp
> > >+++ b/lib/Transforms/Scalar/Sink.cpp
> > >@@ -218,6 +218,12 @@ bool Sinking::IsAcceptableTarget(Instruction *Inst,
> > > /// instruction out of its current block into a successor.
> > > bool Sinking::SinkInstruction(Instruction *Inst,
> > > SmallPtrSet<Instruction *, 8> &Stores) {
> > >+
> > >+ // Don't sink alloca instructions. CodeGen assumes allocas outside the
> > >+ // entry block are dynamically sized stack objects.
> > >+ if (dyn_cast<AllocaInst>(Inst))
> > >+ return false;
> > >+
> > You don't use the value of dyn_cast, so just use isa
> >
> > > // Check if it's safe to move the instruction.
> > > if (!isSafeToMove(Inst, AA, Stores))
> > > return false;
> > >diff --git a/test/Transforms/Sink/basic.ll b/test/Transforms/Sink/basic.ll
> > >index 85ab376..740e5a8 100644
> > >--- a/test/Transforms/Sink/basic.ll
> > >+++ b/test/Transforms/Sink/basic.ll
> > >@@ -62,3 +62,26 @@ X: ; preds = %5, %3
> > > ret i32 %R
> > > }
> > >+; We shouldn't sink allocas, since CodeGen interprets allocas outside the
> > >+; entry block as dynamically sized stack objects.
> > >+
> > >+; CHECK-LABEL: @alloca_sink
> > >+; CHECK: entry:
> > >+; CHECK-NEXT: alloca
> > >+define i32 @alloca_sink(i32 %a, i32 %b) {
> > >+entry:
> > >+ %0 = alloca i32
> > >+ %1 = icmp ne i32 %a, 0
> > >+ br i1 %1, label %if, label %endif
> > >+
> > >+if:
> > >+ %2 = getelementptr i32* %0, i32 1
> > >+ store i32 0, i32* %0
> > >+ store i32 1, i32* %2
> > >+ %3 = getelementptr i32* %0, i32 %b
> > >+ %4 = load i32* %3
> > >+ ret i32 %4
> > >+
> > >+endif:
> > >+ ret i32 0
> > >+}
> >
> >
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Sink-Don-t-sink-allocas.patch
Type: text/x-diff
Size: 1963 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140120/09005784/attachment.patch>
More information about the llvm-commits
mailing list