[llvm] 86ce8e4 - [RISCV][TTI] Fix potential crash of using dyn_cast() in getIntrinsicInstrCost() NFC. (#109379)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 20 07:45:56 PDT 2024
Author: Elvis Wang
Date: 2024-09-20T22:45:53+08:00
New Revision: 86ce8e4504c06ecc3cc42f002ad4eb05cac10925
URL: https://github.com/llvm/llvm-project/commit/86ce8e4504c06ecc3cc42f002ad4eb05cac10925
DIFF: https://github.com/llvm/llvm-project/commit/86ce8e4504c06ecc3cc42f002ad4eb05cac10925.diff
LOG: [RISCV][TTI] Fix potential crash of using dyn_cast() in getIntrinsicInstrCost() NFC. (#109379)
This patch fix the potential crash about using dyn_cast in `vp_cmp`
which is same as #109313.
Check if the IntrinsicCostAttrubute contains underlying instruction
first and cast to the VPCmpIntrinsic.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index c850b91a410927..d4513a576e7b85 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1039,12 +1039,12 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
case Intrinsic::vp_fcmp: {
Intrinsic::ID IID = ICA.getID();
std::optional<unsigned> FOp = VPIntrinsic::getFunctionalOpcodeForVP(IID);
- auto *UI = dyn_cast<VPCmpIntrinsic>(ICA.getInst());
-
// We can only handle vp_cmp intrinsics with underlying instructions.
- if (!UI)
+ if (!ICA.getInst())
break;
+
assert(FOp);
+ auto *UI = cast<VPCmpIntrinsic>(ICA.getInst());
return getCmpSelInstrCost(*FOp, ICA.getArgTypes()[0], ICA.getReturnType(),
UI->getPredicate(), CostKind);
}
More information about the llvm-commits
mailing list