Hi all,<br><br>I'm writting following LLVM assembly:<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 = 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 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>