[GlobalISel] Fix legalizer artifact combiner from crashing with invalid dead instruct...
authorAmara Emerson <aemerson@apple.com>
Wed, 27 Mar 2019 17:47:42 +0000 (17:47 +0000)
committerAmara Emerson <aemerson@apple.com>
Wed, 27 Mar 2019 17:47:42 +0000 (17:47 +0000)
commit381188f1f39ea8980c23aecb3a0695425aaa99cc
tree37d98299321ea6420325ab87ecff37a0e1441ee1
parente5094d6d3d29817d05e21cc6e34fad271b7e7d0a
[GlobalISel] Fix legalizer artifact combiner from crashing with invalid dead instructions.

The artifact combiners push instructions which have been marked for deletion
onto an list for the legalizer to deal with on return. However, for trunc(ext)
combines the combiner routine recursively calls itself. When it does this the
dead instructions list may not be empty, and the other combiners don't expect
to be dealing with essentially invalid MIR (multiple vreg defs etc).

This change fixes it by ensuring that the dead instructions are processed on
entry into tryCombineInstruction.

As a result, this fix exposed a few places in tests where G_TRUNC instructions
were not being deleted even though they were dead.

Differential Revision: https://reviews.llvm.org/D59892

llvm-svn: 357101
llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
llvm/lib/CodeGen/GlobalISel/Legalizer.cpp
llvm/test/CodeGen/AArch64/GlobalISel/legalize-phi.mir
llvm/test/CodeGen/AArch64/GlobalISel/legalizer-combiner-zext-trunc-crash.mir [new file with mode: 0644]
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-icmp.mir
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-unmerge-values.mir
llvm/test/CodeGen/Mips/GlobalISel/legalizer/sub.mir