Skip to content

[AMDGPU] Allow null operands in VImage tensor instructions#200911

Merged
RyanRio merged 3 commits into
llvm:mainfrom
RyanRio:users/rmitchel/null_tensor_opnds
Jun 5, 2026
Merged

[AMDGPU] Allow null operands in VImage tensor instructions#200911
RyanRio merged 3 commits into
llvm:mainfrom
RyanRio:users/rmitchel/null_tensor_opnds

Conversation

@RyanRio
Copy link
Copy Markdown
Contributor

@RyanRio RyanRio commented Jun 1, 2026

NULL is equivalent to passing a block of SGPRs that are set to zero, and is allowed

@llvmorg-github-actions
Copy link
Copy Markdown

@llvm/pr-subscribers-backend-amdgpu

Author: Ryan Mitchell (RyanRio)

Changes

NULL is equivalent to passing a block of SGPRs that are set to zero, and is allowed


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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/MIMGInstructions.td (+3-3)
  • (modified) llvm/test/MC/AMDGPU/gfx1250_asm_vimage_err.s (-36)
diff --git a/llvm/lib/Target/AMDGPU/MIMGInstructions.td b/llvm/lib/Target/AMDGPU/MIMGInstructions.td
index 0f31697f15688..a425e06a7554c 100644
--- a/llvm/lib/Target/AMDGPU/MIMGInstructions.td
+++ b/llvm/lib/Target/AMDGPU/MIMGInstructions.td
@@ -2182,9 +2182,9 @@ class VIMAGE_TENSOR_Pseudo<string opName, bit _UpTo2D = 0> :
   let hasSideEffects = 0;
 
   bit UpTo2D = _UpTo2D;
-  let InOperandList = !if(UpTo2D, (ins SReg_128_XNULL:$vaddr0, SReg_256_XNULL:$vaddr1, R128A16:$r128, CPol:$cpol),
-                                      (ins SReg_128_XNULL:$vaddr0, SReg_256_XNULL:$vaddr1, SReg_128_XNULL:$vaddr2,
-                                       SReg_128_XNULL:$vaddr3, R128A16:$r128, CPol:$cpol));
+  let InOperandList = !if(UpTo2D, (ins SReg_128:$vaddr0, SReg_256:$vaddr1, R128A16:$r128, CPol:$cpol),
+                                      (ins SReg_128:$vaddr0, SReg_256:$vaddr1, SReg_128:$vaddr2,
+                                       SReg_128:$vaddr3, R128A16:$r128, CPol:$cpol));
   string AsmOperands = " $vaddr0, $vaddr1"#!if(UpTo2D, "", ", $vaddr2, $vaddr3")#"$r128$cpol";
 }
 
diff --git a/llvm/test/MC/AMDGPU/gfx1250_asm_vimage_err.s b/llvm/test/MC/AMDGPU/gfx1250_asm_vimage_err.s
index 2f911ae79c00f..3f8a913b2c458 100644
--- a/llvm/test/MC/AMDGPU/gfx1250_asm_vimage_err.s
+++ b/llvm/test/MC/AMDGPU/gfx1250_asm_vimage_err.s
@@ -25,42 +25,6 @@ tensor_store_from_lds s[0:3], s[4:11], s[12:15], s[16:19] r128
 tensor_store_from_lds s[0:3], s[4:11], s[12:15], s[16:19] th:TH_LOAD_NT_HT scope:SCOPE_DEV
 // GFX1250-ERR: :[[@LINE-1]]:59: error: invalid th value for store instructions
 
-tensor_load_to_lds null, s[4:11]
-// GFX1250-ERR: :[[@LINE-1]]:20: error: invalid operand for instruction
-
-tensor_load_to_lds s[0:3], null
-// GFX1250-ERR: :[[@LINE-1]]:28: error: invalid operand for instruction
-
-tensor_load_to_lds null, s[4:11], s[12:15], s[16:19]
-// GFX1250-ERR: :[[@LINE-1]]:20: error: invalid operand for instruction
-
-tensor_load_to_lds s[0:3], null, s[12:15], s[16:19]
-// GFX1250-ERR: :[[@LINE-1]]:28: error: invalid operand for instruction
-
-tensor_load_to_lds s[0:3], s[4:11], null, s[16:19]
-// GFX1250-ERR: :[[@LINE-1]]:37: error: invalid operand for instruction
-
-tensor_load_to_lds s[0:3], s[4:11], s[12:15], null
-// GFX1250-ERR: :[[@LINE-1]]:47: error: invalid operand for instruction
-
-tensor_store_from_lds null, s[4:11]
-// GFX1250-ERR: :[[@LINE-1]]:23: error: invalid operand for instruction
-
-tensor_store_from_lds s[0:3], null
-// GFX1250-ERR: :[[@LINE-1]]:31: error: invalid operand for instruction
-
-tensor_store_from_lds null, s[4:11], s[12:15], s[16:19]
-// GFX1250-ERR: :[[@LINE-1]]:23: error: invalid operand for instruction
-
-tensor_store_from_lds s[0:3], null, s[12:15], s[16:19]
-// GFX1250-ERR: :[[@LINE-1]]:31: error: invalid operand for instruction
-
-tensor_store_from_lds s[0:3], s[4:11], null, s[16:19]
-// GFX1250-ERR: :[[@LINE-1]]:40: error: invalid operand for instruction
-
-tensor_store_from_lds s[0:3], s[4:11], s[12:15], null
-// GFX1250-ERR: :[[@LINE-1]]:50: error: invalid operand for instruction
-
 tensor_load_to_lds s[14:17], s[4:11]
 // GFX1250-ERR: :[[@LINE-1]]:20: error: invalid register alignment
 

