[llvm] r340921 - [NFC] Unify guards detection

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 29 05:23:13 PDT 2018


Reverted in r340923 as this broke the build on all builders from what
I can tell, e.g.

    http://lab.llvm.org:8011/builders/clang-cmake-armv8-lnt/builds/4626/
    http://lab.llvm.org:8011/builders/clang-ppc64be-linux-lnt/builds/18647/
    http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux/builds/5856/
    http://lab.llvm.org:8011/builders/lld-x86_64-freebsd/builds/22800/

Please try to keep an eye on buildbots / buildbot emails when committing.


On Wed, Aug 29, 2018 at 1:37 PM, Max Kazantsev via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: mkazantsev
> Date: Wed Aug 29 04:37:34 2018
> New Revision: 340921
>
> URL: http://llvm.org/viewvc/llvm-project?rev=340921&view=rev
> Log:
> [NFC] Unify guards detection
>
> We have multiple places in code where we try to identify whether or not
> some instruction is a guard. This patch factors out this logic into a separate
> utility function which works uniformly in all places.
>
> Differential Revision: https://reviews.llvm.org/D51152
> Reviewed By: fedor.sergeev
>
> Modified:
>     llvm/trunk/include/llvm/Transforms/Utils/GuardUtils.h
>     llvm/trunk/lib/Analysis/AliasSetTracker.cpp
>     llvm/trunk/lib/Analysis/ValueTracking.cpp
>     llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
>     llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp
>     llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
>     llvm/trunk/lib/Transforms/Scalar/LICM.cpp
>     llvm/trunk/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp
>     llvm/trunk/lib/Transforms/Utils/GuardUtils.cpp
>
> Modified: llvm/trunk/include/llvm/Transforms/Utils/GuardUtils.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/GuardUtils.h?rev=340921&r1=340920&r2=340921&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Transforms/Utils/GuardUtils.h (original)
> +++ llvm/trunk/include/llvm/Transforms/Utils/GuardUtils.h Wed Aug 29 04:37:34 2018
> @@ -17,6 +17,10 @@ namespace llvm {
>
>  class CallInst;
>  class Function;
> +class User;
> +
> +/// Returns true iff \p U has semantics of a guard.
> +bool isGuard(const User *U);
>
>  /// Splits control flow at point of \p Guard, replacing it with explicit branch
>  /// by the condition of guard's first argument. The taken branch then goes to
>
> Modified: llvm/trunk/lib/Analysis/AliasSetTracker.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasSetTracker.cpp?rev=340921&r1=340920&r2=340921&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/AliasSetTracker.cpp (original)
> +++ llvm/trunk/lib/Analysis/AliasSetTracker.cpp Wed Aug 29 04:37:34 2018
> @@ -34,6 +34,7 @@
>  #include "llvm/Support/Debug.h"
>  #include "llvm/Support/ErrorHandling.h"
>  #include "llvm/Support/raw_ostream.h"
> +#include "llvm/Transforms/Utils/GuardUtils.h"
>  #include <cassert>
>  #include <cstdint>
>  #include <vector>
> @@ -172,8 +173,7 @@ void AliasSet::addUnknownInst(Instructio
>    // 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<Intrinsic::experimental_guard>()) &&
> +  bool MayWriteMemory = I->mayWriteToMemory() && !isGuard(I) &&
>      !(I->use_empty() && match(I, m_Intrinsic<Intrinsic::invariant_start>()));
>    if (!MayWriteMemory) {
>      Alias = SetMayAlias;
>
> Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=340921&r1=340920&r2=340921&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
> +++ llvm/trunk/lib/Analysis/ValueTracking.cpp Wed Aug 29 04:37:34 2018
> @@ -66,6 +66,7 @@
>  #include "llvm/Support/ErrorHandling.h"
>  #include "llvm/Support/KnownBits.h"
>  #include "llvm/Support/MathExtras.h"
> +#include "llvm/Transforms/Utils/GuardUtils.h"
>  #include <algorithm>
>  #include <array>
>  #include <cassert>
> @@ -1902,8 +1903,7 @@ static bool isKnownNonNullFromDominating
>            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<Intrinsic::experimental_guard>()) &&
> +        } else if (Pred == ICmpInst::ICMP_NE && isGuard(Curr) &&
>                     DT->dominates(cast<Instruction>(Curr), CtxI)) {
>            return true;
>          }
>
> Modified: llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp?rev=340921&r1=340920&r2=340921&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp Wed Aug 29 04:37:34 2018
> @@ -54,6 +54,7 @@
>  #include "llvm/Support/RecyclingAllocator.h"
>  #include "llvm/Support/raw_ostream.h"
>  #include "llvm/Transforms/Scalar.h"
> +#include "llvm/Transforms/Utils/GuardUtils.h"
>  #include <cassert>
>  #include <deque>
>  #include <memory>
> @@ -863,7 +864,7 @@ bool EarlyCSE::processNode(DomTreeNode *
>        continue;
>      }
>
> -    if (match(Inst, m_Intrinsic<Intrinsic::experimental_guard>())) {
> +    if (isGuard(Inst)) {
>        if (auto *CondI =
>                dyn_cast<Instruction>(cast<CallInst>(Inst)->getArgOperand(0))) {
>          if (SimpleValue::canHandle(CondI)) {
>
> Modified: llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp?rev=340921&r1=340920&r2=340921&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/GuardWidening.cpp Wed Aug 29 04:37:34 2018
> @@ -57,6 +57,7 @@
>  #include "llvm/Support/Debug.h"
>  #include "llvm/Support/KnownBits.h"
>  #include "llvm/Transforms/Scalar.h"
> +#include "llvm/Transforms/Utils/GuardUtils.h"
>  #include "llvm/Transforms/Utils/LoopUtils.h"
>
>  using namespace llvm;
> @@ -107,12 +108,6 @@ static void setCondition(Instruction *I,
>    cast<BranchInst>(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<Intrinsic::experimental_guard>());
> -}
> -
>  // Eliminates the guard instruction properly.
>  static void eliminateGuard(Instruction *GuardInst) {
>    GuardInst->eraseFromParent();
>
> Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=340921&r1=340920&r2=340921&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Wed Aug 29 04:37:34 2018
> @@ -65,6 +65,7 @@
>  #include "llvm/Transforms/Scalar.h"
>  #include "llvm/Transforms/Utils/BasicBlockUtils.h"
>  #include "llvm/Transforms/Utils/Cloning.h"
> +#include "llvm/Transforms/Utils/GuardUtils.h"
>  #include "llvm/Transforms/Utils/Local.h"
>  #include "llvm/Transforms/Utils/SSAUpdater.h"
>  #include "llvm/Transforms/Utils/ValueMapper.h"
> @@ -2607,9 +2608,8 @@ bool JumpThreadingPass::ProcessGuards(Ba
>
>    if (auto *BI = dyn_cast<BranchInst>(Parent->getTerminator()))
>      for (auto &I : *BB)
> -      if (match(&I, m_Intrinsic<Intrinsic::experimental_guard>()))
> -        if (ThreadGuard(BB, cast<IntrinsicInst>(&I), BI))
> -          return true;
> +      if (isGuard(&I) && ThreadGuard(BB, cast<IntrinsicInst>(&I), BI))
> +        return true;
>
>    return false;
>  }
>
> Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=340921&r1=340920&r2=340921&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Wed Aug 29 04:37:34 2018
> @@ -66,6 +66,7 @@
>  #include "llvm/Transforms/Scalar.h"
>  #include "llvm/Transforms/Scalar/LoopPassManager.h"
>  #include "llvm/Transforms/Utils/BasicBlockUtils.h"
> +#include "llvm/Transforms/Utils/GuardUtils.h"
>  #include "llvm/Transforms/Utils/LoopUtils.h"
>  #include "llvm/Transforms/Utils/SSAUpdater.h"
>  #include <algorithm>
> @@ -527,7 +528,7 @@ bool llvm::hoistRegion(DomTreeNode *N, A
>        using namespace PatternMatch;
>        if (((I.use_empty() &&
>              match(&I, m_Intrinsic<Intrinsic::invariant_start>())) ||
> -           match(&I, m_Intrinsic<Intrinsic::experimental_guard>())) &&
> +           isGuard(&I)) &&
>            IsMustExecute && IsMemoryNotModified &&
>            CurLoop->hasLoopInvariantOperands(&I)) {
>          hoist(I, DT, CurLoop, SafetyInfo, ORE);
>
> Modified: llvm/trunk/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp?rev=340921&r1=340920&r2=340921&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/LowerGuardIntrinsic.cpp Wed Aug 29 04:37:34 2018
> @@ -49,10 +49,8 @@ static bool lowerGuardIntrinsic(Function
>
>    SmallVector<CallInst *, 8> ToLower;
>    for (auto &I : instructions(F))
> -    if (auto *CI = dyn_cast<CallInst>(&I))
> -      if (auto *F = CI->getCalledFunction())
> -        if (F->getIntrinsicID() == Intrinsic::experimental_guard)
> -          ToLower.push_back(CI);
> +    if (isGuard(&I))
> +      ToLower.push_back(cast<CallInst>(&I));
>
>    if (ToLower.empty())
>      return false;
>
> Modified: llvm/trunk/lib/Transforms/Utils/GuardUtils.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/GuardUtils.cpp?rev=340921&r1=340920&r2=340921&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/GuardUtils.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/GuardUtils.cpp Wed Aug 29 04:37:34 2018
> @@ -15,6 +15,7 @@
>  #include "llvm/IR/Instructions.h"
>  #include "llvm/IR/IRBuilder.h"
>  #include "llvm/IR/MDBuilder.h"
> +#include "llvm/IR/PatternMatch.h"
>  #include "llvm/Transforms/Utils/BasicBlockUtils.h"
>
>  using namespace llvm;
> @@ -24,6 +25,11 @@ static cl::opt<uint32_t> PredicatePassBr
>      cl::desc("The probability of a guard failing is assumed to be the "
>               "reciprocal of this value (default = 1 << 20)"));
>
> +bool llvm::isGuard(const User *U) {
> +  using namespace llvm::PatternMatch;
> +  return match(U, m_Intrinsic<Intrinsic::experimental_guard>());
> +}
> +
>  void llvm::makeGuardControlFlowExplicit(Function *DeoptIntrinsic,
>                                          CallInst *Guard) {
>    OperandBundleDef DeoptOB(*Guard->getOperandBundle(LLVMContext::OB_deopt));
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list