HomePhabricator

[InstCombine] Invert `add A, sext(B) --> sub A, zext(B)` canonicalization (to…

Authored by lebedev.ri on Dec 5 2019, 9:44 AM.

Description

[InstCombine] Invert add A, sext(B) --> sub A, zext(B) canonicalization (to sub A, zext B -> add A, sext B)

Summary:
D68408 proposes to greatly improve our negation sinking abilities.
But in current canonicalization, we produce sub A, zext(B),
which we will consider non-canonical and try to sink that negation,
undoing the existing canonicalization.
So unless we explicitly stop producing previous canonicalization,
we will have two conflicting folds, and will end up endlessly looping.

This inverts canonicalization, and adds back the obvious fold
that we'd miss:

It is obvious that @ossfuzz_9880() / @lshr_out_of_range()/@ashr_out_of_range()
(oss-fuzz 4871) are no longer folded as much, though those aren't really worrying.

Reviewers: spatel, efriedma, t.p.northover, hfinkel

Reviewed By: spatel

Subscribers: hiraditya, llvm-commits

Tags: #llvm

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