Skip to content

[AMDGPU] Fix V_INDIRECT_REG_READ_GPR_IDX expansion with immediate index - #179699

Merged
kurapov-peter merged 4 commits into
llvm:mainfrom
kurapov-peter:fix-indirect-reg-read-imm-idx
Feb 9, 2026
Merged

[AMDGPU] Fix V_INDIRECT_REG_READ_GPR_IDX expansion with immediate index#179699
kurapov-peter merged 4 commits into
llvm:mainfrom
kurapov-peter:fix-indirect-reg-read-imm-idx

Conversation

@kurapov-peter

Copy link
Copy Markdown
Contributor

The definition for V_INDIRECT_REG_READ_GPR_IDX_B32_V*'s SSrc_b32 operand allows immediates, but the expansion logic handles only register cases now. This can result in expansion failures when e.g. llvm.amdgcn.wave.reduce.umin.i32 is folded into a constant and then used as an insertelement idx.

@llvmbot

llvmbot commented Feb 4, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-backend-amdgpu

Author: Petr Kurapov (kurapov-peter)

Changes

The definition for V_INDIRECT_REG_READ_GPR_IDX_B32_V*'s SSrc_b32 operand allows immediates, but the expansion logic handles only register cases now. This can result in expansion failures when e.g. llvm.amdgcn.wave.reduce.umin.i32 is folded into a constant and then used as an insertelement idx.


Full diff: https://github.com/llvm/llvm-project/pull/179699.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/SIInstrInfo.cpp (+1-2)
diff --git a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
index 9e3b683d10c45..581391d3d83db 100644
--- a/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/SIInstrInfo.cpp
@@ -2410,11 +2410,10 @@ bool SIInstrInfo::expandPostRAPseudo(MachineInstr &MI) const {
     Register Dst = MI.getOperand(0).getReg();
     Register VecReg = MI.getOperand(1).getReg();
     bool IsUndef = MI.getOperand(1).isUndef();
-    Register Idx = MI.getOperand(2).getReg();
     Register SubReg = MI.getOperand(3).getImm();
 
     MachineInstr *SetOn = BuildMI(MBB, MI, DL, get(AMDGPU::S_SET_GPR_IDX_ON))
-                              .addReg(Idx)
+                              .add(MI.getOperand(2))
                               .addImm(AMDGPU::VGPRIndexMode::SRC0_ENABLE);
     SetOn->getOperand(3).setIsUndef();
 

@github-actions

github-actions Bot commented Feb 4, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 189668 tests passed
  • 5049 tests skipped

✅ The build succeeded and all tests passed.

@arsenm arsenm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs tests

@kurapov-peter

Copy link
Copy Markdown
Contributor Author

Needs tests

Is there something specific you have in mind? The change is trivial, so I decided it doesn't deserve a test.

@arsenm

arsenm commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Is there something specific you have in mind?

An IR and/or MIR test that would have asserted before

so I decided it doesn't deserve a test.

No, every functional change needs a test.

The definition for V_INDIRECT_REG_READ_GPR_IDX_B32_V*'s SSrc_b32 operand allows immediates, but the expansion logic handles only register cases now.
This can result in expansion failures when e.g. llvm.amdgcn.wave.reduce.umin.i32 is folded into a constant and then used as an insertelement idx.
@kurapov-peter
kurapov-peter force-pushed the fix-indirect-reg-read-imm-idx branch from d62b31c to 46d02a0 Compare February 5, 2026 15:41
@@ -0,0 +1,21 @@
; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -O1 -global-isel=true < %s | FileCheck %s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you actually need -O1 or -global-isel to reproduce? If not remove both

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I do need both

@arsenm arsenm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's so fragile it depends on -O1 -global-isel, might be worth adding a mir test

@@ -0,0 +1,21 @@
; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -O1 -global-isel=true < %s | FileCheck %s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -O1 -global-isel=true < %s | FileCheck %s
; RUN: llc -mtriple=amdgcn -mcpu=gfx90a -O1 -global-isel < %s | FileCheck %s

@kurapov-peter
kurapov-peter merged commit 27a8ab0 into llvm:main Feb 9, 2026
10 checks passed
@kurapov-peter
kurapov-peter deleted the fix-indirect-reg-read-imm-idx branch February 9, 2026 10:33
rishabhmadan19 pushed a commit to rishabhmadan19/llvm-project that referenced this pull request Feb 9, 2026
…ex (llvm#179699)

The definition for V_INDIRECT_REG_READ_GPR_IDX_B32_V*'s SSrc_b32 operand
allows immediates, but the expansion logic handles only register cases
now. This can result in expansion failures when e.g.
llvm.amdgcn.wave.reduce.umin.i32 is folded into a constant and then used
as an insertelement idx.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants