OSDN Git Service

[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)
commit0b4a709cf73c6071de118b7b0af099454d63d213
treecfb657863cfb8570baadd7d3a6ee464ccf51cbd8
parentd8c6515dbf89e68a8cd0cde9e8ca9d3584ca178a
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300363 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineAddSub.cpp
lib/Transforms/InstCombine/InstCombineCasts.cpp
lib/Transforms/InstCombine/InstCombineCompares.cpp
lib/Transforms/InstCombine/InstCombineInternal.h
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
lib/Transforms/InstCombine/InstCombinePHI.cpp
lib/Transforms/InstCombine/InstCombineSelect.cpp
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/sub.ll