[InstCombine] ease use constraint in tryFactorization()
authorSanjay Patel <spatel@rotateright.com>
Wed, 24 Aug 2022 15:39:24 +0000 (11:39 -0400)
committerSanjay Patel <spatel@rotateright.com>
Wed, 24 Aug 2022 16:10:54 +0000 (12:10 -0400)
commit0cfc6510323fbb5a56a5de23cbc65f7cc30fd34c
tree45e72df4253ebed2c9e80adcad1e4dbbd64000fa
parent3dd4d6a0cec85d96af0340a48aaacf638215fe76
[InstCombine] ease use constraint in tryFactorization()

The stronger one-use checks prevented transforms like this:
(x * y) + x --> x * (y + 1)
(x * y) - x --> x * (y - 1)

https://alive2.llvm.org/ce/z/eMhvQa

This is one of the IR transforms suggested in issue #57255.

This should be better in IR because it removes a use of a
variable operand (we already fold the case with a constant
multiply operand).
The backend should be able to re-distribute the multiply if
that's better for the target.

Differential Revision: https://reviews.llvm.org/D132412
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/add.ll
llvm/test/Transforms/InstCombine/and-or.ll
llvm/test/Transforms/InstCombine/ctpop.ll
llvm/test/Transforms/InstCombine/sub.ll