Hi Stephen,

It seems that while this did get pushed upstream, it's not actually
part of master or any other branch.

It appears to be the same for these:
https://github.com/llvm/llvm-project/commit/80f81325b8e8f0bed81a28dffb8eba526002f2b3
https://github.com/llvm/llvm-project/commit/24b81434a056825f4e9dd3ef06bad7a2ef34f813
https://github.com/llvm/llvm-project/commit/3191fa21be09d6e7352751f86626a2e8fb251555

I'm guessing you wanted to push them to master.

(I'll also start an llvm-dev thread about this, because it would be
good if there was a hook or something that disallowed this.)

Thanks,
Hans


On Wed, Jan 15, 2020 at 1:18 PM via llvm-branch-commits
<llvm-branch-commits@lists.llvm.org> wrote:
>
>
> Author: gbtozers
> Date: 2020-01-14T15:28:16Z
> New Revision: 6762d53b66d9de18825f09f43c3d6c2b3ea95913
>
> URL: 
> https://github.com/llvm/llvm-project/commit/6762d53b66d9de18825f09f43c3d6c2b3ea95913
> DIFF: 
> https://github.com/llvm/llvm-project/commit/6762d53b66d9de18825f09f43c3d6c2b3ea95913.diff
>
> LOG: Add RemovePureUndefs to opt
>
> Added:
>
>
> Modified:
>     llvm/include/llvm/InitializePasses.h
>     llvm/include/llvm/LinkAllPasses.h
>     llvm/include/llvm/Transforms/Scalar.h
>     llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
>     llvm/lib/Transforms/Scalar/DCE.cpp
>     llvm/lib/Transforms/Scalar/JumpThreading.cpp
>     llvm/lib/Transforms/Scalar/Scalar.cpp
>     llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
>
> Removed:
>
>
>
> ################################################################################
> diff  --git a/llvm/include/llvm/InitializePasses.h 
> b/llvm/include/llvm/InitializePasses.h
> index 831c6882b4a9..c59170da05a0 100644
> --- a/llvm/include/llvm/InitializePasses.h
> +++ b/llvm/include/llvm/InitializePasses.h
> @@ -347,6 +347,7 @@ void initializeRAGreedyPass(PassRegistry&);
>  void initializeReachingDefAnalysisPass(PassRegistry&);
>  void initializeReassociateLegacyPassPass(PassRegistry&);
>  void initializeRedundantDbgInstEliminationPass(PassRegistry&);
> +void initializePureUndefDbgInstEliminationPass(PassRegistry&);
>  void initializeRegAllocFastPass(PassRegistry&);
>  void initializeRegBankSelectPass(PassRegistry&);
>  void initializeRegToMemPass(PassRegistry&);
>
> diff  --git a/llvm/include/llvm/LinkAllPasses.h 
> b/llvm/include/llvm/LinkAllPasses.h
> index aa64296f9428..9dcf5958029e 100644
> --- a/llvm/include/llvm/LinkAllPasses.h
> +++ b/llvm/include/llvm/LinkAllPasses.h
> @@ -160,6 +160,7 @@ namespace {
>        (void) llvm::createPostDomViewerPass();
>        (void) llvm::createReassociatePass();
>        (void) llvm::createRedundantDbgInstEliminationPass();
> +      (void) llvm::createPureUndefDbgInstEliminationPass();
>        (void) llvm::createRegionInfoPass();
>        (void) llvm::createRegionOnlyPrinterPass();
>        (void) llvm::createRegionOnlyViewerPass();
>
> diff  --git a/llvm/include/llvm/Transforms/Scalar.h 
> b/llvm/include/llvm/Transforms/Scalar.h
> index 1f2842836303..85c931bb20d1 100644
> --- a/llvm/include/llvm/Transforms/Scalar.h
> +++ b/llvm/include/llvm/Transforms/Scalar.h
> @@ -60,6 +60,14 @@ Pass *createDeadInstEliminationPass();
>  //
>  Pass *createRedundantDbgInstEliminationPass();
>
> +//===----------------------------------------------------------------------===//
> +//
> +// PureUndefDbgInstElimination - This pass removes dbg intrinsics for 
> variables
> +// which are always `undef` within a function, without modifying the CFG of 
> the
> +// function.  It is a FunctionPass.
> +//
> +Pass *createPureUndefDbgInstEliminationPass();
> +
>  
> //===----------------------------------------------------------------------===//
>  //
>  // DeadCodeElimination - This pass is more powerful than DeadInstElimination,
>
> diff  --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h 
> b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
> index dec8447c9f52..2273d7d90a41 100644
> --- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
> +++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
> @@ -98,6 +98,8 @@ bool MergeBlockIntoPredecessor(BasicBlock *BB, 
> DomTreeUpdater *DTU = nullptr,
>  /// Returns true if at least one instruction was removed.
>  bool RemoveRedundantDbgInstrs(BasicBlock *BB);
>
> +bool RemovePureUndefDbgInstrs(Function &F);
> +
>  /// Replace all uses of an instruction (specified by BI) with a value, then
>  /// remove and delete the original instruction.
>  void ReplaceInstWithValue(BasicBlock::InstListType &BIL,
>
> diff  --git a/llvm/lib/Transforms/Scalar/DCE.cpp 
> b/llvm/lib/Transforms/Scalar/DCE.cpp
> index a4b0c8df98f6..716b2264eddd 100644
> --- a/llvm/lib/Transforms/Scalar/DCE.cpp
> +++ b/llvm/lib/Transforms/Scalar/DCE.cpp
> @@ -115,6 +115,36 @@ Pass *llvm::createRedundantDbgInstEliminationPass() {
>    return new RedundantDbgInstElimination();
>  }
>
> +//===--------------------------------------------------------------------===//
> +// PureUndefDbgInstElimination pass implementation
> +//
> +
> +namespace {
> +struct PureUndefDbgInstElimination : public FunctionPass {
> +  static char ID; // Pass identification, replacement for typeid
> +  PureUndefDbgInstElimination() : FunctionPass(ID) {
> +    
> initializePureUndefDbgInstEliminationPass(*PassRegistry::getPassRegistry());
> +  }
> +  bool runOnFunction(Function &F) override {
> +    if (skipFunction(F))
> +      return false;
> +    return RemovePureUndefDbgInstrs(F);
> +  }
> +
> +  void getAnalysisUsage(AnalysisUsage &AU) const override {
> +    AU.setPreservesCFG();
> +  }
> +};
> +}
> +
> +char PureUndefDbgInstElimination::ID = 0;
> +INITIALIZE_PASS(PureUndefDbgInstElimination, "pure-undef-dbg-inst-elim",
> +                "Pure Undef Dbg Instruction Elimination", false, false)
> +
> +Pass *llvm::createPureUndefDbgInstEliminationPass() {
> +  return new PureUndefDbgInstElimination();
> +}
> +
>  
> //===--------------------------------------------------------------------===//
>  // DeadCodeElimination pass implementation
>  //
>
> diff  --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp 
> b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
> index 98c2fcb3dae0..bc769f01ca21 100644
> --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
> +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
> @@ -418,17 +418,21 @@ bool JumpThreadingPass::runImpl(Function &F, 
> TargetLibraryInfo *TLI_,
>        // ProcessBlock doesn't thread BBs with unconditional TIs. However, if 
> BB
>        // is "almost empty", we attempt to merge BB with its sole successor.
>        auto *BI = dyn_cast<BranchInst>(BB.getTerminator());
> -      if (BI && BI->isUnconditional() &&
> -          // The terminator must be the only non-phi instruction in BB.
> -          BB.getFirstNonPHIOrDbg()->isTerminator() &&
> -          // Don't alter Loop headers and latches to ensure another pass can
> -          // detect and transform nested loops later.
> -          !LoopHeaders.count(&BB) && !LoopHeaders.count(BI->getSuccessor(0)) 
> &&
> -          TryToSimplifyUncondBranchFromEmptyBlock(&BB, DTU)) {
> -        // BB is valid for cleanup here because we passed in DTU. F remains
> -        // BB's parent until a DTU->getDomTree() event.
> -        LVI->eraseBlock(&BB);
> -        Changed = true;
> +      if (BI && BI->isUnconditional()) {
> +        BasicBlock *Succ = BI->getSuccessor(0);
> +        if(
> +            // The terminator must be the only non-phi instruction in BB.
> +            BB.getFirstNonPHIOrDbg()->isTerminator() &&
> +            // Don't alter Loop headers and latches to ensure another pass 
> can
> +            // detect and transform nested loops later.
> +            !LoopHeaders.count(&BB) && 
> !LoopHeaders.count(BI->getSuccessor(0)) &&
> +            TryToSimplifyUncondBranchFromEmptyBlock(&BB, DTU)) {
> +          // BB is valid for cleanup here because we passed in DTU. F remains
> +          // BB's parent until a DTU->getDomTree() event.
> +          RemoveRedundantDbgInstrs(Succ);
> +          LVI->eraseBlock(&BB);
> +          Changed = true;
> +        }
>        }
>      }
>      EverChanged |= Changed;
>
> diff  --git a/llvm/lib/Transforms/Scalar/Scalar.cpp 
> b/llvm/lib/Transforms/Scalar/Scalar.cpp
> index 9d088547b436..b0d38ab82874 100644
> --- a/llvm/lib/Transforms/Scalar/Scalar.cpp
> +++ b/llvm/lib/Transforms/Scalar/Scalar.cpp
> @@ -91,6 +91,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
>    initializePartiallyInlineLibCallsLegacyPassPass(Registry);
>    initializeReassociateLegacyPassPass(Registry);
>    initializeRedundantDbgInstEliminationPass(Registry);
> +  initializePureUndefDbgInstEliminationPass(Registry);
>    initializeRegToMemPass(Registry);
>    initializeRewriteStatepointsForGCLegacyPassPass(Registry);
>    initializeSCCPLegacyPassPass(Registry);
>
> diff  --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp 
> b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
> index c9eb4abfa21a..c9e34c39d830 100644
> --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
> +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
> @@ -314,6 +314,40 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, 
> DomTreeUpdater *DTU,
>    return true;
>  }
>
> +bool llvm::RemovePureUndefDbgInstrs(Function &F) {
> +  DenseMap<DebugVariable, SmallVector<DbgValueInst *, 8> > VariableMap;
> +  DenseSet<DebugVariable> NonUndefVariables;
> +
> +  for (auto &BB : F) {
> +    for (auto &I : BB) {
> +      if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(&I)) {
> +        DebugVariable Key(DVI->getVariable(),
> +                          DVI->getExpression(),
> +                          DVI->getDebugLoc()->getInlinedAt());
> +        if (NonUndefVariables.count(Key))
> +          continue;
> +        if (DVI->getValue() == UndefValue::get(DVI->getValue()->getType())) {
> +          auto R = VariableMap.insert(
> +            { Key, SmallVector<DbgValueInst *, 8>(1, DVI) });
> +          if (!R.second) {
> +            auto VMI = R.first;
> +            VMI->second.push_back(DVI);
> +          }
> +        } else {
> +          NonUndefVariables.insert(Key);
> +          VariableMap.erase(Key);
> +        }
> +      }
> +    }
> +  }
> +
> +  for (auto VariableMapping : VariableMap)
> +    for (auto &Instr : VariableMapping.second)
> +      Instr->eraseFromParent();
> +
> +  return VariableMap.size() > 0;
> +}
> +
>  /// Remove redundant instructions within sequences of consecutive dbg.value
>  /// instructions. This is done using a backward scan to keep the last 
> dbg.value
>  /// describing a specific variable/fragment.
>
>
>
> _______________________________________________
> llvm-branch-commits mailing list
> llvm-branch-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to