[InstCombine] Support folding a subtract with a constant LHS into a phi node
authorCraig Topper <craig.topper@gmail.com>
Fri, 14 Apr 2017 19:20:12 +0000 (19:20 +0000)
committerCraig Topper <craig.topper@gmail.com>
Fri, 14 Apr 2017 19:20:12 +0000 (19:20 +0000)
commitfb71b7d3e05c347a05a7607d39bd04bf281c1529
treefdb7777aee84ae471113afa2cf66a1c897949579
parenteff0bc78395432f2afe470b037186bb9f4aa9940
[InstCombine] Support folding a subtract with a constant LHS into a phi node

We currently only support folding a subtract into a select but not a PHI. This fixes that.

I had to fix an assumption in FoldOpIntoPhi that assumed the PHI node was always in operand 0. Now we pass it in like we do for FoldOpIntoSelect. But we still require some dancing to find the Constant when we create the BinOp or ConstantExpr. This is based code is similar to what we do for selects.

Since I touched all call sites, this also renames FoldOpIntoPhi to foldOpIntoPhi to match coding standards.

Differential Revision: https://reviews.llvm.org/D31686

llvm-svn: 300363
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/sub.ll