This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by nikic on Jan 18 2020, 8:05 AM.

Details

Summary

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).

Diff Detail

Event Timeline

nikic created this revision.Jan 18 2020, 8:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2020, 8:05 AM
spatel accepted this revision.Jan 22 2020, 1:12 PM

LGTM - last comment I saw on the negator was that it's on hold, and this improvement shouldn't be hard to subsume if we do proceed there.

This revision is now accepted and ready to land.Jan 22 2020, 1:12 PM
This revision was automatically updated to reflect the committed changes.