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)
commita5423f2598c8579fd5438f71048467db9d13abcd
tree3e7fbcdb1bca62fa6a73a2aee2302c7c021cfa8b
parent9b7716192728fbdd8ae2ba9a13dcd65d7fe6509f
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@209755 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/gepphigep.ll [new file with mode: 0644]