[llvm] [AMDGPU] Fix negative immediate offset for unbuffered smem loads (PR #89165)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 18 02:23:29 PDT 2024


================
@@ -4221,7 +4232,13 @@ bool AMDGPUInstructionSelector::selectSmrdOffset(MachineOperand &Root,
   if (Offset && GEPI.SgprParts.size() == 1 && EncodedImm) {
     Base = GEPI.SgprParts[0];
     *Offset = *EncodedImm;
-    return true;
+    if (*Offset >= 0 || !STI.hasSignedSMRDImmOffset())
+      return true;
+    // For unbuffered smem loads, it is illegal for the Immediate Offset to be
+    // negative if the resulting (Offset + (M0 or SOffset or zero is negative.
+    // Handle the case where the Immediate Offset is negative and there is no
+    // SOffset.
+    return false;
----------------
arsenm wrote:

Also can directly return the boolean expression 

https://github.com/llvm/llvm-project/pull/89165


More information about the llvm-commits mailing list