[llvm] [LV][NFC] Add early bail-out in setCostBasedWideningDecision (PR #230414)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 01:54:23 PDT 2026


https://github.com/david-arm created https://github.com/llvm/llvm-project/pull/230414

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.

>From 0737389726da2e7efb68528cb999fa9579e713ff Mon Sep 17 00:00:00 2001
From: David Sherwood <david.sherwood at arm.com>
Date: Fri, 9 Oct 2026 08:51:31 +0000
Subject: [PATCH] [LV][NFC] Add early bail-out in setCostBasedWideningDecision

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.
---
 llvm/lib/Transforms/Vectorize/LoopVectorize.cpp       | 11 +++++------
 .../LoopVectorize/AArch64/memory-widening-debug.ll    |  2 --
 2 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 12332bfe08eade..d4961e4a7541b0 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 cad07645990c26..32f4fbddcaa842 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



More information about the llvm-commits mailing list