[ISel] Fix DAG divergence after new FMA combine
authorJay Foad <jay.foad@amd.com>
Wed, 28 Sep 2022 14:20:08 +0000 (15:20 +0100)
committerJay Foad <jay.foad@amd.com>
Wed, 28 Sep 2022 18:41:51 +0000 (19:41 +0100)
commit2c12a04bba76e88259b3fae2cf7ce6f033a953ff
tree27ac93427e76474d9558b8bc3a8c4503c3fe2df9
parent2ad41f97f87ad94f4a6e536a0e9027fb954d651e
[ISel] Fix DAG divergence after new FMA combine

D132837 introduced a new DAG combine that used MorphNodeTo to morph an
FMUL into an FMA. It turns out that MorphNodeTo does not properly update
the divergence bit for users of the morphed node, causing an assertion
failure on the new test case:

llc: SelectionDAG.cpp:10486: void llvm::SelectionDAG::VerifyDAGDivergence(): Assertion `calculateDivergence(N) == N->isDivergent() && "Divergence bit inconsistency detected"' failed.

Fixing MorphNodeTo to propagate the divergence bit is tricky because of
the way it is used to select machine instructions, so use getNode and
ReplaceAllUsesOfValueWith instead.

Differential Revision: https://reviews.llvm.org/D134810
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AMDGPU/dagcombine-fma-fmad.ll