AMDGPU/GlobalISel: Fix crash after mad/fma_mix fails selection
authorPetar Avramovic <Petar.Avramovic@amd.com>
Fri, 18 Nov 2022 17:00:01 +0000 (18:00 +0100)
committerPetar Avramovic <Petar.Avramovic@amd.com>
Fri, 18 Nov 2022 17:02:26 +0000 (18:02 +0100)
commit0f3e72e86c8c7c6bf0ec24bf1e2acd74b4123e7b
treee443ce6118f3020fc8a7850e64e3ec7c183deb9a
parent38302c60efe520e2cf1749d6e1ac23648dcad5ee
AMDGPU/GlobalISel: Fix crash after mad/fma_mix fails selection

When selectVOP3PMadMixModsImpl fails, it can still create new copy instr
via selectVOP3ModsImpl. When selectG_FMA_FMAD gives up, new copy instr
will remain dead but will not be automatically removed.
InstructionSelect does not check if instructions created during selection
are dead.
Such dead copy doesn't have register class on dst operand and causes crash.
Fix is to build copy when operands are being added to selected instruction.

Differential Revision: https://reviews.llvm.org/D138044
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h
llvm/test/CodeGen/AMDGPU/GlobalISel/fma.ll