https://github.com/MrSidims created https://github.com/llvm/llvm-project/pull/242684
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> >From 51bf36a707aa38c605ebdafd2c0d7eea90615bfd Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov <[email protected]> Date: Sat, 14 Nov 2026 14:19:37 +0100 Subject: [PATCH] [AMDGPU] Let -align-loops override the target loop alignment 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. --- llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 6 +++++- .../test/CodeGen/AMDGPU/loop-header-align-gfx950.mir | 12 ++++++------ llvm/test/CodeGen/AMDGPU/loop-prefetch.ll | 9 ++++++++- 3 files changed, 19 insertions(+), 8 deletions(-) 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 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
