[llvm] [RISCV][TTI] Fix potential crash of using dyn_cast() in getIntrinsicInstrCost() NFC. (PR #109379)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 23:12:34 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Elvis Wang (ElvisWang123)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/109379.diff
1 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp (+3-3)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 5d280b44630aef..d1cf7fc2991058 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);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/109379
More information about the llvm-commits
mailing list