<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Hey Neil,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
thank you for replying and the information.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
I think it is dumb... I have changed my implementation to passing a byval array pointer. In this case, this optimization doesn't trigger.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
I think the expansion in this optimization is quite useless because byval array pointer achieves the same (I suppose) while the generated size remains small.  This reveals unnecessarily complex execution detail.<br>
</div>
<div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div></div>
<div id="divtagdefaultwrapper" 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/" style="">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 target="_blank" style=""></a></b></span></span></font></div>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Neil Henning <neil.henning@unity3d.com><br>
<b>Sent:</b> April 13, 2020 9:10 AM<br>
<b>To:</b> Jason -Zhong Sheng- Hu <fdhzs2010@hotmail.com><br>
<b>Cc:</b> llvm-dev@lists.llvm.org <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] Optimization generate super long function definition</font>
<div> </div>
</div>
<div>
<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="x_gmail_quote">
<div dir="ltr" class="x_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="x_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="x_gmail-m_-8058013783395405281Signature">
<div></div>
<div id="x_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 size="3" style="font-size:12pt"><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="x_gmail_signature">
<div dir="ltr">
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="border-collapse:collapse; border-spacing:0px; color:rgb(90,90,91); font-size:13px; margin:0px 0px 20px; padding:0px">
<tbody style="margin:0px; padding:0px">
<tr style="margin:0px; padding:0px">
<td align="left" style="border-collapse:collapse; font-size:0px; line-height:1.5em; padding:0px 0px 20px; vertical-align:top">
<table cellspacing="0" cellpadding="0" border="0" align="left" style="border-collapse:collapse; border-spacing:0px; margin:0px; padding:0px">
<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 alt="" width="64" height="auto" 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%" src="https://unity3d.com/profiles/unity3d/themes/unity/images/ui/other/unity-logo-dark-email.png"></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr style="margin:0px; padding:0px">
<td align="left" style="border-collapse:collapse; font-size:0px; line-height:1.5em; padding:0px; vertical-align:top">
<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 align="left" style="border-collapse:collapse; font-size:0px; line-height:1.5em; padding:0px; vertical-align:top">
<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 align="left" style="border-collapse:collapse; font-size:0px; line-height:1.5em; padding:0px; vertical-align:top">
<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>
</div>
</body>
</html>