[llvm-branch-commits] [llvm] [AMDGPU] Ignore call clobbers in `fixShift64HiggRegBug` hazard check (PR #243358)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 16 22:17:33 PST 2026


https://github.com/easyonaadit created https://github.com/llvm/llvm-project/pull/243358

The check for `fixShift64HighRegBug` checks the reg mask to find if
the next higher register is in use. This can give false positives.
Update it to only check for the actual registers which are used,
which is more conservative in some cases, but should help avoid miscompiles.

This bug was found due to a wrong result being computed in device libs with ASAN enabled.

>From e0bfe62b2cefbeee062e352a95390c9dfe836898 Mon Sep 17 00:00:00 2001
From: Aaditya <Aaditya.AlokDeshpande at amd.com>
Date: Tue, 17 Nov 2026 10:50:46 +0530
Subject: [PATCH] [AMDGPU] Ignore call clobbers in `fixShift64HiggRegBug`
 hazard check

The check for `fixShift64HighRegBug` checks the reg mask to find if
the next higher register is in use. This can give false positives.
Update it to only check for the actual registers which are used,
which is more conservative in some cases, but should help avoid miscompiles.

This bug was found due to a wrong result being computed in device libs with ASAN enabled.
---
 llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp | 4 +++-
 llvm/test/CodeGen/AMDGPU/hazard-shift64.mir    | 6 ++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp b/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp
index 073e3cbe5c6e61..58a170847a5469 100644
--- a/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp
+++ b/llvm/lib/Target/AMDGPU/GCNHazardRecognizer.cpp
@@ -2988,7 +2988,9 @@ bool GCNHazardRecognizer::fixShift64HighRegBug(MachineInstr *MI) {
   if (!TRI.isVGPR(MRI, AmtReg) || ((AmtReg - AMDGPU::VGPR0) & 7) != 7)
     return false;
 
-  if (AmtReg != AMDGPU::VGPR255 && MRI.isPhysRegUsed(AmtReg + 1))
+  // Registers clobbered by calls are not necessarily part of the allocation.
+  if (AmtReg != AMDGPU::VGPR255 &&
+      MRI.isPhysRegUsed(AmtReg + 1, /*SkipRegMaskTest=*/true))
     return false;
 
   assert(ST.needsAlignedVGPRs());
diff --git a/llvm/test/CodeGen/AMDGPU/hazard-shift64.mir b/llvm/test/CodeGen/AMDGPU/hazard-shift64.mir
index 1c3be407270b65..12c340a1b5de38 100644
--- a/llvm/test/CodeGen/AMDGPU/hazard-shift64.mir
+++ b/llvm/test/CodeGen/AMDGPU/hazard-shift64.mir
@@ -320,7 +320,8 @@ body:             |
     ; GCN: liveins: $sgpr4_sgpr5, $sgpr82_sgpr83, $vgpr63
     ; GCN-NEXT: {{  $}}
     ; GCN-NEXT: $sgpr30_sgpr31 = SI_CALL killed $sgpr4_sgpr5, 0, csr_amdgpu_gfx90ainsts
-    ; GCN-NEXT: renamable $vgpr2_vgpr3 = V_LSHRREV_B64_e64 killed $vgpr63, killed $sgpr82_sgpr83, implicit $exec
+    ; GCN-NEXT: $vgpr2 = V_MOV_B32_e32 killed $vgpr63, implicit $exec
+    ; GCN-NEXT: renamable $vgpr2_vgpr3 = V_LSHRREV_B64_e64 killed $vgpr2, killed $sgpr82_sgpr83, implicit $exec
     ; GCN-NEXT: S_ENDPGM 0, implicit $vgpr2_vgpr3
     $sgpr30_sgpr31 = SI_CALL killed $sgpr4_sgpr5, 0, csr_amdgpu_gfx90ainsts
     renamable $vgpr2_vgpr3 = V_LSHRREV_B64_e64 killed $vgpr63, killed $sgpr82_sgpr83, implicit $exec
@@ -382,7 +383,8 @@ body:             |
     ; GCN: liveins: $sgpr4_sgpr5, $sgpr82_sgpr83, $vgpr63
     ; GCN-NEXT: {{  $}}
     ; GCN-NEXT: $sgpr30_sgpr31 = SI_CALL killed $sgpr4_sgpr5, @callee_uses_v71, csr_amdgpu_gfx90ainsts
-    ; GCN-NEXT: renamable $vgpr2_vgpr3 = V_LSHRREV_B64_e64 killed $vgpr63, killed $sgpr82_sgpr83, implicit $exec
+    ; GCN-NEXT: $vgpr2 = V_MOV_B32_e32 killed $vgpr63, implicit $exec
+    ; GCN-NEXT: renamable $vgpr2_vgpr3 = V_LSHRREV_B64_e64 killed $vgpr2, killed $sgpr82_sgpr83, implicit $exec
     ; GCN-NEXT: S_ENDPGM 0, implicit $vgpr2_vgpr3
     $sgpr30_sgpr31 = SI_CALL killed $sgpr4_sgpr5, @callee_uses_v71, csr_amdgpu_gfx90ainsts
     renamable $vgpr2_vgpr3 = V_LSHRREV_B64_e64 killed $vgpr63, killed $sgpr82_sgpr83, implicit $exec



More information about the llvm-branch-commits mailing list