From 28f27dd2641739e328ef0bec68a577ff44cbec33 Mon Sep 17 00:00:00 2001 From: Anna Thomas Date: Wed, 13 Apr 2022 12:08:53 -0400 Subject: [PATCH] Check users of instrinsics instead of traversing entire function.NFC Updated LowerGuardIntrinsic and LowerWidenableCondition to check for users of the respective intrinsic, instead of checking for guards and widenable conditions by traversing the entire function. This is an NFC. Should save some compile time. --- llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp | 10 +++++++--- llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp b/llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp index f9d9c80..8dc037b 100644 --- a/llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp +++ b/llvm/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp @@ -48,9 +48,13 @@ static bool lowerGuardIntrinsic(Function &F) { return false; SmallVector ToLower; - for (auto &I : instructions(F)) - if (isGuard(&I)) - ToLower.push_back(cast(&I)); + // Traverse through the users of GuardDecl. + // This is presumably cheaper than traversing all instructions in the + // function. + for (auto *U : GuardDecl->users()) + if (auto *CI = dyn_cast(U)) + if (CI->getFunction() == &F) + ToLower.push_back(CI); if (ToLower.empty()) return false; diff --git a/llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp b/llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp index 644bf3b..e2de322 100644 --- a/llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp +++ b/llvm/lib/Transforms/Scalar/LowerWidenableCondition.cpp @@ -47,9 +47,13 @@ static bool lowerWidenableCondition(Function &F) { using namespace llvm::PatternMatch; SmallVector ToLower; - for (auto &I : instructions(F)) - if (match(&I, m_Intrinsic())) - ToLower.push_back(cast(&I)); + // Traverse through the users of WCDecl. + // This is presumably cheaper than traversing all instructions in the + // function. + for (auto *U : WCDecl->users()) + if (auto *CI = dyn_cast(U)) + if (CI->getFunction() == &F) + ToLower.push_back(CI); if (ToLower.empty()) return false; -- 2.7.4