Skip to content

Commit b0769aa

Browse files
authored
[IR] Make intrinsic checks more efficient (NFC) (#148682)
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.
1 parent 13d8188 commit b0769aa

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class IntrinsicInst : public CallInst {
5454

5555
/// Return the intrinsic ID of this intrinsic.
5656
Intrinsic::ID getIntrinsicID() const {
57-
return getCalledFunction()->getIntrinsicID();
57+
return cast<Function>(getCalledOperand())->getIntrinsicID();
5858
}
5959

6060
bool isAssociative() const {
@@ -131,9 +131,8 @@ class IntrinsicInst : public CallInst {
131131

132132
/// Methods for support type inquiry through isa, cast, and dyn_cast:
133133
static bool classof(const CallInst *I) {
134-
if (const Function *CF = I->getCalledFunction())
135-
return CF->isIntrinsic();
136-
return false;
134+
auto *F = dyn_cast_or_null<Function>(I->getCalledOperand());
135+
return F && F->isIntrinsic();
137136
}
138137
static bool classof(const Value *V) {
139138
return isa<CallInst>(V) && classof(cast<CallInst>(V));

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ struct IntrinsicID_match {
26332633

26342634
template <typename OpTy> bool match(OpTy *V) const {
26352635
if (const auto *CI = dyn_cast<CallInst>(V))
2636-
if (const auto *F = CI->getCalledFunction())
2636+
if (const auto *F = dyn_cast_or_null<Function>(CI->getCalledOperand()))
26372637
return F->getIntrinsicID() == ID;
26382638
return false;
26392639
}

llvm/lib/IR/Instructions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ bool CallBase::isTailCall() const {
355355
}
356356

357357
Intrinsic::ID CallBase::getIntrinsicID() const {
358-
if (auto *F = getCalledFunction())
358+
if (auto *F = dyn_cast_or_null<Function>(getCalledOperand()))
359359
return F->getIntrinsicID();
360360
return Intrinsic::not_intrinsic;
361361
}

0 commit comments

Comments
 (0)