<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);">
<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="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>
</body>
</html>