[llvm] [WIP] Add new pass for converting scalable vector instructions with known VL to fixed length vectors (PR #190860)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 7 14:59:45 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Ryan Buchner (bababuck)

<details>
<summary>Changes</summary>

This provides an initial implementation of `ScalableToFixedVectorsPass`. This pass finds chains of scalable VP intrinsics that have a constant `%vl` that is less than `MinVScale * Width`. For instance,
```
call void @<!-- -->llvm.vp.store.nxv4i32.p0(<vscale x 4 x i32> %data, ptr %dst, <vscale x 4 x i1> splat (i1 true), i32 4)
...to...
store <4 x i32> %data, ptr %dst, align 16
```
This is necessary for LTO cases where the constant vector length isn't exposed until after vectorization has occurred. Particularly, we may be able to re-vectorize in the SLP which needs fixed length vectors. See #<!-- -->164762

AI Statement: I used internal AI tools to write the pass boilerplate and to conduct an initial code review.

Based on disucssions with @<!-- -->lukel97.

---

Patch is 44.68 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/190860.diff


7 Files Affected:

- (added) llvm/include/llvm/Transforms/Scalar/ScalableToFixedVectors.h (+83) 
- (modified) llvm/lib/Passes/PassBuilder.cpp (+1) 
- (modified) llvm/lib/Passes/PassBuilderPipelines.cpp (+6) 
- (modified) llvm/lib/Passes/PassRegistry.def (+1) 
- (modified) llvm/lib/Transforms/Scalar/CMakeLists.txt (+1) 
- (added) llvm/lib/Transforms/Scalar/ScalableToFixedVectors.cpp (+336) 
- (added) llvm/test/Transforms/ScalableToFixedVectors/basic.ll (+450) 


``````````diff
diff --git a/llvm/include/llvm/Transforms/Scalar/ScalableToFixedVectors.h b/llvm/include/llvm/Transforms/Scalar/ScalableToFixedVectors.h
new file mode 100644
index 0000000000000..4ca16db8a0db8
--- /dev/null
+++ b/llvm/include/llvm/Transforms/Scalar/ScalableToFixedVectors.h
@@ -0,0 +1,83 @@
+//===- ScalableToFixedVectors.h - Convert scalable to fixed vectors -------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass converts IR operations on scalable vector types to fixed-length
+// vectors when the effective length is known and is less than the minimum
+// possible scaled vector length. For a scalable vector type with
+// element count VF (known min elements), if minvscale * VF > VL, the we can
+// convert to a fixed length vector of length VL.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_SCALAR_SCALABLETOFIXEDVECTORS_H
+#define LLVM_TRANSFORMS_SCALAR_SCALABLETOFIXEDVECTORS_H
+
+#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/IR/Type.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <limits>
+
+namespace llvm {
+
+class ScalableToFixedVectorsPass
+    : public PassInfoMixin<ScalableToFixedVectorsPass> {
+public:
+  explicit ScalableToFixedVectorsPass() {}
+
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
+
+private:
+  void reset();
+  unsigned getMinimumVLOfInst(const Instruction *I) const;
+  void convertToFixed(IRBuilder<> &Builder, Instruction *I, unsigned VL);
+  bool isSupported(const Value *V) const;
+  void transfer(Instruction *I);
+  bool isSeedCandidate(const Instruction *I) const;
+  bool allVectorOperandsConverted(Instruction *I) const;
+
+  // Minimum VScale for the current function
+  unsigned MinVScale;
+  static constexpr unsigned MaxVL = std::numeric_limits<unsigned>::max();
+
+  /// For a given instruction, records what elements of it are demanded by
+  /// downstream users.
+  MapVector<Instruction *, unsigned> DemandedVLs;
+  /// Maps the original instructions to their fixed vector type version
+  MapVector<Instruction *, Instruction *> ScaledToFixed;
+  SetVector<Instruction *> Worklist;
+
+  /// \returns all operands that are of scalable vector type
+  auto vector_operands(Instruction *I) const {
+    return make_filter_range(I->operands(), [this](Value *V) {
+      return V->getType()->isScalableTy();
+    });
+  }
+
+  /// \returns all users of the given instruction
+  /// Returns as a Value* to be compatible with `vector_operands`
+  auto vector_users(Instruction *I) const {
+    return map_range(I->users(), [this](User *U) -> Value * { return U; });
+  }
+};
+} // end namespace llvm
+
+#endif // LLVM_TRANSFORMS_SCALAR_SCALABLETOFIXEDVECTORS_H
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index a23d64b491a79..5b99591b77060 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -334,6 +334,7 @@
 #include "llvm/Transforms/Scalar/RewriteStatepointsForGC.h"
 #include "llvm/Transforms/Scalar/SCCP.h"
 #include "llvm/Transforms/Scalar/SROA.h"
+#include "llvm/Transforms/Scalar/ScalableToFixedVectors.h"
 #include "llvm/Transforms/Scalar/ScalarizeMaskedMemIntrin.h"
 #include "llvm/Transforms/Scalar/Scalarizer.h"
 #include "llvm/Transforms/Scalar/SeparateConstOffsetFromGEP.h"
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 5e4688f4dd7ef..198b6adbe966b 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -129,6 +129,7 @@
 #include "llvm/Transforms/Scalar/Reassociate.h"
 #include "llvm/Transforms/Scalar/SCCP.h"
 #include "llvm/Transforms/Scalar/SROA.h"
+#include "llvm/Transforms/Scalar/ScalableToFixedVectors.h"
 #include "llvm/Transforms/Scalar/SimpleLoopUnswitch.h"
 #include "llvm/Transforms/Scalar/SimplifyCFG.h"
 #include "llvm/Transforms/Scalar/SpeculativeExecution.h"
@@ -806,6 +807,8 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
   FPM.addPass(InstCombinePass());
   invokePeepholeEPCallbacks(FPM, Level);
 
+  FPM.addPass(ScalableToFixedVectorsPass());
+
   return FPM;
 }
 
