[GlobalISel] Fix CSEMIRBuilder silently allowing use-before-def.
authorAmara Emerson <amara@apple.com>
Tue, 29 Sep 2020 19:22:30 +0000 (12:22 -0700)
committerAmara Emerson <amara@apple.com>
Mon, 5 Oct 2020 18:00:00 +0000 (11:00 -0700)
commitc2bce848ecae0e17883e7cc4b8054c1e12ef1f98
treec678caf08a266b88549d922173e6d4903337627c
parent8fb4645321765124aa89c8e798a989eae38739ce
[GlobalISel] Fix CSEMIRBuilder silently allowing use-before-def.

If a CSEMIRBuilder query hits the instruction at the current insert point,
move insert point ahead one so that subsequent uses of the builder don't end up with
uses before defs.

This fix also shows that AMDGPU was also affected by this bug often, but got away
with it because it was using a G_IMPLICIT_DEF before the use.

Differential Revision: https://reviews.llvm.org/D88605
llvm/lib/CodeGen/GlobalISel/CSEMIRBuilder.cpp
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-implicit-def.mir
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-constant.mir
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-flat.mir
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-global.mir
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-local.mir
llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-load-private.mir
llvm/unittests/CodeGen/GlobalISel/CSETest.cpp