[InstCombinePHI] Partial simplification of identity operations.
authorCharlie Turner <charlie.turner@arm.com>
Thu, 13 Aug 2015 12:38:58 +0000 (12:38 +0000)
committerCharlie Turner <charlie.turner@arm.com>
Thu, 13 Aug 2015 12:38:58 +0000 (12:38 +0000)
commit99985c9fac383c3b433f15237e2761afcaef7ee3
treedddeb5f14b926e7839e1436857c5c578bfcb09e3
parent26f2b3561ceda3484a1ee2bb9396087f596db516
[InstCombinePHI] Partial simplification of identity operations.

Consider this code:

BB:
  %i = phi i32 [ 0, %if.then ], [ %c, %if.else ]
  %add = add nsw i32 %i, %b
  ...

In this common case the add can be moved to the %if.else basic block, because
adding zero is an identity operation. If we go though %if.then branch it's
always a win, because add is not executed; if not, the number of instructions
stays the same.

This pattern applies also to other instructions like sub, shl, shr, ashr | 0,
mul, sdiv, div | 1.

Patch by Jakub Kuderski!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244887 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombinePHI.cpp
test/Transforms/InstCombine/phi.ll