[llvm] AMDGPU: Only allow 31bit positive offset for scratch (PR #71895)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 22:40:45 PST 2023


https://github.com/ruiling created https://github.com/llvm/llvm-project/pull/71895

This just helps code safer as how the value interpreted by hardware might change.

>From 507125a8a02e4438b2b4da4b07e2e6ed8eb2cbb9 Mon Sep 17 00:00:00 2001
From: Ruiling Song <ruiling.song at amd.com>
Date: Fri, 10 Nov 2023 14:32:41 +0800
Subject: [PATCH] AMDGPU: Only allow 31bit positive offset for scratch

This just helps code safer as how the value interpreted by hardware
might change.
---
 llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
index cd810f0b43e50db..014026dd209da25 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
@@ -1859,7 +1859,7 @@ bool AMDGPUDAGToDAGISel::SelectScratchSVAddr(SDNode *N, SDValue Addr,
       std::tie(SplitImmOffset, RemainderOffset)
         = TII->splitFlatOffset(COffsetVal, AMDGPUAS::PRIVATE_ADDRESS, true);
 
-      if (isUInt<32>(RemainderOffset)) {
+      if (RemainderOffset > 0 && isInt<32>(RemainderOffset)) {
         SDNode *VMov = CurDAG->getMachineNode(
           AMDGPU::V_MOV_B32_e32, SL, MVT::i32,
           CurDAG->getTargetConstant(RemainderOffset, SDLoc(), MVT::i32));



More information about the llvm-commits mailing list