HomePhabricator

[InstCombine] Generalize %x * (-1<<C) --> (-%x) * (1<<C) fold

Authored by lebedev.ri on Aug 6 2020, 11:10 AM.

Description

[InstCombine] Generalize %x * (-1<<C) --> (-%x) * (1<<C) fold

Multiplication is commutative, and either of operands can be negative,
so if the RHS is a negated power-of-two, we should try to make it
true power-of-two (which will allow us to turn it into a left-shift),
by trying to sink the negation down into LHS op.

But, we shouldn't re-invent the logic for sinking negation,
let's just use Negator for that.

Tests and original patch by: Simon Pilgrim @RKSimon!

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