[AARCH64][RegisterCoalescer] clang miscompiles zero-extension to long long
authorSimon Wallis <simon.wallis2@arm.com>
Tue, 8 Sep 2020 07:04:52 +0000 (08:04 +0100)
committerSimon Wallis <simon.wallis2@arm.com>
Tue, 8 Sep 2020 07:04:52 +0000 (08:04 +0100)
commit8ee1419ab688ee2da2ac2cb0cf19db03f4c4742e
tree8fbecd613cd71edd2d0bf911e91dae30bcbbc35e
parentea795304ec073a63c3c5b4fd0c5579e667201dad
[AARCH64][RegisterCoalescer] clang miscompiles zero-extension to long long

Implement AArch64 variant of shouldCoalesce() to detect a known failing case
and prevent the coalescing of a 32-bit copy into a 64-bit sign-extending load.

Do not coalesce in the following case:
COPY where source is bottom 32 bits of a 64-register,
and destination is a 32-bit subregister of a 64-bit register,
ie it causes the rest of the register to be implicitly set to zero.

A mir test has been added.

In the test case, the 32-bit copy implements a 32 to 64 bit zero extension
and relies on the upper 32 bits being zeroed.

Coalescing to the result of the 64-bit load meant overwriting
the upper 32 bits incorrectly when the loaded byte was negative.

Reviewed By: john.brawn

Differential Revision: https://reviews.llvm.org/D85956
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
llvm/lib/Target/AArch64/AArch64RegisterInfo.h
llvm/test/CodeGen/AArch64/zext-reg-coalesce.mir [new file with mode: 0644]