[llvm] [llvm][RISCV] Do not assume V extension on seeing vector type. (PR #166994)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 7 10:53:50 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-risc-v

Author: Chenguang Wang (wecing)

<details>
<summary>Changes</summary>

We have a private extension which also uses the vector type in the frontend. Our platform does not have the V extension, so it triggered assertion failures from within getLMULCost().

I am not sure what is the best way to handle this, or if there are more such assertions within the codebase. But it feels reasonable to check for V extension before assuming LMUL exists.

---
Full diff: https://github.com/llvm/llvm-project/pull/166994.diff


1 Files Affected:

- (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp (+3-2) 


``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 7bc0b5b394828..ababe42604ba5 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -2140,8 +2140,9 @@ InstructionCost RISCVTTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src,
   // Assume memory ops cost scale with the number of vector registers
   // possible accessed by the instruction.  Note that BasicTTI already
   // handles the LT.first term for us.
-  if (LT.second.isVector() && CostKind != TTI::TCK_CodeSize)
-    BaseCost *= TLI->getLMULCost(LT.second);
+  if (TLI->getSubtarget().hasVInstructions())
+    if (LT.second.isVector() && CostKind != TTI::TCK_CodeSize)
+      BaseCost *= TLI->getLMULCost(LT.second);
   return Cost + BaseCost;
 }
 

``````````

</details>


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


More information about the llvm-commits mailing list