Skip to content

Commit 2fbc40d

Browse files
committed
[RISCV] Split compound if statement to fix a crash.
We're not allowed to call getELEN when the vector extension is not enabled. If we're looking at a vector type, isTypeLegal would only return true if the vector extensions are enabled. So early out for non-vector types before we call isTypeLegal and getELEN.
1 parent cf6e62d commit 2fbc40d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,12 +898,15 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
898898
TTI::TargetCostKind CostKind,
899899
const Instruction *I) {
900900
bool IsVectorType = isa<VectorType>(Dst) && isa<VectorType>(Src);
901+
if (!IsVectorType)
902+
return BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
903+
901904
bool IsTypeLegal = isTypeLegal(Src) && isTypeLegal(Dst) &&
902905
(Src->getScalarSizeInBits() <= ST->getELen()) &&
903906
(Dst->getScalarSizeInBits() <= ST->getELen());
904907

905908
// FIXME: Need to compute legalizing cost for illegal types.
906-
if (!IsVectorType || !IsTypeLegal)
909+
if (!IsTypeLegal)
907910
return BaseT::getCastInstrCost(Opcode, Dst, Src, CCH, CostKind, I);
908911

909912
int ISD = TLI->InstructionOpcodeToISD(Opcode);

0 commit comments

Comments
 (0)