[llvm] [LV][NFC] Add early bail-out in setCostBasedWideningDecision (PR #230414)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 9 01:54:59 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: David Sherwood (david-arm)
<details>
<summary>Changes</summary>
While doing recent work to improve the debug output when setting widening decisions I realised that we were unnecessarily printing out debug for all members of the interleave group. I thought in general it's perhaps clearer to bail out early if a particular memory access has already been decided.
---
Full diff: https://github.com/llvm/llvm-project/pull/230414.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/LoopVectorize.cpp (+5-6)
- (modified) llvm/test/Transforms/LoopVectorize/AArch64/memory-widening-debug.ll (-2)
``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 12332bfe08ead..d4961e4a7541b 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4532,8 +4532,11 @@ void LoopVectorizationCostModel::setCostBasedWideningDecision(ElementCount VF) {
for (BasicBlock *BB : TheLoop->blocks()) {
// For each instruction in the old loop.
for (Instruction &I : *BB) {
- Value *Ptr = getLoadStorePointerOperand(&I);
- if (!Ptr)
+ Value *Ptr = getLoadStorePointerOperand(&I);
+
+ // Ignore if no pointer found or a widening decision has already been
+ // made.
+ if (!Ptr || (getWideningDecision(&I, VF) != CM_Unknown))
continue;
LLVM_DEBUG(dbgs() << "LV: Memory widening: calculating best strategy for "
@@ -4606,10 +4609,6 @@ void LoopVectorizationCostModel::setCostBasedWideningDecision(ElementCount VF) {
const auto *Group = getInterleavedAccessGroup(&I);
assert(Group && "Fail to get an interleaved access group.");
- // Make one decision for the whole group.
- if (getWideningDecision(&I, VF) != CM_Unknown)
- continue;
-
NumAccesses = Group->getNumMembers();
if (interleavedAccessCanBeWidened(&I, VF))
InterleaveCost = getInterleaveGroupCost(&I, VF);
diff --git a/llvm/test/Transforms/LoopVectorize/AArch64/memory-widening-debug.ll b/llvm/test/Transforms/LoopVectorize/AArch64/memory-widening-debug.ll
index cad07645990c2..32f4fbddcaa84 100644
--- a/llvm/test/Transforms/LoopVectorize/AArch64/memory-widening-debug.ll
+++ b/llvm/test/Transforms/LoopVectorize/AArch64/memory-widening-debug.ll
@@ -53,7 +53,6 @@ define void @interleaved_load(ptr noalias readonly %src, ptr noalias %dst, i64 %
; FIXED: LV: Memory widening: InterleaveCost = 2, GatherScatterCost = Invalid, ScalarizationCost = 32
; FIXED: LV: Setting widening decision to Interleave for VF 4 and instruction: %load.0 = load i16, ptr %gep.0, align 2
; FIXED: LV: Setting widening decision to Interleave for VF 4 and instruction: %load.1 = load i16, ptr %gep.1, align 2
-; FIXED: LV: Memory widening: calculating best strategy for %load.1 = load i16, ptr %gep.1, align 2
; FIXED: LV: Memory widening: calculating best strategy for store i16 %add, ptr %dst.gep, align 2
; FIXED: LV: Memory widening: can be widened normally with cost 1
; FIXED: LV: Setting widening decision to Widen for VF 4 and instruction: store i16 %add, ptr %dst.gep, align 2
@@ -63,7 +62,6 @@ define void @interleaved_load(ptr noalias readonly %src, ptr noalias %dst, i64 %
; SVE: LV: Memory widening: InterleaveCost = 5, GatherScatterCost = 42, ScalarizationCost = Invalid
; SVE: LV: Setting widening decision to Interleave for VF vscale x 2 and instruction: %load.0 = load i16, ptr %gep.0, align 2
; SVE: LV: Setting widening decision to Interleave for VF vscale x 2 and instruction: %load.1 = load i16, ptr %gep.1, align 2
-; SVE: LV: Memory widening: calculating best strategy for %load.1 = load i16, ptr %gep.1, align 2
; SVE: LV: Memory widening: calculating best strategy for store i16 %add, ptr %dst.gep, align 2
; SVE: LV: Memory widening: can be widened normally with cost 1
; SVE: LV: Setting widening decision to Widen for VF vscale x 2 and instruction: store i16 %add, ptr %dst.gep, align 2
``````````
</details>
https://github.com/llvm/llvm-project/pull/230414
More information about the llvm-commits
mailing list