[llvm] [Hexagon] Exclude debug instructions from load/store widening size limit (PR #221649)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 6 23:19:23 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-hexagon
Author: Yongqiang Tian (yqtian-se)
<details>
<summary>Changes</summary>
## Summary
`HexagonLoadStoreWidening` used raw `MachineBasicBlock::size()` as a
compile-time guard. Debug instructions could therefore push an otherwise
identical block over the limit and disable load or store widening.
This uses `sizeWithoutDebugLargerThan` for the guard. That existing predicate
excludes debug instructions and pseudo probes from the count. A generated MIR
regression checks both sides of the instruction-count boundary.
## Testing
- At a limit of 8, the new regression fails its widening check on the
unmodified build and passes with this patch. At a limit of 7, it verifies
that 8 ordinary instructions still suppress widening.
- `utils/update_mir_test_checks.py` run with the patched `llc`.
- Hexagon CodeGen: 1550 passed, 3 unsupported, 13 expected failures; the one
excluded test lacks a target triple and passes when explicitly run with
`-mtriple=hexagon` (the minimal test build has no default target).
- Original C reproducer after the patch: both `-g0` and `-g` emit
`memd=1 memw=1`.
Fixes #<!-- -->221634
AI disclosure: This patch was developed with OpenAI Codex 5.6 Sol and
co-reviewed by Claude and Yongqiang Tian.
---
Full diff: https://github.com/llvm/llvm-project/pull/221649.diff
2 Files Affected:
- (modified) llvm/lib/Target/Hexagon/HexagonLoadStoreWidening.cpp (+1-1)
- (modified) llvm/test/CodeGen/Hexagon/load-widen-addasl.mir (+30-4)
``````````diff
diff --git a/llvm/lib/Target/Hexagon/HexagonLoadStoreWidening.cpp b/llvm/lib/Target/Hexagon/HexagonLoadStoreWidening.cpp
index 90996d4e9f41d..350f12a0094a0 100644
--- a/llvm/lib/Target/Hexagon/HexagonLoadStoreWidening.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonLoadStoreWidening.cpp
@@ -956,7 +956,7 @@ bool HexagonLoadStoreWidening::processBasicBlock(MachineBasicBlock &MBB) {
bool Changed = false;
// To prevent long compile time check for max BB size.
- if (MBB.size() > MaxMBBSizeForLoadStoreWidening)
+ if (MBB.sizeWithoutDebugLargerThan(MaxMBBSizeForLoadStoreWidening))
return false;
createGroups(MBB, SGs);
diff --git a/llvm/test/CodeGen/Hexagon/load-widen-addasl.mir b/llvm/test/CodeGen/Hexagon/load-widen-addasl.mir
index 50eed864b15cd..006c522f97627 100644
--- a/llvm/test/CodeGen/Hexagon/load-widen-addasl.mir
+++ b/llvm/test/CodeGen/Hexagon/load-widen-addasl.mir
@@ -1,7 +1,6 @@
-# RUN: llc -march=hexagon -run-pass=hexagon-widen-loads -verify-machineinstrs %s -o - | FileCheck %s
-
-# CHECK: S2_addasl_rrri [[VREG0:%[0-9]+]], [[VREG1:%[0-9]+]], [[IMM:[0-9]+]]
-# CHECK-NEXT: doubleregs = L4_loadrd_rr [[VREG0]], [[VREG1]], [[IMM]]
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
+# RUN: llc -march=hexagon -run-pass=hexagon-widen-loads -max-bb-size-for-load-store-widening=8 -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=WIDEN
+# RUN: llc -march=hexagon -run-pass=hexagon-widen-loads -max-bb-size-for-load-store-widening=7 -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=NO-WIDEN
--- |
define float @qhl_scalar_dsp_fft_f32(ptr %x, i32 %0) {
@@ -24,9 +23,36 @@ body: |
bb.0.entry:
liveins: $r0, $r1
+ ; WIDEN-LABEL: name: qhl_scalar_dsp_fft_f32
+ ; WIDEN: liveins: $r0, $r1
+ ; WIDEN-NEXT: {{ $}}
+ ; WIDEN-NEXT: [[COPY:%[0-9]+]]:intregs = COPY $r1
+ ; WIDEN-NEXT: [[COPY1:%[0-9]+]]:intregs = COPY $r0
+ ; WIDEN-NEXT: [[S2_addasl_rrri:%[0-9]+]]:intregs = S2_addasl_rrri [[COPY1]], [[COPY]], 3
+ ; WIDEN-NEXT: DBG_VALUE
+ ; WIDEN-NEXT: [[L4_loadrd_rr:%[0-9]+]]:doubleregs = L4_loadrd_rr [[COPY1]], [[COPY]], 3 :: (load (s64) from %ir.cgep)
+ ; WIDEN-NEXT: [[COPY2:%[0-9]+]]:intregs = COPY [[L4_loadrd_rr]].isub_lo
+ ; WIDEN-NEXT: [[COPY3:%[0-9]+]]:intregs = COPY [[L4_loadrd_rr]].isub_hi
+ ; WIDEN-NEXT: S2_storeri_io [[COPY1]], 0, killed [[COPY2]] :: (store (s32) into %ir.x, align 8)
+ ; WIDEN-NEXT: $r0 = COPY [[COPY3]]
+ ; WIDEN-NEXT: PS_jmpret $r31, implicit-def dead $pc, implicit $r0
+ ;
+ ; NO-WIDEN-LABEL: name: qhl_scalar_dsp_fft_f32
+ ; NO-WIDEN: liveins: $r0, $r1
+ ; NO-WIDEN-NEXT: {{ $}}
+ ; NO-WIDEN-NEXT: [[COPY:%[0-9]+]]:intregs = COPY $r1
+ ; NO-WIDEN-NEXT: [[COPY1:%[0-9]+]]:intregs = COPY $r0
+ ; NO-WIDEN-NEXT: [[S2_addasl_rrri:%[0-9]+]]:intregs = S2_addasl_rrri [[COPY1]], [[COPY]], 3
+ ; NO-WIDEN-NEXT: DBG_VALUE
+ ; NO-WIDEN-NEXT: [[L2_loadri_io:%[0-9]+]]:intregs = L2_loadri_io [[S2_addasl_rrri]], 0 :: (load (s32) from %ir.cgep, align 8)
+ ; NO-WIDEN-NEXT: S2_storeri_io [[COPY1]], 0, killed [[L2_loadri_io]] :: (store (s32) into %ir.x, align 8)
+ ; NO-WIDEN-NEXT: [[L2_loadri_io1:%[0-9]+]]:intregs = L2_loadri_io [[S2_addasl_rrri]], 4 :: (load (s32) from %ir.arrayidx.imagp)
+ ; NO-WIDEN-NEXT: $r0 = COPY [[L2_loadri_io1]]
+ ; NO-WIDEN-NEXT: PS_jmpret $r31, implicit-def dead $pc, implicit $r0
%1:intregs = COPY $r1
%0:intregs = COPY $r0
%2:intregs = S2_addasl_rrri %0, %1, 3
+ DBG_VALUE
%3:intregs = L2_loadri_io %2, 0 :: (load (s32) from %ir.cgep, align 8)
S2_storeri_io %0, 0, killed %3 :: (store (s32) into %ir.x, align 8)
%4:intregs = L2_loadri_io %2, 4 :: (load (s32) from %ir.arrayidx.imagp)
``````````
</details>
https://github.com/llvm/llvm-project/pull/221649
More information about the llvm-commits
mailing list