[llvm-dev] Why doesn't this loop get removed?

David Blaikie via llvm-dev llvm-dev at lists.llvm.org
Wed Jun 17 11:07:59 PDT 2020


Not sure. But I was curious enough to check where the breakpoint is -
at 61: https://godbolt.org/z/XDijBB - at 60 it does the desired thing
and optimizes down to ret of a literal.

If you're curious/want to investigate yourself you can run clang/llvm
with -mllvm -print-after-all it'll print the internal representation
after each optimization. So using that with 60 and 61 and comparing
the difference in behavior might point to at least /a/ smoking gun.

On Wed, Jun 17, 2020 at 10:54 AM Riyaz Puthiyapurayil via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
>
> int f() {
>
>     int A[100];
>
>     for (int i = 0; i < 100; ++i)
>
>         A[i] = i;
>
>     return A[10];
>
> }
>
>
>
> Neither gcc nor clang eliminates the loop. Clang also blows up the code a bit by unrolling the loop. Why can’t this loop and the array be eliminated and the function body turned into ret i32 10 ? Am I missing something?
>
>
>
> /Riyaz
>
>
>
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list