[AMDGPU] Fix negative offset values interpretation in getMemOperandsWithOffset for DS
authorJanek van Oirschot <janek.vanoirschot@amd.com>
Wed, 26 Apr 2023 13:05:06 +0000 (14:05 +0100)
committerJanek van Oirschot <janek.vanoirschot@amd.com>
Wed, 26 Apr 2023 13:10:25 +0000 (14:10 +0100)
commit124acb7ca31aa358cc5f7b4a5d09edbd1c0cac84
treec76eb201226b78ee469a1ef08499701a8a495bd0
parentde2547329b41ad6ea4ea876d12731bde5a6b64c5
[AMDGPU] Fix negative offset values interpretation in getMemOperandsWithOffset for DS

The offset values may result in an erroneous scheduling of a load before write for a memory location if the offset values are represented as negative values in MIR, despite actually being unsigned values. This representation in MIR happens as SelectionDAG::getConstant could go through APInt to represent the encoding which assumes the MSB of the encoding as a sign-bit, regardless of whether it is supposed to be a signed value. The 8-bit negative (interpreted) value gets cast to an unsigned 32 bit value in getMemOperandsWithOffset used for comparisons in areMemAccessesTriviallyDisjoint eventually leading to an erroneous schedule in the machine scheduler.

Reviewed By: arsenm, foad

Differential Revision: https://reviews.llvm.org/D149080
llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/test/CodeGen/AMDGPU/si-triv-disjoint-mem-access.ll
llvm/test/CodeGen/AMDGPU/triv-disjoint-mem-access-neg-offset.mir [new file with mode: 0644]