HomePhabricator

[InstCombine] Combine neg of shl of sub (PR44529)

Authored by nikic on Jan 18 2020, 7:54 AM.

Description

[InstCombine] Combine neg of shl of sub (PR44529)

Fixes https://bugs.llvm.org/show_bug.cgi?id=44529. We already have
a combine to sink a negation through a left-shift, but it currently
only works if the shift operand is negatable without creating any
instructions. This patch introduces freelyNegateValue() as a more
powerful extension of dyn_castNegVal(), which allows negating a
value as long as this doesn't end up increasing instruction count.
Specifically, this patch adds support for negating A-B to B-A.

This mechanism could in the future be extended to handle general
negation chains that a) start at a proper 0-X negation and b) only
require one operand to be freely negatable. This would end up as a
weaker form of D68408 aimed at the most obviously profitable subset
that eliminates a negation entirely.

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

Details

Committed
nikicJan 22 2020, 2:03 PM
Differential Revision
D72978: [InstCombine] Combine neg of shl of sub (PR44529)
Parents
rG80c34f94acdb: [InstCombine] Add test for PR44529; NFC
Branches
Unknown
Tags
Unknown