AMDGPU: Handle invariant when lowering global loads#168914
Merged
Conversation
This was referenced Nov 20, 2025
Contributor
Author
Member
|
@llvm/pr-subscribers-backend-amdgpu Author: Matt Arsenault (arsenm) ChangesGlobal with invariant should be treated identically to Full diff: https://github.com/llvm/llvm-project/pull/168914.diff 2 Files Affected:
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index 875278a3b4f97..c681d12ba7499 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -11944,7 +11944,7 @@ SDValue SITargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
AS == AMDGPUAS::CONSTANT_ADDRESS_32BIT ||
(AS == AMDGPUAS::GLOBAL_ADDRESS &&
Subtarget->getScalarizeGlobalBehavior() && Load->isSimple() &&
- isMemOpHasNoClobberedMemOperand(Load))) {
+ (Load->isInvariant() || isMemOpHasNoClobberedMemOperand(Load)))) {
if ((!Op->isDivergent() || AMDGPU::isUniformMMO(MMO)) &&
Alignment >= Align(4) && NumElements < 32) {
if (MemVT.isPow2VectorType() ||
diff --git a/llvm/test/CodeGen/AMDGPU/load-global-invariant.ll b/llvm/test/CodeGen/AMDGPU/load-global-invariant.ll
index b881edde0f448..6cdadc5bab5fb 100644
--- a/llvm/test/CodeGen/AMDGPU/load-global-invariant.ll
+++ b/llvm/test/CodeGen/AMDGPU/load-global-invariant.ll
@@ -50,15 +50,22 @@ define amdgpu_kernel void @load_global_v3i64(ptr addrspace(1) %dst, ptr addrspac
define amdgpu_kernel void @load_global_v3i64_invariant(ptr addrspace(1) %dst, ptr addrspace(1) %src) #0 {
; CHECK-LABEL: load_global_v3i64_invariant:
; CHECK: ; %bb.0:
-; CHECK-NEXT: v_mov_b32_e32 v6, 0
-; CHECK-NEXT: s_load_dwordx2 s[0:1], s[8:9], 0x0
-; CHECK-NEXT: s_load_dwordx2 s[2:3], s[8:9], 0x8
+; CHECK-NEXT: v_mov_b32_e32 v4, 0
+; CHECK-NEXT: s_load_dwordx2 s[4:5], s[8:9], 0x0
+; CHECK-NEXT: s_load_dwordx2 s[6:7], s[8:9], 0x8
; CHECK-NEXT: s_waitcnt lgkmcnt(0)
-; CHECK-NEXT: global_load_dwordx4 v[0:3], v6, s[2:3]
-; CHECK-NEXT: global_load_dwordx2 v[4:5], v6, s[2:3] offset:16
-; CHECK-NEXT: s_waitcnt vmcnt(0)
-; CHECK-NEXT: global_store_dwordx2 v6, v[4:5], s[0:1] offset:16
-; CHECK-NEXT: global_store_dwordx4 v6, v[0:3], s[0:1]
+; CHECK-NEXT: s_load_dwordx4 s[0:3], s[6:7], 0x0
+; CHECK-NEXT: s_nop 0
+; CHECK-NEXT: s_load_dwordx2 s[6:7], s[6:7], 0x10
+; CHECK-NEXT: s_waitcnt lgkmcnt(0)
+; CHECK-NEXT: v_mov_b32_e32 v0, s6
+; CHECK-NEXT: v_mov_b32_e32 v1, s7
+; CHECK-NEXT: global_store_dwordx2 v4, v[0:1], s[4:5] offset:16
+; CHECK-NEXT: v_mov_b32_e32 v0, s0
+; CHECK-NEXT: v_mov_b32_e32 v1, s1
+; CHECK-NEXT: v_mov_b32_e32 v2, s2
+; CHECK-NEXT: v_mov_b32_e32 v3, s3
+; CHECK-NEXT: global_store_dwordx4 v4, v[0:3], s[4:5]
; CHECK-NEXT: s_endpgm
%ld = load <3 x i64>, ptr addrspace(1) %src, align 32, !invariant.load !0
store <3 x i64> %ld, ptr addrspace(1) %dst, align 32
|
🐧 Linux x64 Test Results
|
a406bd2 to
954dc93
Compare
dd3f339 to
1c8ddb0
Compare
Global with invariant should be treated identically to constant.
954dc93 to
4be9e5b
Compare
1c8ddb0 to
a8b806c
Compare
shiltian
reviewed
Nov 21, 2025
| (AS == AMDGPUAS::GLOBAL_ADDRESS && | ||
| Subtarget->getScalarizeGlobalBehavior() && Load->isSimple() && | ||
| isMemOpHasNoClobberedMemOperand(Load))) { | ||
| (Load->isInvariant() || isMemOpHasNoClobberedMemOperand(Load)))) { |
Contributor
There was a problem hiding this comment.
and there is no test change with this?
Contributor
Author
There was a problem hiding this comment.
No, there was in the test from #168913 but it turned out to be restoring a regression from one of the later patches
Base automatically changed from
users/arsenm/amdgpu/add-baseline-test-invariant-vector-load
to
main
November 21, 2025 18:53
shiltian
approved these changes
Nov 21, 2025
aadeshps-mcw
pushed a commit
to aadeshps-mcw/llvm-project
that referenced
this pull request
Nov 26, 2025
Global with invariant should be treated identically to constant.
Priyanshu3820
pushed a commit
to Priyanshu3820/llvm-project
that referenced
this pull request
Nov 26, 2025
Global with invariant should be treated identically to constant.
augusto2112
pushed a commit
to augusto2112/llvm-project
that referenced
this pull request
Dec 3, 2025
Global with invariant should be treated identically to constant.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Global with invariant should be treated identically to
constant.