InstCombine: Negator: don't rely on complexity sorting already being performed (PR47752)
authorRoman Lebedev <lebedev.ri@gmail.com>
Wed, 7 Oct 2020 10:52:25 +0000 (13:52 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Wed, 7 Oct 2020 12:09:50 +0000 (15:09 +0300)
commitfed0f890e5698a7a408acaf0aa23319e918f6a2a
tree7cea5b395e706f9e03daa0136d5fc90a41e05977
parentf71f5f39f670075f7b653b1e1a6bd24e5c8f099e
InstCombine: Negator: don't rely on complexity sorting already being performed (PR47752)

In some cases, we can negate instruction if only one of it's operands
negates. Previously, we assumed that constants would have been
canonicalized to RHS already, but that isn't guaranteed to happen,
because of InstCombine worklist visitation order,
as the added test (previously-hanging) shows.

So if we only need to negate a single operand,
we should ensure ourselves that we try constant operand first.
Do that by re-doing the complexity sorting ourselves,
when we actually care about it.

Fixes https://bugs.llvm.org/show_bug.cgi?id=47752
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp
llvm/test/Transforms/InstCombine/sub-of-negatible.ll