<div dir="ltr">I think SimplifyCFG could be abusing the undef value for this. If num is defined before the loop, it no longer becomes optimized: <a href="https://godbolt.org/z/woHRQf">https://godbolt.org/z/woHRQf</a></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 3, 2020 at 3:50 PM Karl Rehm <<a href="mailto:klrehm123@gmail.com">klrehm123@gmail.com</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>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" target="_blank">https://godbolt.org/z/F6NjdG</a></div><div><br></div><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">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></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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></div></div>
</blockquote></div>