[GlobalISel][IRTranslator] Fix <1 x Ty> handling in ConstantExprs
authorJay Foad <jay.foad@amd.com>
Fri, 17 Apr 2020 15:17:26 +0000 (16:17 +0100)
committerJay Foad <jay.foad@amd.com>
Tue, 12 May 2020 15:51:03 +0000 (16:51 +0100)
commit989be65b11fa2fbc2cde7e188657636ea9a2da1d
tree10553e3690cae1ad2af4ae728319cfbe104bdeef
parentbd80a8bb87617a25a1fda0338db3b26637b273a0
[GlobalISel][IRTranslator] Fix <1 x Ty> handling in ConstantExprs

Summary:
ConstantExprs involving operations on <1 x Ty> could translate into MIR
that failed to verify with:
*** Bad machine code: Reading virtual register without a def ***

The problem was that translate(const Constant &C, Register Reg) had
recursive calls that passed the same Reg in for the translation of a
subexpression, but without updating VMap for the subexpression first as
translate(const Constant &C, Register Reg) expects.

Fix this by using the same translateCopy helper function that we use for
translating Instructions. In some cases this causes extra G_COPY
MIR instructions to be generated.

Fixes https://bugs.llvm.org/show_bug.cgi?id=45576

Reviewers: arsenm, volkan, t.p.northover, aditya_nandakumar

Subscribers: jvesely, wdng, nhaehnle, rovka, hiraditya, kerbowa, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78378
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
llvm/test/CodeGen/AMDGPU/GlobalISel/irtranslator-constantexpr.ll [new file with mode: 0644]