[llvm] [IR] Make intrinsic checks more efficient (NFC) (PR #148682)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 14 10:30:42 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
Directly cast the callee operand instead of going through getCalledFunction(). We can do this because for intrinsics the function type between the call and the function is guaranteed to match.
This is a minor compile-time improvement as is, but has a much bigger impact with a future change that makes getCalledFunction() more expensive.
There is some code duplication between these four uses, but they are each just different enough that representing one in terms of another would be less efficient.
Compile-time: https://llvm-compile-time-tracker.com/compare.php?from=65d20bb0ab27f1b0078cc8811d02f7b47eb779bf&to=bd48e3670dd5100808deb1b74294e6bcd4966d3f&stat=instructions:u
---
Full diff: https://github.com/llvm/llvm-project/pull/148682.diff
3 Files Affected:
- (modified) llvm/include/llvm/IR/IntrinsicInst.h (+3-4)
- (modified) llvm/include/llvm/IR/PatternMatch.h (+1-1)
- (modified) llvm/lib/IR/Instructions.cpp (+1-1)
``````````diff
diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h
index d8f8bdeb01d43..0318427bf8a1c 100644
--- a/llvm/include/llvm/IR/IntrinsicInst.h
+++ b/llvm/include/llvm/IR/IntrinsicInst.h
@@ -54,7 +54,7 @@ class IntrinsicInst : public CallInst {
/// Return the intrinsic ID of this intrinsic.
Intrinsic::ID getIntrinsicID() const {
- return getCalledFunction()->getIntrinsicID();
+ return cast<Function>(getCalledOperand())->getIntrinsicID();
}
bool isAssociative() const {
@@ -131,9 +131,8 @@ class IntrinsicInst : public CallInst {
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const CallInst *I) {
- if (const Function *CF = I->getCalledFunction())
- return CF->isIntrinsic();
- return false;
+ auto *F = dyn_cast_or_null<Function>(I->getCalledOperand());
+ return F && F->isIntrinsic();
}
static bool classof(const Value *V) {
return isa<CallInst>(V) && classof(cast<CallInst>(V));
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index ed9b83d5d4361..50e50a91389e2 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -2633,7 +2633,7 @@ struct IntrinsicID_match {
template <typename OpTy> bool match(OpTy *V) const {
if (const auto *CI = dyn_cast<CallInst>(V))
- if (const auto *F = CI->getCalledFunction())
+ if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand()))
return F->getIntrinsicID() == ID;
return false;
}
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 9fe79366f9b2f..b8963823f1c67 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -355,7 +355,7 @@ bool CallBase::isTailCall() const {
}
Intrinsic::ID CallBase::getIntrinsicID() const {
- if (auto *F = getCalledFunction())
+ if (auto *F = dyn_cast_or_null<Function>(getCalledOperand()))
return F->getIntrinsicID();
return Intrinsic::not_intrinsic;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/148682
More information about the llvm-commits
mailing list