@@ -2290,6 +2293,9 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level,
                                       .convertSwitchToArithmetic(true)
                                       .hoistCommonInsts(true)
                                       .speculateUnpredictables(true)));
+
+  LateFPM.addPass(ScalableToFixedVectorsPass());
+
   MPM.addPass(createModuleToFunctionPassAdaptor(std::move(LateFPM)));
 
   // Drop bodies of available eternally objects to improve GlobalDCE.
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index c92d93d7ae396..19333573f891d 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -568,6 +568,7 @@ FUNCTION_PASS("view-dom-only", DomOnlyViewer())
 FUNCTION_PASS("view-post-dom", PostDomViewer())
 FUNCTION_PASS("view-post-dom-only", PostDomOnlyViewer())
 FUNCTION_PASS("wasm-eh-prepare", WasmEHPreparePass())
+FUNCTION_PASS("scalable-to-fixed-vectors", ScalableToFixedVectorsPass())
 #undef FUNCTION_PASS
 
 #ifndef FUNCTION_PASS_WITH_PARAMS
diff --git a/llvm/lib/Transforms/Scalar/CMakeLists.txt b/llvm/lib/Transforms/Scalar/CMakeLists.txt
index 37dbb34605646..12850197ca06e 100644
--- a/llvm/lib/Transforms/Scalar/CMakeLists.txt
+++ b/llvm/lib/Transforms/Scalar/CMakeLists.txt
@@ -80,6 +80,7 @@ add_llvm_component_library(LLVMScalarOpts
   StructurizeCFG.cpp
   TailRecursionElimination.cpp
   WarnMissedTransforms.cpp
+  ScalableToFixedVectors.cpp
 
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Transforms
diff --git a/llvm/lib/Transforms/Scalar/ScalableToFixedVectors.cpp b/llvm/lib/Transforms/Scalar/ScalableToFixedVectors.cpp
new file mode 100644
index 0000000000000..ca33bceadf337
--- /dev/null
+++ b/llvm/lib/Transforms/Scalar/ScalableToFixedVectors.cpp
@@ -0,0 +1,336 @@
+//===- ScalableToFixedVectors.cpp - Convert scalable to fixed vectors -----===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass converts IR operations on scalable vector types to fixed-length
+// vectors when the effective length is known and is less than the minimum
+// possible scaled vector length. For a scalable vector type with
+// element count VF (known min elements), if minvscale * VF > VL, the we can
+// convert to a fixed length vector of length VL.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Transforms/Scalar/ScalableToFixedVectors.h"
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/VectorUtils.h"
+#include "llvm/IR/Attributes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/InstrTypes.h"
+#include "llvm/IR/Instructions.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "scalable-to-fixed-vectors"
+
+STATISTIC(NumScalableInstructionsConvertedToFixed,
+          "Number of scalable instructions with constant EVL converted to "
+          "fixed vectors");
+STATISTIC(NumFunctionsWithScalableConvertedToFixed,
+          "Number of functions with scalable vector converted to fixed width");
+
+/// For a given Instruction \p I, find the vector length needed required by
+/// the vector instruction
+/// If a vector intrinsic, must have:
+/// - A constant VL
+/// - All `true` mask
+/// For other instructions, return 0 since length depends on demanded Elt's
+unsigned
+ScalableToFixedVectorsPass::getMinimumVLOfInst(const Instruction *I) const {
+  unsigned MinVL = 0;
+  if (const auto *VPI = dyn_cast<VPIntrinsic>(I)) {
+    auto getMinVLVPIntrinsic = [&](const VPIntrinsic *VPI) -> unsigned {
+      Value *Mask = VPI->getMaskParam();
+      if (!Mask)
+        return MaxVL;
+      Value *SV = getSplatValue(Mask);
+      if (!SV)
+        return MaxVL;
+      if (auto *CI = dyn_cast<ConstantInt>(SV); !CI || !CI->isOne())
+        return MaxVL;
+      Value *EVL = VPI->getVectorLengthParam();
+      const auto *CInt = dyn_cast_or_null<ConstantInt>(EVL);
+      if (!CInt)
+        return MaxVL;
+      uint64_t EVLVal64 =
+          std::min(CInt->getLimitedValue(MaxVL),
+                   static_cast<uint64_t>(std::numeric_limits<unsigned>::max()));
+      return static_cast<unsigned>(EVLVal64);
+    };
+    VectorType *VTy = nullptr;
+    switch (VPI->getIntrinsicID()) {
+    case Intrinsic::vp_store: {
+      VTy = dyn_cast<VectorType>(VPI->getMemoryDataParam()->getType());
+      break;
+    }
+    case Intrinsic::vp_load:
+      VTy = dyn_cast<VectorType>(I->getType());
+      break;
+    }
+    assert(VTy && "VP load/store must carry a scalable vector type");
+    ElementCount EC = VTy->getElementCount();
+    assert(EC.isScalable() && "Unexpected fixed type vector");
+    uint64_t MinElems = EC.getKnownMinValue();
+    uint64_t MinWidth = static_cast<uint64_t>(MinVScale) * MinElems;
+    unsigned EVLVal = getMinVLVPIntrinsic(VPI);
+    if (EVLVal <= MinWidth)
+      MinVL = EVLVal;
+    else
+      MinVL = MaxVL;
+  }
+  LLVM_DEBUG(dbgs() << "Found MinVL="; if (MinVL == MaxVL) dbgs() << "MaxVL";
+             else dbgs() << MinVL; dbgs() << " for " << *I << "\n");
+  return MinVL;
+}
+
+/// Is the given instruction a scalable vp_store
+/// Only consider vp_store since it can be converted to store
+static bool isScalableStoreVPIntrinsic(const Instruction *I) {
+  const auto *VPI = dyn_cast<VPIntrinsic>(I);
+  if (!VPI)
+    return false;
+  if (VPI->getIntrinsicID() != Intrinsic::vp_store)
+    return false;
+  return VPI->getMemoryDataParam()->getType()->isScalableTy();
+}
+
+/// Identify seed instructions to start conversion (vp_store only).
+bool ScalableToFixedVectorsPass::isSeedCandidate(const Instruction *I) const {
+  return isScalableStoreVPIntrinsic(I);
+}
+
+/// Check whether all scalable vector operands of I have been converted.
+bool ScalableToFixedVectorsPass::allVectorOperandsConverted(
+    Instruction *I) const {
+  for (Value *Op : vector_operands(I)) {
+    if (auto *OpI = dyn_cast<Instruction>(Op)) {
+      if (!ScaledToFixed.count(OpI))
+        return false;
+    }
+  }
+  return true;
+}
+
+/// Clear persistent data structures
+void ScalableToFixedVectorsPass::reset() {
+  DemandedVLs.clear();
+  ScaledToFixed.clear();
+}
+
+PreservedAnalyses
+ScalableToFixedVectorsPass::run(Function &F, FunctionAnalysisManager &FAM) {
+  LLVM_DEBUG(dbgs() << "Running ScalableToFixedVectorsPass on " << F.getName()
+                    << "\n");
+
+  assert(DemandedVLs.empty() &&
+         "DemandedVLs ought to be reset for each call to run()");
+  assert(Worklist.empty() &&
+         "Worklist ought to be reset for each call to run()");
+  assert(ScaledToFixed.empty() &&
+         "ScaledToFixed ought to be reset for each call to run()");
+
+  // If vscale is unknown, conservatively assume 1
+  Attribute VSR = F.getFnAttribute(Attribute::VScaleRange);
+  MinVScale = VSR.isValid() ? VSR.getVScaleRangeMin() : 1;
+
+  // For each instruction that defines a vector, propagate the VL it
+  // uses to its inputs.
+  for (BasicBlock &BB : F) {
+    for (Instruction &I : BB) {
+      if (isSeedCandidate(&I)) {
+        unsigned MinVL = getMinimumVLOfInst(&I);
+        if (MinVL != MaxVL) {
+          DemandedVLs[&I] = MinVL;
+          Worklist.insert(&I);
+        }
+      }
+    }
+  }
+
+  while (!Worklist.empty()) {
+    Instruction *I = Worklist.front();
+    Worklist.remove(I);
+    transfer(I);
+  }
+
+  // Find instructions that don't have any vector operands to start vectorizing
+  // from Need to go top down since we can't temporarily use the old
+  // instructions due to type mismatch
+  for (auto const &[I, VL] : DemandedVLs) {
+    if (VL == MaxVL)
+      continue;
+    if (llvm::none_of(vector_operands(I),
+                      [&](const Value *V) { return isa<Instruction>(V); }))
+      Worklist.insert(I);
+  }
+
+  if (Worklist.empty()) {
+    reset();
+    return PreservedAnalyses::all();
+  }
+
+  IRBuilder<> Builder(F.getContext());
+
+  while (!Worklist.empty()) {
+    Instruction *I = Worklist.front();
+    Worklist.remove(I);
+    unsigned VL = DemandedVLs[I];
+    assert(VL != MaxVL && "Should reduce VL");
+    convertToFixed(Builder, I, VL);
+    for (auto *U : I->users()) {
+      auto *UI = dyn_cast<Instruction>(U);
+      if (!UI)
+        continue;
+      if (allVectorOperandsConverted(UI))
+        Worklist.insert(UI);
+    }
+  }
+
+  // Clean up old instructions
+  // Work bottom up, only deleting once instruction has no users
+  for (BasicBlock &BB : F)
+    for (Instruction &I : BB)
+      if (isSeedCandidate(&I) && DemandedVLs[&I] != MaxVL)
+        Worklist.insert(&I);
+  while (!Worklist.empty()) {
+    Instruction *I = Worklist.front();
+    Worklist.remove(I);
+    for (Value *V : I->operands())
+      if (Instruction *OpI = dyn_cast<Instruction>(V))
+        if (OpI->hasOneUser())
+          Worklist.insert(OpI);
+    I->eraseFromParent();
+  }
+
+  reset();
+  ++NumFunctionsWithScalableConvertedToFixed;
+  return PreservedAnalyses::none();
+}
+
+/// Look through \p I's operands and propagate what it demands to its uses.
+/// Also capture its operations demands and transfer to itself
+/// Is bi-directional since we want all instructions in the graph
+/// to have the same type/length
+/// TODO: Can we shorten non-masked loads?
+void ScalableToFixedVectorsPass::transfer(Instruction *I) {
+  for (Value *Op : llvm::concat<Value *>(vector_operands(I), vector_users(I))) {
+    if (isSupported(Op)) {
+      if (Instruction *OpI = dyn_cast<Instruction>(Op)) {
+        unsigned Prev = DemandedVLs[OpI];
+        if (Prev == 0)
+          DemandedVLs[OpI] = std::max(DemandedVLs[I], getMinimumVLOfInst(OpI));
+        else
+          DemandedVLs[OpI] = std::max(DemandedVLs[I], DemandedVLs[OpI]);
+        // TODO: Support changing the length of VP intrinsics
+        if (isa<VPIntrinsic>(OpI) && getMinimumVLOfInst(OpI) != DemandedVLs[I])
+          DemandedVLs[OpI] = MaxVL;
+        if (DemandedVLs[OpI] != Prev) {
+          LLVM_DEBUG(dbgs() << "Updated " << *OpI << " with VL=";
+                     if (DemandedVLs[OpI] == MaxVL) dbgs() << "MaxVL";
+                     else dbgs() << DemandedVLs[OpI]; dbgs() << "\n");
+          Worklist.insert(OpI);
+        }
+      }
+    } else {
+      // Can't shorten non-intructions/unsupported instructions
+      LLVM_DEBUG(dbgs() << "Unsupported value " << *Op << "\n");
+      if (DemandedVLs[I] != MaxVL) {
+        DemandedVLs[I] = MaxVL;
+        Worklist.insert(I);
+      }
+    }
+  }
+}
+
+/// Return true if we can reason about demanded VLs elementwise for \p I.
+/// Right now just handle just a few easy to reason about operations
+/// TODO: Support other arithmetic instructions
+/// TODO: Support insert/extract subvectors
+/// TODO: Support PHIs
+/// TODO: Support arguments
+bool ScalableToFixedVectorsPass::isSupported(const Value *V) const {
+  if (auto *VPI = dyn_cast<VPIntrinsic>(V)) {
+    unsigned VPID = VPI->getIntrinsicID();
+    if (VPID != Intrinsic::vp_store && VPID != Intrinsic::vp_load)
+      return false;
+    return VPI->getType()->isScalableTy() || isScalableStoreVPIntrinsic(VPI);
+  } else if (auto *SV = getSplatValue(V)) {
+    return isa<Constant>(SV);
+  } else if (auto *I = dyn_cast<Instruction>(V)) {
+    return I->getType()->isScalableTy() && I->isBinaryOp();
+  }
+  return false;
+}
+
+/// Convert a single scalable vector instruction into a fixed width vector
+/// instruction Will convert select VP intrinsics into base vector instructions
+/// (e.g. vp_store -> store)
+void ScalableToFixedVectorsPass::convertToFixed(IRBuilder<> &Builder,
+                                                Instruction *I, unsigned VL) {
+  assert(isSupported(I) && "Cannot convert unsupported instruction");
+  Builder.SetInsertPoint(I);
+
+  // Return the transformed operation
+  auto TransformOp = [&](Value *Op) -> Value * {
+    if (auto *OpI = dyn_cast<Instruction>(Op)) {
+      if (ScaledToFixed.count(OpI)) {
+        return ScaledToFixed[OpI];
+      } else {
+        assert(
+            !DemandedVLs[OpI] &&
+            "Expected to find Fixed version of instruction with demanded VL");
+        return Op;
+      }
+    } else if (auto *SV = getSplatValue(Op); SV && isa<Constant>(SV)) {
+      return ConstantVector::getSplat(ElementCount::getFixed(VL),
+                                      cast<Constant>(SV));
+    }
+    return Op;
+  };
+
+  Value *Fixed = nullptr;
+  if (const auto *BOp = dyn_cast<BinaryOperator>(I)) {
+    Fixed = Builder.CreateBinOp(BOp->getOpcode(), TransformOp(I->getOperand(0)),
+                                TransformOp(I->getOperand(1)));
+  } else if (const auto *VPI = dyn_cast<VPIntrinsic>(I)) {
+    assert(VL == getMinimumVLOfInst(I) &&
+           "Can't reduce VP intrinsics with changed VL");
+    switch (VPI->getIntrinsicID()) {
+    case Intrinsic::vp_store:
+      Fixed = Builder.CreateAlignedStore(TransformOp(I->getOperand(0)),
+                                         TransformOp(I->getOperand(1)),
+                                         VPI->getParamAlign(1));
+      break;
+    case Intrinsic::vp_load:
+      Type *FixedType =
+          llvm::FixedVectorType::get(I->getType()->getScalarType(), VL);
+      Fixed = Builder.CreateAlignedLoad(
+          FixedType, TransformOp(I->getOperand(0)), VPI->getParamAlign(0));
+      break;
+    }
+  }
+  assert(Fixed && "Failed to create FixedOp");
+
+  Instruction *FI = cast<Instruction>(Fixed);
+  FI->copyMetadata(*I);
+  FI->copyIRFlags(I);
+  FI->setDebugLoc(I->getDebugLoc());
+  FI->takeName(I);
+  ScaledToFixed[I] = FI;
+  LLVM_DEBUG(dbgs() << "Converted scalable:\n"
+                    << *I << "\nto fixed:\n"
+                    << *FI << "\n");
+  ++NumScalableInstructionsConvertedToFixed;
+}
diff --git a/llvm/test/Transforms/ScalableToFixedVectors/basic.ll b/llvm/test/Transforms/ScalableToFixedVectors/basic.ll
new file mode 100644
index 0000000000000..e7f675311505d
--- /dev/null
+++ b/llvm/test/Transforms/ScalableToFixedVectors/basic.ll
@@ -0,0 +1,450 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes="function(scalable-to-fixed-vectors)" -S %s | FileCheck %s
+
+; Store of a splat vector
+define void @const_store(ptr %dst) vscale_range(2,4) {
+; CHECK-LABEL: define void @const_store(
+; CHECK-SAME: ptr [[DST:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:    store <4 x i32> splat (i32 2), ptr [[DST]], align 16
+; CHECK-NEXT:    ret void
+;
+  call void @llvm.vp.store.nxv4i32.p0(<vscale x 4 x i32> splat (i32 2), ptr %dst, <vscale x 4 x i1> splat (i1 true), i32 4)
+  ret void
+}
+
+; Simple load-store chain, VL < MinVScaleVL
+define void @load_store(ptr %src, ptr %dst) vscale_range(2,4) {
+; CHECK-LABEL: define void @load_store(
+; CHECK-SAME: ptr [[SRC:%.*]], ptr [[DST:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:    [[LOAD:%.*]] = load <4 x i32>, ptr [[SRC]], align 16
+; CHECK-NEXT:    store <4 x i32> [[LOAD]], ptr [[DST]], align 16
+; CHECK-NEXT:    ret void
+;
+  %load = tail call <vscale x 4 x i32> @llvm.vp.load.nxv4i32.p0(ptr %src, <vscale x 4 x i1> splat (i1 true), i32 4)
+  call void @llvm...
[truncated]

``````````

</details>


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


More information about the llvm-commits mailing list