[InstCombine] fold multiply by signbit-splat to cmp+select
authorSanjay Patel <spatel@rotateright.com>
Fri, 27 May 2022 15:27:14 +0000 (11:27 -0400)
committerSanjay Patel <spatel@rotateright.com>
Fri, 27 May 2022 15:54:19 +0000 (11:54 -0400)
commitb5b6aa4d53407ff1f7805fc000def63669d64a9f
tree34919f987e9bff599fdb9b3d75fb5785b131b2bb
parent5a6e0857577e6dafb03716cfd47fa319441691dc
[InstCombine] fold multiply by signbit-splat to cmp+select

(ashr i32 X, 31) * C --> (X < 0) ? -C : 0
https://alive2.llvm.org/ce/z/G8u9SS

With a constant operand, this is an improvement in IR
and codegen (where it can be converted to a mask op).

Without a constant operand, we would have to negate
the operand, so that is probably better left to the backend.

This is similar but not the same optimization that is requested
in #55618.
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/mul.ll