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)
commitc6b506a0ae3bf1e6902f2fe83b62ed945a8c30e0
tree5107ae6f64ce388b98fe1a56d5c2071d6375b366
parent9c6ae36861bacb9ca4f13a4dabe08a4460554f15
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: 209843
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/gepphigep.ll [new file with mode: 0644]