HomePhabricator

[InstCombine] Negator - sink sinkable negations

Authored by lebedev.ri on Apr 21 2020, 11:24 AM.

Description

[InstCombine] Negator - sink sinkable negations

Summary:
As we have discussed previously (e.g. in D63992 / D64090 / PR42457), sub instruction
can almost be considered non-canonical. While we do convert sub %x, C -> add %x, -C,
we sparsely do that for non-constants. But we should.

Here, i propose to interpret sub %x, %y as add (sub 0, %y), %x IFF the negation can be sinked into the %y

This has some potential to cause endless combine loops (either around PHI's, or if there are some opposite transforms).
For former there's -instcombine-negator-max-depth option to mitigate it, should this expose any such issues
For latter, if there are still any such opposing folds, we'd need to remove the colliding fold.
In any case, reproducers welcomed!

Reviewers: spatel, nikic, efriedma, xbolva00

Reviewed By: spatel

Subscribers: xbolva00, mgorny, hiraditya, reames, llvm-commits

Tags: #llvm

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

Details

Committed
lebedev.riApr 21 2020, 12:00 PM
Reviewer
spatel
Differential Revision
D68408: [InstCombine] Negator - sink sinkable negations
Parents
rGa13dce1d90cb: Fix build. NFC.
Branches
Unknown
Tags
Unknown