[llvm] 3637f66 - [RISCV][TTI] Fix crash of non-built-in vector type cost quering. (#167258)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 10 01:01:47 PST 2025


Author: Elvis Wang
Date: 2025-11-10T17:01:43+08:00
New Revision: 3637f66b4d819c1cef6a3b58466fc8b1f983cfe0

URL: https://github.com/llvm/llvm-project/commit/3637f66b4d819c1cef6a3b58466fc8b1f983cfe0
DIFF: https://github.com/llvm/llvm-project/commit/3637f66b4d819c1cef6a3b58466fc8b1f983cfe0.diff

LOG: [RISCV][TTI] Fix crash of non-built-in vector type cost quering. (#167258)

For the non-built-in vector type, the RISCV cost model cannot handle
this properly.
So fall back to the BasicTTI for this situation.

Fixes: #166732

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
    llvm/test/Analysis/CostModel/RISCV/cast.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 332433b4e530b..3d8eb4097604a 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1683,7 +1683,8 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
       !TypeSize::isKnownLE(DL.getTypeSizeInBits(Src),
                            SrcLT.second.getSizeInBits()) ||
       !TypeSize::isKnownLE(DL.getTypeSizeInBits(Dst),
-                           DstLT.second.getSizeInBits()))
+                           DstLT.second.getSizeInBits()) ||
+      SrcLT.first > 1 || DstLT.first > 1)
     return BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
 
   // The split cost is handled by the base getCastInstrCost

diff  --git a/llvm/test/Analysis/CostModel/RISCV/cast.ll b/llvm/test/Analysis/CostModel/RISCV/cast.ll
index e64bce2d9c9e5..6dacd59f07fde 100644
--- a/llvm/test/Analysis/CostModel/RISCV/cast.ll
+++ b/llvm/test/Analysis/CostModel/RISCV/cast.ll
@@ -6239,3 +6239,13 @@ define void @legalization_crash() {
   fptoui <192 x float> undef to <192 x i1>
   ret void
 }
+
+; Test that types that need to be split go through BasicTTIImpl.
+define void @BitInt_crash() {
+; ZVE64X-LABEL: 'BitInt_crash'
+; ZVE64X-NEXT:  Cost Model: Found an estimated cost of 2043 for instruction: %1 = bitcast <16 x i64> poison to <512 x i2>
+; ZVE64X-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
+;
+  bitcast <16 x i64> poison to <512 x i2>
+  ret void
+}


        


More information about the llvm-commits mailing list