<div dir="ltr">Ok, thanks for the clarification. So looking into ScalarEvolution is what I'd look into if I wanted to optimize this a bit more? I'm mainly interested in how I'd go about "de-looping" this.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 3, 2020 at 4:55 PM Michael Kruse <<a href="mailto:llvmdev@meinersbur.de" target="_blank">llvmdev@meinersbur.de</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">Your code and the one you have seen in<br>
<a href="https://bugs.llvm.org/show_bug.cgi?id=44679" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=44679</a> are structurally<br>
different. In that latter, setting n to a constant value causes a<br>
branch taken in the next iteration. Your's is a more classic for-loop<br>
from 0 to 2. It is ScalarEvolution's job to find this out. SimplyCFG<br>
job is just to normalize the IR into a form understood by<br>
ScalarEvolution. That is, ScalarEvolution is the primary engine<br>
enabling this.<br>
<br>
Michael<br>
<br>
Am Mo., 3. Feb. 2020 um 14:51 Uhr schrieb Karl Rehm <<a href="mailto:klrehm123@gmail.com" target="_blank">klrehm123@gmail.com</a>>:<br>
><br>
> Hm. I assumed that JumpThreading would be the primary factor in optimizing code like this. Guess not. I'll need to look into SimplifyCFG to see what prevents it from doing the same thing to the other loop: <a href="https://godbolt.org/z/F6NjdG" rel="noreferrer" target="_blank">https://godbolt.org/z/F6NjdG</a><br>
><br>
> On Mon, Feb 3, 2020 at 3:09 PM Michael Kruse <<a href="mailto:llvmdev@meinersbur.de" target="_blank">llvmdev@meinersbur.de</a>> wrote:<br>
>><br>
>> I assumed the LLVM-IR behind the godbolt link represented the C code<br>
>> you used before.<br>
>><br>
>> SimplifyCFG actually helps the loop being removed:<br>
>> <a href="https://godbolt.org/z/5v7SXh" rel="noreferrer" target="_blank">https://godbolt.org/z/5v7SXh</a><br>
>><br>
>> But this doesn't even involve JumpThreading.<br>
>><br>
>> Michael<br>
</blockquote></div>