From 96eaa942450bac15390f94351854ab5433895b66 Mon Sep 17 00:00:00 2001 From: Elvis Wang Date: Sun, 9 Nov 2025 16:20:03 -0800 Subject: [PATCH 1/2] [RISCV][TTI] Fix crash of non-built-in vector type cost quering. For the non-built-in vector type, the RISCV cost model cannot handle this propely. So fall back to the BasicTTI for this situation. Fixes: #166732 --- llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp | 3 ++- llvm/test/Analysis/CostModel/RISCV/cast.ll | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp index 7bc0b5b394828..73387b4999898 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..16163f7b07dee 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 BitInt cases won't crash at cost model. +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 +} From af172529234c7f76be50e2a78b99a4686ec1eba1 Mon Sep 17 00:00:00 2001 From: Elvis Wang Date: Sun, 9 Nov 2025 21:23:57 -0800 Subject: [PATCH 2/2] !fixup, adderss comments. --- llvm/test/Analysis/CostModel/RISCV/cast.ll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/test/Analysis/CostModel/RISCV/cast.ll b/llvm/test/Analysis/CostModel/RISCV/cast.ll index 16163f7b07dee..6dacd59f07fde 100644 --- a/llvm/test/Analysis/CostModel/RISCV/cast.ll +++ b/llvm/test/Analysis/CostModel/RISCV/cast.ll @@ -6240,7 +6240,7 @@ define void @legalization_crash() { ret void } -; Test that BitInt cases won't crash at cost model. +; 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>