Skip to content

Commit 86ce8e4

Browse files
authored
[RISCV][TTI] Fix potential crash of using dyn_cast() in getIntrinsicInstrCost() NFC. (llvm#109379)
This patch fix the potential crash about using dyn_cast in `vp_cmp` which is same as llvm#109313. Check if the IntrinsicCostAttrubute contains underlying instruction first and cast to the VPCmpIntrinsic.
1 parent 4eb9838 commit 86ce8e4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,12 +1039,12 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
10391039
case Intrinsic::vp_fcmp: {
10401040
Intrinsic::ID IID = ICA.getID();
10411041
std::optional<unsigned> FOp = VPIntrinsic::getFunctionalOpcodeForVP(IID);
1042-
auto *UI = dyn_cast<VPCmpIntrinsic>(ICA.getInst());
1043-
10441042
// We can only handle vp_cmp intrinsics with underlying instructions.
1045-
if (!UI)
1043+
if (!ICA.getInst())
10461044
break;
1045+
10471046
assert(FOp);
1047+
auto *UI = cast<VPCmpIntrinsic>(ICA.getInst());
10481048
return getCmpSelInstrCost(*FOp, ICA.getArgTypes()[0], ICA.getReturnType(),
10491049
UI->getPredicate(), CostKind);
10501050
}

0 commit comments

Comments
 (0)