Index: llvm/trunk/include/llvm/Analysis/GuardUtils.h =================================================================== --- llvm/trunk/include/llvm/Analysis/GuardUtils.h +++ llvm/trunk/include/llvm/Analysis/GuardUtils.h @@ -0,0 +1,26 @@ +//===-- GuardUtils.h - Utils for work with guards ---------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Utils that are used to perform analyzes related to guards and their +// conditions. +//===----------------------------------------------------------------------===// + +#ifndef LLVM_ANALYSIS_GUARDUTILS_H +#define LLVM_ANALYSIS_GUARDUTILS_H + +namespace llvm { + +class User; + +/// Returns true iff \p U has semantics of a guard. +bool isGuard(const User *U); + +} // llvm + +#endif // LLVM_ANALYSIS_GUARDUTILS_H + Index: llvm/trunk/lib/Analysis/AliasSetTracker.cpp =================================================================== --- llvm/trunk/lib/Analysis/AliasSetTracker.cpp +++ llvm/trunk/lib/Analysis/AliasSetTracker.cpp @@ -13,6 +13,7 @@ #include "llvm/Analysis/AliasSetTracker.h" #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/GuardUtils.h" #include "llvm/Analysis/MemoryLocation.h" #include "llvm/Config/llvm-config.h" #include "llvm/IR/CallSite.h" @@ -172,8 +173,7 @@ // Guards are marked as modifying memory for control flow modelling purposes, // but don't actually modify any specific memory location. using namespace PatternMatch; - bool MayWriteMemory = I->mayWriteToMemory() && - !match(I, m_Intrinsic()) && + bool MayWriteMemory = I->mayWriteToMemory() && !isGuard(I) && !(I->use_empty() && match(I, m_Intrinsic())); if (!MayWriteMemory) { Alias = SetMayAlias; Index: llvm/trunk/lib/Analysis/CMakeLists.txt =================================================================== --- llvm/trunk/lib/Analysis/CMakeLists.txt +++ llvm/trunk/lib/Analysis/CMakeLists.txt @@ -30,6 +30,7 @@ DominanceFrontier.cpp EHPersonalities.cpp GlobalsModRef.cpp + GuardUtils.cpp IVUsers.cpp IndirectCallPromotionAnalysis.cpp InlineCost.cpp Index: llvm/trunk/lib/Analysis/GuardUtils.cpp =================================================================== --- llvm/trunk/lib/Analysis/GuardUtils.cpp +++ llvm/trunk/lib/Analysis/GuardUtils.cpp @@ -0,0 +1,21 @@ +//===-- GuardUtils.cpp - Utils for work with guards -------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Utils that are used to perform analyzes related to guards and their +// conditions. +//===----------------------------------------------------------------------===// + +#include "llvm/Analysis/GuardUtils.h" +#include "llvm/IR/PatternMatch.h" + +using namespace llvm; + +bool llvm::isGuard(const User *U) { + using namespace llvm::PatternMatch; + return match(U, m_Intrinsic()); +} Index: llvm/trunk/lib/Analysis/ValueTracking.cpp =================================================================== --- llvm/trunk/lib/Analysis/ValueTracking.cpp +++ llvm/trunk/lib/Analysis/ValueTracking.cpp @@ -26,6 +26,7 @@ #include "llvm/ADT/iterator_range.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/AssumptionCache.h" +#include "llvm/Analysis/GuardUtils.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/Loads.h" #include "llvm/Analysis/LoopInfo.h" @@ -1902,8 +1903,7 @@ BasicBlockEdge Edge(BI->getParent(), NonNullSuccessor); if (Edge.isSingleEdge() && DT->dominates(Edge, CtxI->getParent())) return true; - } else if (Pred == ICmpInst::ICMP_NE && - match(Curr, m_Intrinsic()) && + } else if (Pred == ICmpInst::ICMP_NE && isGuard(Curr) && DT->dominates(cast(Curr), CtxI)) { return true; } Index: llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp +++ llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp @@ -22,6 +22,7 @@ #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/AssumptionCache.h" #include "llvm/Analysis/GlobalsModRef.h" +#include "llvm/Analysis/GuardUtils.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/MemorySSA.h" #include "llvm/Analysis/MemorySSAUpdater.h" @@ -54,6 +55,7 @@ #include "llvm/Support/RecyclingAllocator.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/Utils/GuardUtils.h" #include #include #include @@ -863,7 +865,7 @@ continue; } - if (match(Inst, m_Intrinsic())) { + if (isGuard(Inst)) { if (auto *CondI = dyn_cast(cast(Inst)->getArgOperand(0))) { if (SimpleValue::canHandle(CondI)) { Index: llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp +++ llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp @@ -45,6 +45,7 @@ #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/Statistic.h" #include "llvm/Analysis/BranchProbabilityInfo.h" +#include "llvm/Analysis/GuardUtils.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/PostDominators.h" @@ -107,12 +108,6 @@ cast(I)->setCondition(NewCond); } -// Whether or not the particular instruction \p I is a guard. -static bool isGuard(const Instruction *I) { - using namespace llvm::PatternMatch; - return match(I, m_Intrinsic()); -} - // Eliminates the guard instruction properly. static void eliminateGuard(Instruction *GuardInst) { GuardInst->eraseFromParent(); Index: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp +++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp @@ -25,6 +25,7 @@ #include "llvm/Analysis/CFG.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/GlobalsModRef.h" +#include "llvm/Analysis/GuardUtils.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/LazyValueInfo.h" #include "llvm/Analysis/Loads.h" @@ -2607,9 +2608,8 @@ if (auto *BI = dyn_cast(Parent->getTerminator())) for (auto &I : *BB) - if (match(&I, m_Intrinsic())) - if (ThreadGuard(BB, cast(&I), BI)) - return true; + if (isGuard(&I) && ThreadGuard(BB, cast(&I), BI)) + return true; return false; } Index: llvm/trunk/lib/Transforms/Scalar/LICM.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/LICM.cpp +++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp @@ -38,6 +38,7 @@ #include "llvm/Analysis/CaptureTracking.h" #include "llvm/Analysis/ConstantFolding.h" #include "llvm/Analysis/GlobalsModRef.h" +#include "llvm/Analysis/GuardUtils.h" #include "llvm/Analysis/Loads.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopPass.h" @@ -528,7 +529,7 @@ using namespace PatternMatch; if (((I.use_empty() && match(&I, m_Intrinsic())) || - match(&I, m_Intrinsic())) && + isGuard(&I)) && IsMustExecute && IsMemoryNotModified && CurLoop->hasLoopInvariantOperands(&I)) { hoist(I, DT, CurLoop, SafetyInfo, ORE); Index: llvm/trunk/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp +++ llvm/trunk/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp @@ -15,6 +15,7 @@ #include "llvm/Transforms/Scalar/LowerGuardIntrinsic.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/Analysis/GuardUtils.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Function.h" #include "llvm/IR/InstIterator.h" @@ -49,10 +50,8 @@ SmallVector ToLower; for (auto &I : instructions(F)) - if (auto *CI = dyn_cast(&I)) - if (auto *F = CI->getCalledFunction()) - if (F->getIntrinsicID() == Intrinsic::experimental_guard) - ToLower.push_back(CI); + if (isGuard(&I)) + ToLower.push_back(cast(&I)); if (ToLower.empty()) return false;