Duncan, <br><br>Forgot my previous e-mail I figured out by myself that adding:<br><br>target datalayout = "e-p:32:32:32" <br><br>to my orignal code helps 'opt' to generate :<br><br>; ModuleID = 'structaccess2.ll'<br>
target datalayout = "e-p:32:32:32"<br><br>%struct._anon0 = type <{ i32, i32, i32 }><br><br>@s = common global %struct._anon0 zeroinitializer, align 4<br><br>define arm_aapcscc void @foo() nounwind {<br>L.entry:<br>
store i32 5, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 0), align 4<br> store i32 10, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 1), align 4<br> store i32 15, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 2), align 4<br>
ret void<br>}<br><br>Why is exactly what I expected, thanks for pointing me at this !<br>Best Regards<br>Seb<br><br><div class="gmail_quote">2011/10/18 Seb <span dir="ltr"><<a href="mailto:babslachem@gmail.com">babslachem@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi Duncan,<br><br>What do you mean by "a data layout string in your module" ?<br>Best Regards<br>
<font color="#888888">Seb</font><div><div></div><div class="h5"><br><br><div class="gmail_quote">2011/10/18 Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi Seb,<br>
<div><br>
> I'm writting following LLVM assembly:<br>
><br>
> ; ModuleID = 'structaccess.ll'<br>
><br>
<br>
</div>not having a data layout string in your module disables many optimizations.<br>
<br>
Ciao, Duncan.<br>
<div><div></div><div><br>
> %struct._anon0 = type <{ i32, i32, i32 }><br>
><br>
> @s = common global %struct._anon0 zeroinitializer<br>
><br>
> define arm_aapcscc void @foo() nounwind {<br>
> L.entry:<br>
> store i32 5, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 0)<br>
> store i32 10, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 1)<br>
> %0 = load i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 0)<br>
> %1 = load i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 1)<br>
> %2 = add i32 %0, %1<br>
> store i32 %2, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 2)<br>
> ret void<br>
> }<br>
><br>
> Using 'opt' utility as follows :<br>
><br>
> opt -O2 structaccess.ll -S -o structaccess-opt.ll<br>
><br>
> I've got following code for structaccess-opt.ll file:<br>
><br>
> ; ModuleID = 'structaccess.ll'<br>
><br>
> %struct._anon0 = type <{ i32, i32, i32 }><br>
><br>
> @s = common global %struct._anon0 zeroinitializer<br>
><br>
> define arm_aapcscc void @foo() nounwind {<br>
> L.entry:<br>
> store i32 5, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 0)<br>
> store i32 10, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 1)<br>
> %0 = load i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 0)<br>
> %1 = add i32 %0, 10<br>
> store i32 %1, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 2)<br>
> ret void<br>
> }<br>
><br>
> I would have expected constant 5 to be propagated by 'opt' to its use and thus<br>
> LLVM assembly after opt to be :<br>
><br>
> ; ModuleID = 'structaccess.ll'<br>
><br>
> %struct._anon0 = type <{ i32, i32, i32 }><br>
><br>
> @s = common global %struct._anon0 zeroinitializer<br>
><br>
> define arm_aapcscc void @foo() nounwind {<br>
> L.entry:<br>
> store i32 5, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 0)<br>
> store i32 10, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 1)<br>
> store i32 15, i32* getelementptr inbounds (%struct._anon0* @s, i32 0, i32 2)<br>
> ret void<br>
> }<br>
><br>
> Can someone explain me why this is not the case ?<br>
><br>
> Note that C equivalent would be something like:<br>
><br>
> struct {<br>
> int x, y, z;<br>
> } s;<br>
><br>
> void foo()<br>
> {<br>
> s.x = 5 ;<br>
> s.y = 10 ;<br>
> s.z = s.x + s.y ;<br>
> }<br>
><br>
><br>
><br>
</div></div>> _______________________________________________<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/mailman/listinfo/llvmdev</a><br>
<br>
_______________________________________________<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/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br>
</div></div></blockquote></div><br>