Add support for combining GEPs across PHI nodes
authorLouis Gerbarg <lgg@apple.com>
Wed, 28 May 2014 17:38:31 +0000 (17:38 +0000)
committerLouis Gerbarg <lgg@apple.com>
Wed, 28 May 2014 17:38:31 +0000 (17:38 +0000)
commit727f1cbb1770b860df9293563a1c957f47215ec6
tree7b703b8b7a2fc91224bb8f9ca006259a10483cdd
parentd31b5963ff0433def6c44eb1530a217e7c3a9ed0
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.

llvm-svn: 209755
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/gepphigep.ll [new file with mode: 0644]