tensor_store_from_lds s[0:3], s[4:11], s[12:15], s[16:19] th:TH_LOAD_NT_HT scope:SCOPE_DEV
// GFX1250-ERR: :[[@LINE-1]]:59: error: invalid th value for store instructions

tensor_load_to_lds null, s[4:11]
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.

Hmm, SP3 doesn't allow this syntax.

Also, need to add them to encoding/decoding tests.

@shiltian shiltian requested a review from rampitec June 1, 2026 19:39
Copy link
Copy Markdown
Contributor

@rampitec rampitec left a comment

Choose a reason for hiding this comment

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

First 2 operands can be numbered SGPRs only.

@RyanRio
Copy link
Copy Markdown
Contributor Author

RyanRio commented Jun 1, 2026

Yeah unfortunately that seems to be the case, even if maybe hardware doesn't check for it.

@RyanRio RyanRio closed this Jun 1, 2026
@rampitec
Copy link
Copy Markdown
Contributor

rampitec commented Jun 1, 2026

Yeah unfortunately that seems to be the case, even if maybe hardware doesn't check for it.

The other 2 can be null though.

@RyanRio RyanRio reopened this Jun 1, 2026
@RyanRio
Copy link
Copy Markdown
Contributor Author

RyanRio commented Jun 1, 2026

True 😄 adding the asm/dasm tests too

@RyanRio RyanRio requested review from rampitec and shiltian June 1, 2026 23:07
Copy link
Copy Markdown
Contributor

@rampitec rampitec left a comment

Choose a reason for hiding this comment

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

LGTM

// GFX12-ERR: :[[@LINE-1]]:1: error: instruction not supported on this GPU (gfx1200): tensor_store_from_lds
// GFX1250: tensor_store_from_lds s[0:3], s[4:11] th:TH_STORE_BYPASS scope:SCOPE_SYS ; encoding: [0x01,0x40,0x71,0xd0,0x00,0x00,0x3c,0x7c,0x00,0x04,0x7c,0x7c]

tensor_store_from_lds s[0:3], s[4:11], null, null th:TH_STORE_NT_HT scope:SCOPE_DEV
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.

There seems to be some difference between this and SP3:

tensor_store_from_lds  s[0:3], s[4:11], null, null dmask:0x1 th:TH_STORE_NT_HT scope:SCOPE_DEV // 000000000000: D0714001 7C680000 7C7C0400

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.

Hm you are right, that 0x71 should be 0x31

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.

This is also incorrect -

tensor_store_from_lds s[0:3], s[4:11] th:TH_STORE_BYPASS scope:SCOPE_SYS
// GFX12-ERR: :[[@line-1]]:1: error: instruction not supported on this GPU (gfx1200): tensor_store_from_lds
// GFX1250: tensor_store_from_lds s[0:3], s[4:11] th:TH_STORE_BYPASS scope:SCOPE_SYS ; encoding: [0x01,0x40,0x71,0xd0,0x00,0x00,0x3c,0x7c,0x00,0x04,0x7c,0x7c]

It has the same hex, and just leaves off the opnds (which btw, seems like in this case the sp3 does not leave them off, not specifying null is an error)

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.

Are we missing something about the reasoning for this in the tablegen -

let dmask = 1; // sp3
let dim = 1; // sp3

@rampitec @changpeng

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.

According to SPG these fields are unused and shall be set to 0.

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.

Right so it's a mistake they're set to 1 right now yeah

@RyanRio
Copy link
Copy Markdown
Contributor Author

RyanRio commented Jun 5, 2026

Ping, good to merge this, and fix dim/dmask separately?

@RyanRio RyanRio requested a review from shiltian June 5, 2026 14:30
Copy link
Copy Markdown
Contributor

@shiltian shiltian left a comment

Choose a reason for hiding this comment

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

Sounds good to me.

@RyanRio RyanRio merged commit de1ff3e into llvm:main Jun 5, 2026
10 checks passed
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