[EarlyCSE] Equivalent SELECTs should hash equally
authorBryan Chan <bryan.chan@huawei.com>
Sat, 29 Aug 2020 21:25:16 +0000 (17:25 -0400)
committerBryan Chan <bryan.chan@huawei.com>
Thu, 10 Sep 2020 20:59:24 +0000 (16:59 -0400)
commitc9826829d74e637163fdb0351870b8204e62d6e6
tree5f1ff702a8eaad20f9005fa0b35e2cc79d8f9931
parentcb19e8c6d192a108b72ab07362921864a9e244f9
[EarlyCSE] Equivalent SELECTs should hash equally

DenseMap<SimpleValue> assumes that, if its isEqual method returns true
for two elements, then its getHashValue method must return the same value
for them. This invariant is broken when one SELECT node is a min/max
operation, and the other can be transformed into an equivalent min/max by
inverting its predicate and swapping its operands. This patch fixes an
assertion failure that would occur intermittently while compiling the
following IR:

    define i32 @t(i32 %i) {
      %cmp = icmp sle i32 0, %i
      %twin1 = select i1 %cmp, i32 %i, i32 0
      %cmpinv = icmp sgt i32 0, %i
      %twin2 = select i1 %cmpinv,  i32 0, i32 %i
      %sink = add i32 %twin1, %twin2
      ret i32 %sink
    }

Differential Revision: https://reviews.llvm.org/D86843
llvm/lib/Transforms/Scalar/EarlyCSE.cpp
llvm/test/Transforms/EarlyCSE/commute.ll