[InstCombine] Negator: cache negation results (PR46362)
authorRoman Lebedev <lebedev.ri@gmail.com>
Wed, 17 Jun 2020 18:37:19 +0000 (21:37 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Wed, 17 Jun 2020 19:47:20 +0000 (22:47 +0300)
commite3d8cb1e1d227c61576914e42435b5e71d442631
tree66ef1dfd781b01340f102638e817f3c96a4c9937
parentc4166f3d84985a8eddfc12dce10a2f66f7dc98d6
[InstCombine] Negator: cache negation results (PR46362)

It is possible that we can try to negate the same value multiple times.
For example, PHI nodes may happen to have multiple incoming values
(all of which must be the same value) for the same incoming basic block.
It may happen that we try to negate such a PHI node, and succeed,
and that might result in having now-different incoming values..

To avoid that, and in general to reduce the amount of duplicated
work we might be doing, let's introduce a cache where
we'll track results of negating each value.

The added test was previously failing -verify after -instcombine.

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