<div dir="ltr">On Thu, Sep 5, 2013 at 1:46 PM, Nicholas Chapman <span dir="ltr"><<a href="mailto:admin@indigorenderer.com" target="_blank">admin@indigorenderer.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi All,<br>
I was wondering if there is an optimisation pass that moves a stack allocated array, initialised with constant values, to a global constant array.<br></blockquote><div><br></div><div>No, there is no such pass at the moment.</div>
<div><br></div><div>-Eli</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
And if there is such a pass, what requirements are there for it to operate?<br>
My optimised IR is below. As you can see an array of 5 integers is created with alloca, then each element is stored to in turn. It would be nice if this array was transformed into a global constant array.<br>
<br>
Thanks,<br>
Nick<br>
<br>
<br>
<br>
; ModuleID = 'WinterModule'<br>
target datalayout = "e-p:64:64:64-S128-i1:8:8-i8:<u></u>8:8-i16:16:16-i32:32:32-i64:<u></u>64:64-f16:16:16-f32:32:32-f64:<u></u>64:64-f128:128:128-v64:64:64-<u></u>v128:128:128-a0:0:64-s0:64:64-<u></u>f80:128:128-n8:16:32:64"<br>
<br>
; Function Attrs: nounwind readnone<br>
define i32 @"main(int)"(i32 %i, i32* nocapture %hidden) #0 {<br>
entry:<br>
%"Array literal space" = alloca [5 x i32], align 4<br>
%0 = getelementptr [5 x i32]* %"Array literal space", i64 0, i64 0<br>
store i32 1, i32* %0, align 4<br>
%1 = getelementptr [5 x i32]* %"Array literal space", i64 0, i64 1<br>
store i32 2, i32* %1, align 4<br>
%2 = getelementptr [5 x i32]* %"Array literal space", i64 0, i64 2<br>
store i32 3, i32* %2, align 4<br>
%3 = getelementptr [5 x i32]* %"Array literal space", i64 0, i64 3<br>
store i32 4, i32* %3, align 4<br>
%4 = getelementptr [5 x i32]* %"Array literal space", i64 0, i64 4<br>
store i32 5, i32* %4, align 4<br>
%5 = icmp ult i32 %i, 5<br>
br i1 %5, label %in-bounds.i, label %"elem(array<int, 5>, int).exit"<br>
<br>
in-bounds.i: ; preds = %entry<br>
%6 = sext i32 %i to i64<br>
%7 = getelementptr [5 x i32]* %"Array literal space", i64 0, i64 %6<br>
%8 = load i32* %7, align 4<br>
br label %"elem(array<int, 5>, int).exit"<br>
<br>
"elem(array<int, 5>, int).exit": ; preds = %entry, %in-bounds.i<br>
%iftmp.i = phi i32 [ %8, %in-bounds.i ], [ 0, %entry ]<br>
ret i32 %iftmp.i<br>
}<br>
<br>
attributes #0 = { nounwind readnone }<br>
<br>
<br>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div></div>