[llvm-dev] Which optimization pass deals with heap values?

Russell Wallace via llvm-dev llvm-dev at lists.llvm.org
Mon Jan 17 06:42:20 PST 2022


Thanks! Yeah, looking over the detailed output, it looks like the most
important step was global value numbering, of which it is said

> This pass performs global value numbering to eliminate fully and
partially redundant instructions. It also performs redundant load
elimination.

So yeah, it did indeed eliminate the redundant load.

On Mon, Jan 17, 2022 at 9:50 AM Florian Hahn <florian_hahn at apple.com> wrote:

>
>
> On Jan 17, 2022, at 08:07, Russell Wallace via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
> All the optimization passes I can find in the documentation, deal with
> register, stack or global values; I cannot find any mention of anything
> trying to optimize values on the heap. But this:
>
> #include <stdlib.h>
>
> int main(int argc, char **argv) {
>   int *a = malloc(10 * sizeof(int));
>   for (int i = 0; i < 10; i++)
>     a[i] = i;
>   return a[5];
> }
>
> compiles to 'ret 5' (as it should). Which pass does that?
> _____________________________________________
>
>
>
> You can use `-mllvm -print-changed` with clang when built with assertions
> to find this out, e.g. see https://clang.godbolt.org/z/aM18Tr7Mr
>
> It will be multiple optimizations working together. There are several
> passes that optimize memory operation, like DSE, GVN, EarlyCSE +MemorySSA.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20220117/c5fa8a6a/attachment.html>


More information about the llvm-dev mailing list