GVN-hoist: improve code generation for recursive GEPs
authorSebastian Pop <sebpop@gmail.com>
Wed, 27 Jul 2016 05:48:12 +0000 (05:48 +0000)
committerSebastian Pop <sebpop@gmail.com>
Wed, 27 Jul 2016 05:48:12 +0000 (05:48 +0000)
commit55c3007b881ddeb3ec0ca1769973213576e038d1
tree9a73f30b80702934627e2e5da0dbdb5ddc822d92
parent586d3eaeb59c20f95b1ac89ba53ffca2ddca3866
GVN-hoist: improve code generation for recursive GEPs

When loading or storing in a field of a struct like "a.b.c", GVN is able to
detect the equivalent expressions, and GVN-hoist would fail in the code
generation.  This is because the GEPs are not hoisted as scalar operations to
avoid moving the GEPs too far from their ld/st instruction when the ld/st is not
movable.  So we end up having to generate code for the GEP of a ld/st when we
move the ld/st.  In the case of a GEP referring to another GEP as in "a.b.c" we
need to code generate all the GEPs necessary to make all the operands available
at the new location for the ld/st.  With this patch we recursively walk through
the GEP operands checking whether all operands are available, and in the case of
a GEP operand, it recursively makes all its operands available. Code generation
happens from the inner GEPs out until reaching the GEP that appears as an
operand of the ld/st.

Differential Revision: https://reviews.llvm.org/D22599

llvm-svn: 276841
llvm/lib/Transforms/Scalar/GVNHoist.cpp
llvm/test/Transforms/GVN/hoist-recursive-geps.ll [new file with mode: 0644]