Add support for combining GEPs across PHI nodes
authorLouis Gerbarg <lgg@apple.com>
Thu, 29 May 2014 20:29:47 +0000 (20:29 +0000)
committerLouis Gerbarg <lgg@apple.com>
Thu, 29 May 2014 20:29:47 +0000 (20:29 +0000)
commit78874456fc58ca993635e31ef5ab5517769efb93
tree6db8242763d3f6ab8c7eae30d9e347fd01611deb
parent960fc3503fed972763cbd21ffd03b85ef2e58c82
Add support for combining GEPs across PHI nodes

Currently LLVM will generally merge GEPs. This allows backends to use more
complex addressing modes. In some cases this is not happening because there
is PHI inbetween the two GEPs:

  GEP1--\
        |-->PHI1-->GEP3
  GEP2--/

This patch checks to see if GEP1 and GEP2 are similiar enough that they can be
cloned (GEP12) in GEP3's BB, allowing GEP->GEP merging (GEP123):

  GEP1--\                     --\                           --\
        |-->PHI1-->GEP3  ==>    |-->PHI2->GEP12->GEP3 == >    |-->PHI2->GEP123
  GEP2--/                     --/                           --/

This also breaks certain use chains that are preventing GEP->GEP merges that the
the existing instcombine would merge otherwise.

Tests included.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209843 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/gepphigep.ll [new file with mode: 0644]