<div dir="ltr"><div>Hey Jason Hu,</div><div><br></div><div>So I think this is the SROA pass breaking up the load/store of the aggregate (the [500 x i32] array) into individual load/stores so that it can see if any are unused or can have their stores forwarded. This is a bit of LLVM that I personally find pretty dumb - but if you look at how Clang generates code for your above pattern it'll output memcpy intrinsics instead of doing load/stores, which gets around this issue.</div><div><br></div><div>Note: the compiler hasn't hung, it's just spinning and comparing a few thousand instructions generated from SROA against each other, you might need to wait until the end of the universe but it should complete eventually ;)</div><div><br></div><div>Cheers,</div><div>-Neil.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 13, 2020 at 12:37 AM Jason -Zhong Sheng- Hu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255)">
<div>
<p>Hi all,</p>
<p><br>
</p>
<p>sorry to have sent the same question around. I am quite desperately looking for a solution to this problem and I figured the mailing list is the best bet.<br>
</p>
<p><br>
</p>
<p>In my code, I generate the following function:</p>
<pre><code><span style="font-family:"Courier New",monospace">define i32 @gl.qi([</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32] %x, i32 %i) {
entry:
  %x. = alloca [</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32]
  %i. = alloca i32
  %0 = alloca [</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32]
  store [</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32] %x, [</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32]* %x.
  store i32 %i, i32* %i.
  %x.</span><span style="font-family:"Courier New",monospace">1</span><span style="font-family:"Courier New",monospace"> = load [</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32], [</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32]* %x.
  %i.</span><span style="font-family:"Courier New",monospace">2</span><span style="font-family:"Courier New",monospace"> = load i32, i32* %i.
  store [</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32] %x.</span><span style="font-family:"Courier New",monospace">1</span><span style="font-family:"Courier New",monospace">, [</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32]* %0
  %1 = icmp slt i32 %i.</span><span style="font-family:"Courier New",monospace">2</span><span style="font-family:"Courier New",monospace">, </span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace">
  br i1 %1, label %in-bound, label %out-of-bound

out-of-bound:                                     ; preds = %entry
  call void @gen.panic(i8* getelementptr inbounds ([</span><span style="font-family:"Courier New",monospace">22</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i8], [</span><span style="font-family:"Courier New",monospace">22</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i8]* @pool.str.</span><span style="font-family:"Courier New",monospace">2</span><span style="font-family:"Courier New",monospace">, i32 </span><span style="font-family:"Courier New",monospace">0</span><span style="font-family:"Courier New",monospace">, i32 </span><span style="font-family:"Courier New",monospace">0</span><span style="font-family:"Courier New",monospace">))
  unreachable

in-bound:                                         ; preds = %entry
  %2 = getelementptr inbounds [</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32], [</span><span style="font-family:"Courier New",monospace">500</span><span style="font-family:"Courier New",monospace"> </span><span style="font-family:"Courier New",monospace">x</span><span style="font-family:"Courier New",monospace"> i32]* %0, i32 </span><span style="font-family:"Courier New",monospace">0</span><span style="font-family:"Courier New",monospace">, i32 %i.</span><span style="font-family:"Courier New",monospace">2</span><span style="font-family:"Courier New",monospace">
  %idx = load i32, i32* %2
  ret i32 %idx
}</span>
</code></pre>
<p>the high level functionality is to use <code>%i</code> to index <code>%x</code>, and if
<code>%i</code> is out of bound, a panic function is called instead.</p>
<p><br>
</p>
<p>consider the store line:</p>
<pre><code>  <span>store</span> <span>[500 x i32]</span> %<span>x</span>, <span>[500 x i32]</span>* %<span>x</span>.
</code></pre>
<p>once I pass this function to <code>opt -O1 -S --verify --verify-each</code>, it generates code like this:</p>
<pre><code>define i32 @gl.qi([<span>500</span> <span>x</span> i32] %x, i32 %i) local_unnamed_addr {
entry:
  %0 = alloca [<span>500</span> <span>x</span> i32], align <span>4</span>
  %x.fca.<span>0</span>.extract = extractvalue [<span>500</span> <span>x</span> i32] %x, <span>0</span>
  %x.fca.<span>1</span>.extract = extractvalue [<span>500</span> <span>x</span> i32] %x, <span>1</span>
  %x.fca.<span>2</span>.extract = extractvalue [<span>500</span> <span>x</span> i32] %x, <span>2</span>
  %x.fca.<span>3</span>.extract = extractvalue [<span>500</span> <span>x</span> i32] %x, <span>3</span>
  %x.fca.<span>4</span>.extract = extractvalue [<span>500</span> <span>x</span> i32] %x, <span>4</span>
  %x.fca.<span>5</span>.extract = extractvalue [<span>500</span> <span>x</span> i32] %x, <span>5</span>
</code></pre>
<p>until 500. I put the number to 50000 and it won’t stop.</p>
<p><br>
</p>
<p>This is puzzling. I am not sure why must a <code>store</code> command be expanded to a sequence of
<code>etractvalue</code>s then <code>store</code>s? Is there a way to turn off this particular optimization without turning off the whole optimization?</p>
<p>Or am I looking at the wrong way to do this simple task?</p>
</div>
<br>
</div>
<div>
<div style="font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
<br>
</div>
<div id="gmail-m_-8058013783395405281Signature">
<div></div>
<div id="gmail-m_-8058013783395405281divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif">
<font size="3"><b>Thanks,</b></font></div>
<div dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif">
<font size="3"><b>Jason Hu</b></font></div>
<div dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif">
<font size="3"><b><a href="https://hustmphrrr.github.io/" target="_blank">https://hustmphrrr.github.io/</a></b></font><br>
<font size="3"><b></b></font><font style="font-size:12pt" size="3"><span style="color:rgb(69,129,142)"><span style="font-family:trebuchet ms,sans-serif"><b><a></a></b></span></span></font></div>
</div>
</div>
</div>

_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><table style="border-collapse:collapse;border-spacing:0px;color:rgb(90,90,91);font-size:13px;margin:0px 0px 20px;padding:0px" width="100%" cellspacing="0" cellpadding="0" border="0"><tbody style="margin:0px;padding:0px"><tr style="margin:0px;padding:0px"><td style="border-collapse:collapse;font-size:0px;line-height:1.5em;padding:0px 0px 20px;vertical-align:top" align="left"><table style="border-collapse:collapse;border-spacing:0px;margin:0px;padding:0px" cellspacing="0" cellpadding="0" border="0" align="left"><tbody style="margin:0px;padding:0px"><tr style="margin:0px;padding:0px"><td style="border-collapse:collapse;font-size:1.12em;line-height:1.5em;padding:0px;vertical-align:top;width:64px"><img style="border: medium none; border-radius: 0px; display: block; font-size: 13px; height: auto; line-height: 100%; margin: 0px; max-width: 100%; outline-style: none; outline-width: medium; padding: 20px 0px 0px; width: 100%;" alt="" src="https://unity3d.com/profiles/unity3d/themes/unity/images/ui/other/unity-logo-dark-email.png" width="64" height="auto"></td></tr></tbody></table></td></tr><tr style="margin:0px;padding:0px"><td style="border-collapse:collapse;font-size:0px;line-height:1.5em;padding:0px;vertical-align:top" align="left"><div style="color:rgb(0,0,0);font-family:Roboto,Arial;font-size:14px;font-weight:600;line-height:15px;margin:0px;padding:0px">Neil Henning</div></td></tr><tr style="margin:0px;padding:0px"><td style="border-collapse:collapse;font-size:0px;line-height:1.5em;padding:0px;vertical-align:top" align="left"><div style="color:rgb(0,0,0);font-family:Roboto,Arial;font-size:14px;line-height:15px;margin:0px;padding:0px 0px 10px">Senior Software Engineer Compiler</div></td></tr><tr style="margin:0px;padding:0px"><td style="border-collapse:collapse;font-size:0px;line-height:1.5em;padding:0px;vertical-align:top" align="left"><div style="color:rgb(0,0,0);font-family:Roboto,Arial;font-size:12px;line-height:15px;margin:0px;padding:0px"><a href="http://unity.com" target="_blank">unity.com</a></div></td></tr></tbody></table></div></div>