<div dir="ltr">Wait, you used the same example as I did. I'm confused then; if ScEv is having troubles but it still gets optimized away somewhere, what do you think is doing it?<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 3, 2020 at 2:16 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">Ah, I see. I think there's something else going on here too, though. <a href="https://godbolt.org/z/dCqdvv" target="_blank">https://godbolt.org/z/dCqdvv</a> is optimized away but ScEv doesn't know whether this loop terminates either. <br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 3, 2020 at 1:36 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 am not convinced this is a jump-threading issue, but in the domain<br>
of ScalarEvolution. ScEv would need to find out which of the exits are<br>
taken or whether it loops infinitely. One can see that it exits after<br>
10000 iterations, but ScalarEvolution cannot tell:<br>
<a href="https://godbolt.org/z/dCqdvv" rel="noreferrer" target="_blank">https://godbolt.org/z/dCqdvv</a><br>
<br>
Michael<br>
<br>
Am Mo., 3. Feb. 2020 um 11:56 Uhr schrieb Karl Rehm <<a href="mailto:klrehm123@gmail.com" target="_blank">klrehm123@gmail.com</a>>:<br>
><br>
> Well ideally it'd do the same thing as before (with two if statements). Something like:<br>
> ret i64 4<br>
><br>
> It's not really about needing to be as good as gcc, it's more that I wonder why the same concept with just two if-else blocks gets optimized yet more doesn't.<br>
> An interesting point to make is that I don't think it's jump threading optimizing the original example fully: <a href="https://godbolt.org/z/rGvHJk" rel="noreferrer" target="_blank">https://godbolt.org/z/rGvHJk</a><br>
><br>
> -Karl<br>
><br>
> On Mon, Feb 3, 2020 at 12:29 PM Michael Kruse <<a href="mailto:llvmdev@meinersbur.de" target="_blank">llvmdev@meinersbur.de</a>> wrote:<br>
>><br>
>> How does the code you would like to have look like? I don't see a<br>
>> relevant difference compared to gcc:<br>
>> <a href="https://godbolt.org/z/F-oah4" rel="noreferrer" target="_blank">https://godbolt.org/z/F-oah4</a><br>
>> (clang unnecessarily introduces another temporary register, but that<br>
>> seems unrelated)<br>
>><br>
>> Michael<br>
>><br>
>> Am So., 2. Feb. 2020 um 18:24 Uhr schrieb Karl Rehm via llvm-dev<br>
>> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>:<br>
>> ><br>
>> > Here's a better example. <a href="https://godbolt.org/z/fpTyFS" rel="noreferrer" target="_blank">https://godbolt.org/z/fpTyFS</a><br>
>> > I don't know what exactly you would need to change in JumpThreading to improve this, but I'm open to ideas.<br>
>> ><br>
>> > On Sun, Feb 2, 2020 at 12:45 PM Karl Rehm <<a href="mailto:klrehm123@gmail.com" target="_blank">klrehm123@gmail.com</a>> wrote:<br>
>> >><br>
>> >> Holy crap, I completely missed that. I'm sorry! That's my fault.<br>
>> >><br>
>> >> On Sun, Feb 2, 2020 at 12:15 PM Johannes Doerfert <<a href="mailto:jdoerfert@anl.gov" target="_blank">jdoerfert@anl.gov</a>> wrote:<br>
>> >>><br>
>> >>> On 01/30, Karl Rehm via llvm-dev wrote:<br>
>> >>> > Since the bug report here: <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> I've<br>
>> >>> > been thinking about cases like it, such as: <a href="https://godbolt.org/z/Fwq8mn" rel="noreferrer" target="_blank">https://godbolt.org/z/Fwq8mn</a><br>
>> >>> ><br>
>> >>> > I wonder what we can do about this in a general sense. As far as I can<br>
>> >>> > tell, the jump threading algorithm is *really* conservative, which is one<br>
>> >>> > reason this isn't working as well as I'd hope; however, we don't want to<br>
>> >>> > produce irreducible control flow that the other passes would work less<br>
>> >>> > effectively on. Thoughts?<br>
>> >>><br>
>> >>> I'm confused. In your godbold link you run it with O0 which disables<br>
>> >>> almost all transformations. If we take the IR, remove the optnone<br>
>> >>> attribute, run mem2reg and jump-threading we get what I think is<br>
>> >>> reasonable:<br>
>> >>>   <a href="https://godbolt.org/z/u3fcTZ" rel="noreferrer" target="_blank">https://godbolt.org/z/u3fcTZ</a><br>
>> >>><br>
>> >>> Please correct me if I misunderstand anything here.<br>
>> >>><br>
>> >>> Cheers,<br>
>> >>>   Johannes<br>
>> ><br>
>> > _______________________________________________<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>
</blockquote></div>