Add support for combining GEPs across PHI nodes
authorLouis Gerbarg <lgg@apple.com>
Fri, 16 May 2014 23:47:24 +0000 (23:47 +0000)
committerLouis Gerbarg <lgg@apple.com>
Fri, 16 May 2014 23:47:24 +0000 (23:47 +0000)
commit2d1fa5f718bc53d9b3867371f0941889f02bea3a
treeff672dd442ac8aceac84e3a26731fad2997c58d5
parent70f8b47a650897f7483f7dbb0b1bc3888350dbc3
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.

rdar://15547484

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