diff options
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp | 19 | ||||
| -rw-r--r-- | llvm/lib/Transforms/Scalar/StructurizeCFG.cpp | 19 | 
3 files changed, 28 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp b/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp index 89980d5..a577f51 100644 --- a/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp +++ b/llvm/lib/Transforms/Scalar/DropUnnecessaryAssumes.cpp @@ -122,7 +122,8 @@ DropUnnecessaryAssumesPass::run(Function &F, FunctionAnalysisManager &FAM) {      Value *Cond = Assume->getArgOperand(0);      // Don't drop type tests, which have special semantics. -    if (match(Cond, m_Intrinsic<Intrinsic::type_test>())) +    if (match(Cond, m_Intrinsic<Intrinsic::type_test>()) || +        match(Cond, m_Intrinsic<Intrinsic::public_type_test>()))        continue;      SmallVector<Value *> Affected; diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp index bb6c879..239526e 100644 --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -337,7 +337,7 @@ static void buildPartialUnswitchConditionalBranch(  static void buildPartialInvariantUnswitchConditionalBranch(      BasicBlock &BB, ArrayRef<Value *> ToDuplicate, bool Direction,      BasicBlock &UnswitchedSucc, BasicBlock &NormalSucc, Loop &L, -    MemorySSAUpdater *MSSAU) { +    MemorySSAUpdater *MSSAU, const BranchInst &OriginalBranch) {    ValueToValueMapTy VMap;    for (auto *Val : reverse(ToDuplicate)) {      Instruction *Inst = cast<Instruction>(Val); @@ -377,8 +377,19 @@ static void buildPartialInvariantUnswitchConditionalBranch(    IRBuilder<> IRB(&BB);    IRB.SetCurrentDebugLocation(DebugLoc::getCompilerGenerated());    Value *Cond = VMap[ToDuplicate[0]]; -  IRB.CreateCondBr(Cond, Direction ? &UnswitchedSucc : &NormalSucc, -                   Direction ? &NormalSucc : &UnswitchedSucc); +  // The expectation is that ToDuplicate[0] is the condition used by the +  // OriginalBranch, case in which we can clone the profile metadata from there. +  auto *ProfData = +      !ProfcheckDisableMetadataFixes && +              ToDuplicate[0] == skipTrivialSelect(OriginalBranch.getCondition()) +          ? OriginalBranch.getMetadata(LLVMContext::MD_prof) +          : nullptr; +  auto *BR = +      IRB.CreateCondBr(Cond, Direction ? &UnswitchedSucc : &NormalSucc, +                       Direction ? &NormalSucc : &UnswitchedSucc, ProfData); +  if (!ProfData) +    setExplicitlyUnknownBranchWeightsIfProfiled(*BR, *BR->getFunction(), +                                                DEBUG_TYPE);  }  /// Rewrite the PHI nodes in an unswitched loop exit basic block. @@ -2515,7 +2526,7 @@ static void unswitchNontrivialInvariants(      // the branch in the split block.      if (PartiallyInvariant)        buildPartialInvariantUnswitchConditionalBranch( -          *SplitBB, Invariants, Direction, *ClonedPH, *LoopPH, L, MSSAU); +          *SplitBB, Invariants, Direction, *ClonedPH, *LoopPH, L, MSSAU, *BI);      else {        buildPartialUnswitchConditionalBranch(            *SplitBB, Invariants, Direction, *ClonedPH, *LoopPH, diff --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp index 5f6f66a..0a8f5ea 100644 --- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp +++ b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp @@ -558,11 +558,10 @@ void StructurizeCFG::analyzeLoops(RegionNode *N) {    } else {      // Test for successors as back edge      BasicBlock *BB = N->getNodeAs<BasicBlock>(); -    BranchInst *Term = cast<BranchInst>(BB->getTerminator()); - -    for (BasicBlock *Succ : Term->successors()) -      if (Visited.count(Succ)) -        Loops[Succ] = BB; +    if (BranchInst *Term = dyn_cast<BranchInst>(BB->getTerminator())) +      for (BasicBlock *Succ : Term->successors()) +        if (Visited.count(Succ)) +          Loops[Succ] = BB;    }  } @@ -594,7 +593,7 @@ void StructurizeCFG::gatherPredicates(RegionNode *N) {    for (BasicBlock *P : predecessors(BB)) {      // Ignore it if it's a branch from outside into our region entry -    if (!ParentRegion->contains(P)) +    if (!ParentRegion->contains(P) || !dyn_cast<BranchInst>(P->getTerminator()))        continue;      Region *R = RI->getRegionFor(P); @@ -1402,13 +1401,17 @@ bool StructurizeCFG::makeUniformRegion(Region *R, UniformityInfo &UA) {  /// Run the transformation for each region found  bool StructurizeCFG::run(Region *R, DominatorTree *DT,                           const TargetTransformInfo *TTI) { -  if (R->isTopLevelRegion()) +  // CallBr and its corresponding direct target blocks are for now ignored by +  // this pass. This is not a limitation for the currently intended uses cases +  // of callbr in the AMDGPU backend. +  // Parent and child regions are not affected by this (current) restriction. +  // See `llvm/test/Transforms/StructurizeCFG/callbr.ll` for details. +  if (R->isTopLevelRegion() || isa<CallBrInst>(R->getEntry()->getTerminator()))      return false;    this->DT = DT;    this->TTI = TTI;    Func = R->getEntry()->getParent(); -  assert(hasOnlySimpleTerminator(*Func) && "Unsupported block terminator.");    ParentRegion = R;  | 
