[llvm-branch-commits] [llvm] [AMDGPU] Let -align-loops override the target loop alignment (PR #242684)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Nov 14 10:50:25 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-amdgpu

Author: Dmitry Sidorov (MrSidims)

<details>
<summary>Changes</summary>

On subtargets that align loops themselves, -align-loops=N removed the loop
alignment instead of setting it to N.

Let the option override the target heuristics. -align-loops=1 now disables
loop alignment, as on other targets.

---

<sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub>

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


3 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/SIISelLowering.cpp (+5-1) 
- (modified) llvm/test/CodeGen/AMDGPU/loop-header-align-gfx950.mir (+6-6) 
- (modified) llvm/test/CodeGen/AMDGPU/loop-prefetch.ll (+8-1) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
index c22723e391093a..9cf22b5b97df38 100644
--- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
+++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp
@@ -20819,6 +20819,9 @@ Align SITargetLowering::getPrefLoopAlignment(
   const Align PrefAlign = TargetLowering::getPrefLoopAlignment(ML);
   const Align CacheLineAlign = Align(64);
 
+  if (getTargetMachine().Options.LoopAlignment)
+    return PrefAlign;
+
   // GFX950: Prevent an 8-byte instruction at the block being aligned from being
   // split by the 32-byte instruction fetch window boundary. This avoids a
   // significant fetch delay after a backward branch. We use 32-byte alignment
@@ -20913,7 +20916,8 @@ unsigned SITargetLowering::getMaxPermittedBytesForAlignment(
   // GFX950: Limit padding to 4 bytes (one s_nop) for blocks where an 8-byte
   // instruction could be split by the 32-byte fetch window boundary.
   // See getPrefLoopAlignment() for context.
-  if (needsFetchWindowAlignment(*MBB))
+  if (!getTargetMachine().Options.LoopAlignment &&
+      needsFetchWindowAlignment(*MBB))
     return 4;
   return TargetLowering::getMaxPermittedBytesForAlignment(MBB);
 }
diff --git a/llvm/test/CodeGen/AMDGPU/loop-header-align-gfx950.mir b/llvm/test/CodeGen/AMDGPU/loop-header-align-gfx950.mir
index d4ac12b1643f39..d032cd43b48877 100644
--- a/llvm/test/CodeGen/AMDGPU/loop-header-align-gfx950.mir
+++ b/llvm/test/CodeGen/AMDGPU/loop-header-align-gfx950.mir
@@ -48,7 +48,7 @@ body:             |
   ; ALIGN1-NEXT: {{  $}}
   ; ALIGN1-NEXT:   renamable $sgpr0_sgpr1 = S_MOV_B64 0
   ; ALIGN1-NEXT: {{  $}}
-  ; ALIGN1-NEXT: bb.1 (align 32, max-bytes-for-alignment 4):
+  ; ALIGN1-NEXT: bb.1:
   ; ALIGN1-NEXT:   successors: %bb.2(0x04000000), %bb.1(0x7c000000)
   ; ALIGN1-NEXT:   liveins: $sgpr0_sgpr1, $vgpr0_vgpr1
   ; ALIGN1-NEXT: {{  $}}
@@ -71,7 +71,7 @@ body:             |
   ; ALIGN16-NEXT: {{  $}}
   ; ALIGN16-NEXT:   renamable $sgpr0_sgpr1 = S_MOV_B64 0
   ; ALIGN16-NEXT: {{  $}}
-  ; ALIGN16-NEXT: bb.1:
+  ; ALIGN16-NEXT: bb.1 (align 16):
   ; ALIGN16-NEXT:   successors: %bb.2(0x04000000), %bb.1(0x7c000000)
   ; ALIGN16-NEXT:   liveins: $sgpr0_sgpr1, $vgpr0_vgpr1
   ; ALIGN16-NEXT: {{  $}}
@@ -166,7 +166,7 @@ body:             |
   ; ALIGN16-NEXT: {{  $}}
   ; ALIGN16-NEXT:   renamable $sgpr0_sgpr1 = S_MOV_B64 0
   ; ALIGN16-NEXT: {{  $}}
-  ; ALIGN16-NEXT: bb.1:
+  ; ALIGN16-NEXT: bb.1 (align 16):
   ; ALIGN16-NEXT:   successors: %bb.2(0x04000000), %bb.1(0x7c000000)
   ; ALIGN16-NEXT:   liveins: $sgpr0_sgpr1, $vgpr0
   ; ALIGN16-NEXT: {{  $}}
@@ -321,7 +321,7 @@ body:             |
   ; ALIGN16-NEXT: {{  $}}
   ; ALIGN16-NEXT:   S_BRANCH %bb.2
   ; ALIGN16-NEXT: {{  $}}
-  ; ALIGN16-NEXT: bb.6:
+  ; ALIGN16-NEXT: bb.6 (align 16):
   ; ALIGN16-NEXT:   successors: %bb.7(0x04000000), %bb.2(0x7c000000)
   ; ALIGN16-NEXT:   liveins: $vgpr0_vgpr1
   ; ALIGN16-NEXT: {{  $}}
@@ -483,7 +483,7 @@ body:             |
   ; ALIGN1-NEXT: {{  $}}
   ; ALIGN1-NEXT:   S_BRANCH %bb.2
   ; ALIGN1-NEXT: {{  $}}
-  ; ALIGN1-NEXT: bb.6 (align 32, max-bytes-for-alignment 4):
+  ; ALIGN1-NEXT: bb.6:
   ; ALIGN1-NEXT:   successors: %bb.7(0x04000000), %bb.2(0x7c000000)
   ; ALIGN1-NEXT:   liveins: $vgpr0_vgpr1
   ; ALIGN1-NEXT: {{  $}}
@@ -534,7 +534,7 @@ body:             |
   ; ALIGN16-NEXT: {{  $}}
   ; ALIGN16-NEXT:   S_BRANCH %bb.2
   ; ALIGN16-NEXT: {{  $}}
-  ; ALIGN16-NEXT: bb.6:
+  ; ALIGN16-NEXT: bb.6 (align 16):
   ; ALIGN16-NEXT:   successors: %bb.7(0x04000000), %bb.2(0x7c000000)
   ; ALIGN16-NEXT:   liveins: $vgpr0_vgpr1
   ; ALIGN16-NEXT: {{  $}}
diff --git a/llvm/test/CodeGen/AMDGPU/loop-prefetch.ll b/llvm/test/CodeGen/AMDGPU/loop-prefetch.ll
index 30697437a346a4..078cbe17c204e4 100644
--- a/llvm/test/CodeGen/AMDGPU/loop-prefetch.ll
+++ b/llvm/test/CodeGen/AMDGPU/loop-prefetch.ll
@@ -1,12 +1,15 @@
 ; RUN: llc -mtriple=amdgpu10.30 -asm-verbose=0 < %s | FileCheck --check-prefixes=GCN,GFX10,GFX10-ASM %s
 ; RUN: llc -mtriple=amdgpu10.30 < %s -filetype=obj | llvm-objdump -d --triple=amdgpu10.30 --symbolize-operands - | FileCheck --check-prefixes=GCN,GFX10,GFX10-DIS %s
-; RUN: llc -mtriple=amdgpu10.30 -asm-verbose=0 -align-loops=1 < %s | FileCheck --check-prefixes=GCN,GFX10,GFX10-ASM %s
+; RUN: llc -mtriple=amdgpu10.30 -asm-verbose=0 -align-loops=1 < %s | FileCheck --check-prefix=ALIGN1 %s
 ; RUN: llc -mtriple=amdgpu10.30 -asm-verbose=0 -align-loops=16 < %s | FileCheck --check-prefixes=GCN,ALIGN16 %s
 ; RUN: llc -mtriple=amdgpu8.02 < %s | FileCheck --check-prefix=GFX8 %s
 
 ; GFX8-NOT: s_inst_prefetch
 ; GFX8-NOT: .palign 6
 
+; ALIGN1-NOT: s_inst_prefetch
+; ALIGN1-NOT: .p2align 6
+
 ; GCN-LABEL: test_loop_64
 ; GFX10:          s_movk_i32 s{{[0-9]+}}, 0x400
 ; GFX10-DIS-NEXT: {{^$}}
@@ -16,6 +19,7 @@
 ; GFX10:          s_cbranch_scc0 [[L1]]
 ; GFX10-NEXT:     s_endpgm
 ; ALIGN16:        s_movk_i32 s{{[0-9]+}}, 0x400
+; ALIGN16-NEXT:   .p2align 4
 ; ALIGN16-NEXT:   [[L1:.LBB[0-9_]+]]:
 ; ALIGN16:        s_cbranch_scc0 [[L1]]
 ; ALIGN16-NEXT:   s_endpgm
@@ -45,6 +49,7 @@ bb2:                                              ; preds = %bb2, %bb
 ; GFX10:          s_cbranch_scc0 [[L1]]
 ; GFX10-NEXT:     s_endpgm
 ; ALIGN16:        s_movk_i32 s{{[0-9]+}}, 0x400
+; ALIGN16-NEXT:   .p2align 4
 ; ALIGN16-NEXT:   [[L1:.LBB[0-9_]+]]:
 ; ALIGN16:        s_cbranch_scc0 [[L1]]
 ; ALIGN16-NEXT:   s_endpgm
@@ -91,6 +96,7 @@ bb2:                                              ; preds = %bb2, %bb
 ; GFX10-NEXT:     s_inst_prefetch 0x2
 ; GFX10-NEXT:     s_endpgm
 ; ALIGN16:        s_movk_i32 s{{[0-9]+}}, 0x400
+; ALIGN16-NEXT:   .p2align 4
 ; ALIGN16-NEXT:   [[L1:.LBB[0-9_]+]]:
 ; ALIGN16:        s_cbranch_scc0 [[L1]]
 ; ALIGN16-NEXT:   s_endpgm
@@ -151,6 +157,7 @@ bb2:                                              ; preds = %bb2, %bb
 ; GFX10:          s_cbranch_scc0 [[L1]]
 ; GFX10-NEXT:     s_endpgm
 ; ALIGN16:        s_movk_i32 s{{[0-9]+}}, 0x400
+; ALIGN16-NEXT:   .p2align 4
 ; ALIGN16-NEXT:   [[L1:.LBB[0-9_]+]]:
 ; ALIGN16:        s_cbranch_scc0 [[L1]]
 ; ALIGN16-NEXT:   s_endpgm

``````````

</details>


https://github.com/llvm/llvm-project/pull/242684


More information about the llvm-branch-commits mailing list