llvm.org GIT mirror llvm / f940a1a
Remove the old tail duplication pass. It is not used and is unable to update ssa, so it has to be run really early in the pipeline. Any replacement should probably use the SSAUpdater. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138841 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 8 years ago
21 changed file(s) with 4 addition(s) and 645 deletion(s). Raw diff Collapse all Expand all
582582
583583
  • The LowerSetJmp pass wasn't used effectively by any
  • 584584 target and has been removed.
    585
  • The old TailDup pass was not used in the standard pipeline
  • 586 and was unable to update ssa form, so it has been removed.
    585587
  • The syntax of volatile loads and stores in IR has been changed to
  • 586588 "load volatile"/"store volatile". The old
    587589 syntax ("volatile load"/"volatile store")
    218218 void initializeStripSymbolsPass(PassRegistry&);
    219219 void initializeStrongPHIEliminationPass(PassRegistry&);
    220220 void initializeTailCallElimPass(PassRegistry&);
    221 void initializeTailDupPass(PassRegistry&);
    222221 void initializeTargetDataPass(PassRegistry&);
    223222 void initializeTargetLibraryInfoPass(PassRegistry&);
    224223 void initializeTwoAddressInstructionPassPass(PassRegistry&);
    126126 (void) llvm::createStripDeadDebugInfoPass();
    127127 (void) llvm::createStripDeadPrototypesPass();
    128128 (void) llvm::createTailCallEliminationPass();
    129 (void) llvm::createTailDuplicationPass();
    130129 (void) llvm::createJumpThreadingPass();
    131130 (void) llvm::createUnifyFunctionExitNodesPass();
    132131 (void) llvm::createInstCountPass();
    172172 // For example: 4 + (x + 5) -> x + (4 + 5)
    173173 //
    174174 FunctionPass *createReassociatePass();
    175
    176 //===----------------------------------------------------------------------===//
    177 //
    178 // TailDuplication - Eliminate unconditional branches through controlled code
    179 // duplication, creating simpler CFG structures.
    180 //
    181 FunctionPass *createTailDuplicationPass();
    182175
    183176 //===----------------------------------------------------------------------===//
    184177 //
    2828 SimplifyCFGPass.cpp
    2929 SimplifyLibCalls.cpp
    3030 Sink.cpp
    31 TailDuplication.cpp
    3231 TailRecursionElimination.cpp
    3332 )
    3433
    6262 initializeCFGSimplifyPassPass(Registry);
    6363 initializeSimplifyLibCallsPass(Registry);
    6464 initializeSinkingPass(Registry);
    65 initializeTailDupPass(Registry);
    6665 initializeTailCallElimPass(Registry);
    6766 }
    6867
    +0
    -373
    lib/Transforms/Scalar/TailDuplication.cpp less more
    None //===- TailDuplication.cpp - Simplify CFG through tail duplication --------===//
    1 //
    2 // The LLVM Compiler Infrastructure
    3 //
    4 // This file is distributed under the University of Illinois Open Source
    5 // License. See LICENSE.TXT for details.
    6 //
    7 //===----------------------------------------------------------------------===//
    8 //
    9 // This pass performs a limited form of tail duplication, intended to simplify
    10 // CFGs by removing some unconditional branches. This pass is necessary to
    11 // straighten out loops created by the C front-end, but also is capable of
    12 // making other code nicer. After this pass is run, the CFG simplify pass
    13 // should be run to clean up the mess.
    14 //
    15 // This pass could be enhanced in the future to use profile information to be
    16 // more aggressive.
    17 //
    18 //===----------------------------------------------------------------------===//
    19
    20 #define DEBUG_TYPE "tailduplicate"
    21 #include "llvm/Transforms/Scalar.h"
    22 #include "llvm/Constant.h"
    23 #include "llvm/Function.h"
    24 #include "llvm/Instructions.h"
    25 #include "llvm/IntrinsicInst.h"
    26 #include "llvm/Pass.h"
    27 #include "llvm/Type.h"
    28 #include "llvm/ADT/Statistic.h"
    29 #include "llvm/ADT/SmallPtrSet.h"
    30 #include "llvm/Analysis/InstructionSimplify.h"
    31 #include "llvm/Support/CFG.h"
    32 #include "llvm/Support/CommandLine.h"
    33 #include "llvm/Support/Debug.h"
    34 #include "llvm/Support/raw_ostream.h"
    35 #include "llvm/Transforms/Utils/Local.h"
    36 #include
    37 using namespace llvm;
    38
    39 STATISTIC(NumEliminated, "Number of unconditional branches eliminated");
    40
    41 static cl::opt
    42 TailDupThreshold("taildup-threshold",
    43 cl::desc("Max block size to tail duplicate"),
    44 cl::init(1), cl::Hidden);
    45
    46 namespace {
    47 class TailDup : public FunctionPass {
    48 bool runOnFunction(Function &F);
    49 public:
    50 static char ID; // Pass identification, replacement for typeid
    51 TailDup() : FunctionPass(ID) {
    52 initializeTailDupPass(*PassRegistry::getPassRegistry());
    53 }
    54
    55 private:
    56 inline bool shouldEliminateUnconditionalBranch(TerminatorInst *, unsigned);
    57 inline void eliminateUnconditionalBranch(BranchInst *BI);
    58 SmallPtrSet CycleDetector;
    59 };
    60 }
    61
    62 char TailDup::ID = 0;
    63 INITIALIZE_PASS(TailDup, "tailduplicate", "Tail Duplication", false, false)
    64
    65 // Public interface to the Tail Duplication pass
    66 FunctionPass *llvm::createTailDuplicationPass() { return new TailDup(); }
    67
    68 /// runOnFunction - Top level algorithm - Loop over each unconditional branch in
    69 /// the function, eliminating it if it looks attractive enough. CycleDetector
    70 /// prevents infinite loops by checking that we aren't redirecting a branch to
    71 /// a place it already pointed to earlier; see PR 2323.
    72 bool TailDup::runOnFunction(Function &F) {
    73 bool Changed = false;
    74 CycleDetector.clear();
    75 for (Function::iterator I = F.begin(), E = F.end(); I != E; ) {
    76 if (shouldEliminateUnconditionalBranch(I->getTerminator(),
    77 TailDupThreshold)) {
    78 eliminateUnconditionalBranch(cast(I->getTerminator()));
    79 Changed = true;
    80 } else {
    81 ++I;
    82 CycleDetector.clear();
    83 }
    84 }
    85 return Changed;
    86 }
    87
    88 /// shouldEliminateUnconditionalBranch - Return true if this branch looks
    89 /// attractive to eliminate. We eliminate the branch if the destination basic
    90 /// block has <= 5 instructions in it, not counting PHI nodes. In practice,
    91 /// since one of these is a terminator instruction, this means that we will add
    92 /// up to 4 instructions to the new block.
    93 ///
    94 /// We don't count PHI nodes in the count since they will be removed when the
    95 /// contents of the block are copied over.
    96 ///
    97 bool TailDup::shouldEliminateUnconditionalBranch(TerminatorInst *TI,
    98 unsigned Threshold) {
    99 BranchInst *BI = dyn_cast(TI);
    100 if (!BI || !BI->isUnconditional()) return false; // Not an uncond branch!
    101
    102 BasicBlock *Dest = BI->getSuccessor(0);
    103 if (Dest == BI->getParent()) return false; // Do not loop infinitely!
    104
    105 // Do not inline a block if we will just get another branch to the same block!
    106 TerminatorInst *DTI = Dest->getTerminator();
    107 if (BranchInst *DBI = dyn_cast(DTI))
    108 if (DBI->isUnconditional() && DBI->getSuccessor(0) == Dest)
    109 return false; // Do not loop infinitely!
    110
    111 // FIXME: DemoteRegToStack cannot yet demote invoke instructions to the stack,
    112 // because doing so would require breaking critical edges. This should be
    113 // fixed eventually.
    114 if (!DTI->use_empty())
    115 return false;
    116
    117 // Do not bother with blocks with only a single predecessor: simplify
    118 // CFG will fold these two blocks together!
    119 pred_iterator PI = pred_begin(Dest), PE = pred_end(Dest);
    120 ++PI;
    121 if (PI == PE) return false; // Exactly one predecessor!
    122
    123 BasicBlock::iterator I = Dest->getFirstNonPHI();
    124
    125 for (unsigned Size = 0; I != Dest->end(); ++I) {
    126 if (Size == Threshold) return false; // The block is too large.
    127
    128 // Don't tail duplicate call instructions. They are very large compared to
    129 // other instructions.
    130 if (isa(I) || isa(I)) return false;
    131
    132 // Also alloca and malloc.
    133 if (isa(I)) return false;
    134
    135 // Some vector instructions can expand into a number of instructions.
    136 if (isa(I) || isa(I) ||
    137 isa(I)) return false;
    138
    139 // Only count instructions that are not debugger intrinsics.
    140 if (!isa(I)) ++Size;
    141 }
    142
    143 // Do not tail duplicate a block that has thousands of successors into a block
    144 // with a single successor if the block has many other predecessors. This can
    145 // cause an N^2 explosion in CFG edges (and PHI node entries), as seen in
    146 // cases that have a large number of indirect gotos.
    147 unsigned NumSuccs = DTI->getNumSuccessors();
    148 if (NumSuccs > 8) {
    149 unsigned TooMany = 128;
    150 if (NumSuccs >= TooMany) return false;
    151 TooMany = TooMany/NumSuccs;
    152 for (; PI != PE; ++PI)
    153 if (TooMany-- == 0) return false;
    154 }
    155
    156 // If this unconditional branch is a fall-through, be careful about
    157 // tail duplicating it. In particular, we don't want to taildup it if the
    158 // original block will still be there after taildup is completed: doing so
    159 // would eliminate the fall-through, requiring unconditional branches.
    160 Function::iterator DestI = Dest;
    161 if (&*--DestI == BI->getParent()) {
    162 // The uncond branch is a fall-through. Tail duplication of the block is
    163 // will eliminate the fall-through-ness and end up cloning the terminator
    164 // at the end of the Dest block. Since the original Dest block will
    165 // continue to exist, this means that one or the other will not be able to
    166 // fall through. One typical example that this helps with is code like:
    167 // if (a)
    168 // foo();
    169 // if (b)
    170 // foo();
    171 // Cloning the 'if b' block into the end of the first foo block is messy.
    172
    173 // The messy case is when the fall-through block falls through to other
    174 // blocks. This is what we would be preventing if we cloned the block.
    175 DestI = Dest;
    176 if (++DestI != Dest->getParent()->end()) {
    177 BasicBlock *DestSucc = DestI;
    178 // If any of Dest's successors are fall-throughs, don't do this xform.
    179 for (succ_iterator SI = succ_begin(Dest), SE = succ_end(Dest);
    180 SI != SE; ++SI)
    181 if (*SI == DestSucc)
    182 return false;
    183 }
    184 }
    185
    186 // Finally, check that we haven't redirected to this target block earlier;
    187 // there are cases where we loop forever if we don't check this (PR 2323).
    188 if (!CycleDetector.insert(Dest))
    189 return false;
    190
    191 return true;
    192 }
    193
    194 /// FindObviousSharedDomOf - We know there is a branch from SrcBlock to
    195 /// DestBlock, and that SrcBlock is not the only predecessor of DstBlock. If we
    196 /// can find a predecessor of SrcBlock that is a dominator of both SrcBlock and
    197 /// DstBlock, return it.
    198 static BasicBlock *FindObviousSharedDomOf(BasicBlock *SrcBlock,
    199 BasicBlock *DstBlock) {
    200 // SrcBlock must have a single predecessor.
    201 pred_iterator PI = pred_begin(SrcBlock), PE = pred_end(SrcBlock);
    202 if (PI == PE || ++PI != PE) return 0;
    203
    204 BasicBlock *SrcPred = *pred_begin(SrcBlock);
    205
    206 // Look at the predecessors of DstBlock. One of them will be SrcBlock. If
    207 // there is only one other pred, get it, otherwise we can't handle it.
    208 PI = pred_begin(DstBlock); PE = pred_end(DstBlock);
    209 BasicBlock *DstOtherPred = 0;
    210 BasicBlock *P = *PI;
    211 if (P == SrcBlock) {
    212 if (++PI == PE) return 0;
    213 DstOtherPred = *PI;
    214 if (++PI != PE) return 0;
    215 } else {
    216 DstOtherPred = P;
    217 if (++PI == PE || *PI != SrcBlock || ++PI != PE) return 0;
    218 }
    219
    220 // We can handle two situations here: "if then" and "if then else" blocks. An
    221 // 'if then' situation is just where DstOtherPred == SrcPred.
    222 if (DstOtherPred == SrcPred)
    223 return SrcPred;
    224
    225 // Check to see if we have an "if then else" situation, which means that
    226 // DstOtherPred will have a single predecessor and it will be SrcPred.
    227 PI = pred_begin(DstOtherPred); PE = pred_end(DstOtherPred);
    228 if (PI != PE && *PI == SrcPred) {
    229 if (++PI != PE) return 0; // Not a single pred.
    230 return SrcPred; // Otherwise, it's an "if then" situation. Return the if.
    231 }
    232
    233 // Otherwise, this is something we can't handle.
    234 return 0;
    235 }
    236
    237
    238 /// eliminateUnconditionalBranch - Clone the instructions from the destination
    239 /// block into the source block, eliminating the specified unconditional branch.
    240 /// If the destination block defines values used by successors of the dest
    241 /// block, we may need to insert PHI nodes.
    242 ///
    243 void TailDup::eliminateUnconditionalBranch(BranchInst *Branch) {
    244 BasicBlock *SourceBlock = Branch->getParent();
    245 BasicBlock *DestBlock = Branch->getSuccessor(0);
    246 assert(SourceBlock != DestBlock && "Our predicate is broken!");
    247
    248 DEBUG(dbgs() << "TailDuplication[" << SourceBlock->getParent()->getName()
    249 << "]: Eliminating branch: " << *Branch);
    250
    251 // See if we can avoid duplicating code by moving it up to a dominator of both
    252 // blocks.
    253 if (BasicBlock *DomBlock = FindObviousSharedDomOf(SourceBlock, DestBlock)) {
    254 DEBUG(dbgs() << "Found shared dominator: " << DomBlock->getName() << "\n");
    255
    256 // If there are non-phi instructions in DestBlock that have no operands
    257 // defined in DestBlock, and if the instruction has no side effects, we can
    258 // move the instruction to DomBlock instead of duplicating it.
    259 BasicBlock::iterator BBI = DestBlock->getFirstNonPHI();
    260 while (!isa(BBI)) {
    261 Instruction *I = BBI++;
    262
    263 bool CanHoist = I->isSafeToSpeculativelyExecute() &&
    264 !I->mayReadFromMemory();
    265 if (CanHoist) {
    266 for (unsigned op = 0, e = I->getNumOperands(); op != e; ++op)
    267 if (Instruction *OpI = dyn_cast(I->getOperand(op)))
    268 if (OpI->getParent() == DestBlock ||
    269 (isa(OpI) && OpI->getParent() == DomBlock)) {
    270 CanHoist = false;
    271 break;
    272 }
    273 if (CanHoist) {
    274 // Remove from DestBlock, move right before the term in DomBlock.
    275 DestBlock->getInstList().remove(I);
    276 DomBlock->getInstList().insert(DomBlock->getTerminator(), I);
    277 DEBUG(dbgs() << "Hoisted: " << *I);
    278 }
    279 }
    280 }
    281 }
    282
    283 // Tail duplication can not update SSA properties correctly if the values
    284 // defined in the duplicated tail are used outside of the tail itself. For
    285 // this reason, we spill all values that are used outside of the tail to the
    286 // stack.
    287 for (BasicBlock::iterator I = DestBlock->begin(); I != DestBlock->end(); ++I)
    288 if (I->isUsedOutsideOfBlock(DestBlock)) {
    289 // We found a use outside of the tail. Create a new stack slot to
    290 // break this inter-block usage pattern.
    291 DemoteRegToStack(*I);
    292 }
    293
    294 // We are going to have to map operands from the original block B to the new
    295 // copy of the block B'. If there are PHI nodes in the DestBlock, these PHI
    296 // nodes also define part of this mapping. Loop over these PHI nodes, adding
    297 // them to our mapping.
    298 //
    299 std::map ValueMapping;
    300
    301 BasicBlock::iterator BI = DestBlock->begin();
    302 bool HadPHINodes = isa(BI);
    303 for (; PHINode *PN = dyn_cast(BI); ++BI)
    304 ValueMapping[PN] = PN->getIncomingValueForBlock(SourceBlock);
    305
    306 // Clone the non-phi instructions of the dest block into the source block,
    307 // keeping track of the mapping...
    308 //
    309 for (; BI != DestBlock->end(); ++BI) {
    310 Instruction *New = BI->clone();
    311 New->setName(BI->getName());
    312 SourceBlock->getInstList().push_back(New);
    313 ValueMapping[BI] = New;
    314 }
    315
    316 // Now that we have built the mapping information and cloned all of the
    317 // instructions (giving us a new terminator, among other things), walk the new
    318 // instructions, rewriting references of old instructions to use new
    319 // instructions.
    320 //
    321 BI = Branch; ++BI; // Get an iterator to the first new instruction
    322 for (; BI != SourceBlock->end(); ++BI)
    323 for (unsigned i = 0, e = BI->getNumOperands(); i != e; ++i) {
    324 std::map::const_iterator I =
    325 ValueMapping.find(BI->getOperand(i));
    326 if (I != ValueMapping.end())
    327 BI->setOperand(i, I->second);
    328 }
    329
    330 // Next we check to see if any of the successors of DestBlock had PHI nodes.
    331 // If so, we need to add entries to the PHI nodes for SourceBlock now.
    332 for (succ_iterator SI = succ_begin(DestBlock), SE = succ_end(DestBlock);
    333 SI != SE; ++SI) {
    334 BasicBlock *Succ = *SI;
    335 for (BasicBlock::iterator PNI = Succ->begin(); isa(PNI); ++PNI) {
    336 PHINode *PN = cast(PNI);
    337 // Ok, we have a PHI node. Figure out what the incoming value was for the
    338 // DestBlock.
    339 Value *IV = PN->getIncomingValueForBlock(DestBlock);
    340
    341 // Remap the value if necessary...
    342 std::map::const_iterator I = ValueMapping.find(IV);
    343 if (I != ValueMapping.end())
    344 IV = I->second;
    345 PN->addIncoming(IV, SourceBlock);
    346 }
    347 }
    348
    349 // Next, remove the old branch instruction, and any PHI node entries that we
    350 // had.
    351 BI = Branch; ++BI; // Get an iterator to the first new instruction
    352 DestBlock->removePredecessor(SourceBlock); // Remove entries in PHI nodes...
    353 SourceBlock->getInstList().erase(Branch); // Destroy the uncond branch...
    354
    355 // Final step: now that we have finished everything up, walk the cloned
    356 // instructions one last time, constant propagating and DCE'ing them, because
    357 // they may not be needed anymore.
    358 //
    359 if (HadPHINodes) {
    360 while (BI != SourceBlock->end()) {
    361 Instruction *Inst = BI++;
    362 if (isInstructionTriviallyDead(Inst))
    363 Inst->eraseFromParent();
    364 else if (Value *V = SimplifyInstruction(Inst)) {
    365 Inst->replaceAllUsesWith(V);
    366 Inst->eraseFromParent();
    367 }
    368 }
    369 }
    370
    371 ++NumEliminated; // We just killed a branch!
    372 }
    None ; RUN: opt < %s -inline -tailduplicate -instcombine -jump-threading -licm -loop-unswitch -instcombine -indvars -loop-deletion -gvn -simplifycfg -verify -disable-output
    0 ; RUN: opt < %s -inline -instcombine -jump-threading -licm -loop-unswitch -instcombine -indvars -loop-deletion -gvn -simplifycfg -verify -disable-output
    11
    22 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
    33 target triple = "i386-apple-darwin9"
    None ; RUN: opt < %s -tailduplicate -instcombine -simplifycfg -licm -disable-output
    0 ; RUN: opt < %s -instcombine -simplifycfg -licm -disable-output
    11 target datalayout = "e-p:32:32"
    22 @yy_base = external global [787 x i16] ; <[787 x i16]*> [#uses=1]
    33 @yy_state_ptr = external global i32* ; [#uses=3]
    +0
    -15
    test/Transforms/TailDup/2003-06-24-Simpleloop.ll less more
    None ; RUN: opt < %s -tailduplicate -disable-output
    1
    2 define void @motion_result7() {
    3 entry:
    4 br label %endif
    5 endif: ; preds = %no_exit, %entry
    6 %i.1 = phi i32 [ %inc, %no_exit ], [ 0, %entry ] ; [#uses=1]
    7 %inc = add i32 %i.1, 1 ; [#uses=1]
    8 br i1 false, label %no_exit, label %UnifiedExitNode
    9 no_exit: ; preds = %endif
    10 br i1 false, label %UnifiedExitNode, label %endif
    11 UnifiedExitNode: ; preds = %no_exit, %endif
    12 ret void
    13 }
    14
    +0
    -11
    test/Transforms/TailDup/2003-07-22-InfiniteLoop.ll less more
    None ; RUN: opt < %s -tailduplicate -disable-output
    1
    2 define i32 @sum() {
    3 entry:
    4 br label %loopentry
    5 loopentry: ; preds = %loopentry, %entry
    6 %i.0 = phi i32 [ 1, %entry ], [ %tmp.3, %loopentry ] ; [#uses=1]
    7 %tmp.3 = add i32 %i.0, 1 ; [#uses=1]
    8 br label %loopentry
    9 }
    10
    +0
    -29
    test/Transforms/TailDup/2003-08-23-InvalidatedPointers.ll less more
    None ; RUN: opt < %s -tailduplicate -disable-output
    1
    2 define i32 @sell_haggle() {
    3 entry:
    4 br i1 false, label %then.5, label %UnifiedExitNode
    5 then.5: ; preds = %entry
    6 br i1 false, label %loopentry.1.preheader, label %else.1
    7 else.1: ; preds = %then.5
    8 br label %loopentry.1.preheader
    9 loopentry.1.preheader: ; preds = %else.1, %then.5
    10 %final_ask.0 = phi i32 [ 0, %else.1 ], [ 0, %then.5 ] ; [#uses=2]
    11 br label %loopentry.1
    12 loopentry.1: ; preds = %endif.17, %loopentry.1.preheader
    13 switch i32 0, label %UnifiedExitNode [
    14 i32 2, label %UnifiedExitNode
    15 i32 1, label %endif.16
    16 ]
    17 endif.16: ; preds = %loopentry.1
    18 br i1 false, label %then.17, label %UnifiedExitNode
    19 then.17: ; preds = %endif.16
    20 br i1 false, label %then.18, label %endif.17
    21 then.18: ; preds = %then.17
    22 br i1 false, label %endif.17, label %UnifiedExitNode
    23 endif.17: ; preds = %then.18, %then.17
    24 %cur_ask.3 = phi i32 [ %final_ask.0, %then.17 ], [ %final_ask.0, %then.18 ] ; [#uses=0]
    25 br i1 false, label %loopentry.1, label %UnifiedExitNode
    26 UnifiedExitNode: ; preds = %endif.17, %then.18, %endif.16, %loopentry.1, %loopentry.1, %entry
    27 ret i32 0
    28 }
    +0
    -17
    test/Transforms/TailDup/2003-08-31-UnreachableBlocks.ll less more
    None ; RUN: opt < %s -tailduplicate -disable-output
    1
    2 define i32 @foo() {
    3 entry:
    4 br label %return.i
    5 after_ret.i: ; No predecessors!
    6 br label %return.i
    7 return.i: ; preds = %after_ret.i, %entry
    8 %tmp.3 = ptrtoint i32* null to i32 ; [#uses=1]
    9 br label %return.i1
    10 after_ret.i1: ; No predecessors!
    11 br label %return.i1
    12 return.i1: ; preds = %after_ret.i1, %return.i
    13 %tmp.8 = sub i32 %tmp.3, 0 ; [#uses=0]
    14 ret i32 0
    15 }
    16
    +0
    -20
    test/Transforms/TailDup/2004-04-01-DemoteRegToStack.ll less more
    None ; RUN: opt < %s -tailduplicate -disable-output
    1
    2 define void @interpret() {
    3 entry:
    4 br label %retry
    5 retry: ; preds = %endif.4, %entry
    6 %tmp.8 = call i32 @interp( ) ; [#uses=3]
    7 switch i32 0, label %endif.4 [
    8 i32 -25, label %return
    9 i32 -16, label %return
    10 ]
    11 endif.4: ; preds = %retry
    12 br i1 false, label %return, label %retry
    13 return: ; preds = %endif.4, %retry, %retry
    14 %result.0 = phi i32 [ %tmp.8, %retry ], [ %tmp.8, %retry ], [ %tmp.8, %endif.4 ] ; [#uses=0]
    15 ret void
    16 }
    17
    18 declare i32 @interp()
    19
    +0
    -26
    test/Transforms/TailDup/2008-05-13-InfiniteLoop.ll less more
    None ; RUN: opt < %s -tailduplicate | llc
    1 ; PR2323
    2
    3 define i32 @func_27(i32 %p_28) nounwind {
    4 entry:
    5 %tmp125 = trunc i32 %p_28 to i8 ; [#uses=1]
    6 %tmp5.i = icmp eq i8 %tmp125, 0 ; [#uses=1]
    7 br i1 %tmp5.i, label %bb8.i, label %bb.i
    8
    9 bb.i: ; preds = %entry
    10 br label %bb39.i
    11
    12 bb8.i: ; preds = %entry
    13 br label %bb11.i
    14
    15 bb11.i: ; preds = %bb39.i, %bb8.i
    16 %tmp126 = trunc i32 %p_28 to i8 ; [#uses=1]
    17 br label %bb39.i
    18
    19 bb39.i: ; preds = %bb11.i, %bb.i
    20 %tmp127 = trunc i32 %p_28 to i8 ; [#uses=1]
    21 br label %bb11.i
    22
    23 func_29.exit: ; No predecessors!
    24 ret i32 undef
    25 }
    +0
    -14
    test/Transforms/TailDup/2009-07-31-phicrash.ll less more
    None ; RUN: opt < %s -tailduplicate -disable-output
    1 ; PR4662
    2
    3 define void @a() {
    4 BB:
    5 br label %BB6
    6
    7 BB6:
    8 %tmp9 = phi i64 [ 0, %BB ], [ 5, %BB34 ]
    9 br label %BB34
    10
    11 BB34:
    12 br label %BB6
    13 }
    +0
    -27
    test/Transforms/TailDup/MergeTest.ll less more
    None ; RUN: opt < %s -tailduplicate -taildup-threshold=2 -S | grep add | not grep uses=1
    1
    2 define i32 @test1(i1 %C, i32 %A, i32* %P) {
    3 entry:
    4 br i1 %C, label %L1, label %L2
    5 L1: ; preds = %entry
    6 store i32 1, i32* %P
    7 br label %L2
    8 L2: ; preds = %L1, %entry
    9 %X = add i32 %A, 17 ; [#uses=1]
    10 ret i32 %X
    11 }
    12
    13 define i32 @test2(i1 %C, i32 %A, i32* %P) {
    14 entry:
    15 br i1 %C, label %L1, label %L2
    16 L1: ; preds = %entry
    17 store i32 1, i32* %P
    18 br label %L3
    19 L2: ; preds = %entry
    20 store i32 7, i32* %P
    21 br label %L3
    22 L3: ; preds = %L2, %L1
    23 %X = add i32 %A, 17 ; [#uses=1]
    24 ret i32 %X
    25 }
    26
    +0
    -16
    test/Transforms/TailDup/PHIUpdateTest.ll less more
    None ; This test checks to make sure phi nodes are updated properly
    1 ;
    2 ; RUN: opt < %s -tailduplicate -disable-output
    3
    4 define i32 @test(i1 %c, i32 %X, i32 %Y) {
    5 br label %L
    6 L: ; preds = %F, %0
    7 %A = add i32 %X, %Y ; [#uses=1]
    8 br i1 %c, label %T, label %F
    9 F: ; preds = %L
    10 br i1 %c, label %L, label %T
    11 T: ; preds = %F, %L
    12 %V = phi i32 [ %A, %L ], [ 0, %F ] ; [#uses=1]
    13 ret i32 %V
    14 }
    15
    +0
    -49
    test/Transforms/TailDup/X86/if-tail-dup.ll less more
    None ; RUN: opt < %s -tailduplicate | \
    1 ; RUN: llc -march=x86 -o %t
    2 ; RUN: grep {\\\} %t
    3 ; RUN: not grep jmp %t
    4 ; END.
    5 ; This should have no unconditional jumps in it. The C source is:
    6
    7 ;void foo(int c, int* P) {
    8 ; if (c & 1) P[0] = 1;
    9 ; if (c & 2) P[1] = 1;
    10 ; if (c & 4) P[2] = 1;
    11 ; if (c & 8) P[3] = 1;
    12 ;}
    13
    14 define void @foo(i32 %c, i32* %P) {
    15 entry:
    16 %tmp1 = and i32 %c, 1 ; [#uses=1]
    17 %tmp1.upgrd.1 = icmp eq i32 %tmp1, 0 ; [#uses=1]
    18 br i1 %tmp1.upgrd.1, label %cond_next, label %cond_true
    19 cond_true: ; preds = %entry
    20 store i32 1, i32* %P
    21 br label %cond_next
    22 cond_next: ; preds = %cond_true, %entry
    23 %tmp5 = and i32 %c, 2 ; [#uses=1]
    24 %tmp5.upgrd.2 = icmp eq i32 %tmp5, 0 ; [#uses=1]
    25 br i1 %tmp5.upgrd.2, label %cond_next10, label %cond_true6
    26 cond_true6: ; preds = %cond_next
    27 %tmp8 = getelementptr i32* %P, i32 1 ; [#uses=1]
    28 store i32 1, i32* %tmp8
    29 br label %cond_next10
    30 cond_next10: ; preds = %cond_true6, %cond_next
    31 %tmp13 = and i32 %c, 4 ; [#uses=1]
    32 %tmp13.upgrd.3 = icmp eq i32 %tmp13, 0 ; [#uses=1]
    33 br i1 %tmp13.upgrd.3, label %cond_next18, label %cond_true14
    34 cond_true14: ; preds = %cond_next10
    35 %tmp16 = getelementptr i32* %P, i32 2 ; [#uses=1]
    36 store i32 1, i32* %tmp16
    37 br label %cond_next18
    38 cond_next18: ; preds = %cond_true14, %cond_next10
    39 %tmp21 = and i32 %c, 8 ; [#uses=1]
    40 %tmp21.upgrd.4 = icmp eq i32 %tmp21, 0 ; [#uses=1]
    41 br i1 %tmp21.upgrd.4, label %return, label %cond_true22
    42 cond_true22: ; preds = %cond_next18
    43 %tmp24 = getelementptr i32* %P, i32 3 ; [#uses=1]
    44 store i32 1, i32* %tmp24
    45 ret void
    46 return: ; preds = %cond_next18
    47 ret void
    48 }
    +0
    -20
    test/Transforms/TailDup/basictest.ll less more
    None ; RUN: opt < %s -tailduplicate -disable-output
    1
    2 declare void @__main()
    3
    4 define i32 @main() {
    5 entry:
    6 call void @__main( )
    7 br label %loopentry
    8 loopentry: ; preds = %no_exit, %entry
    9 %i.0 = phi i32 [ %inc, %no_exit ], [ 0, %entry ] ; [#uses=3]
    10 %tmp.1 = icmp sle i32 %i.0, 99 ; [#uses=1]
    11 br i1 %tmp.1, label %no_exit, label %return
    12 no_exit: ; preds = %loopentry
    13 %tmp.51 = call i32 @main( ) ; [#uses=0]
    14 %inc = add i32 %i.0, 1 ; [#uses=1]
    15 br label %loopentry
    16 return: ; preds = %loopentry
    17 ret i32 %i.0
    18 }
    19
    +0
    -15
    test/Transforms/TailDup/basictest2.ll less more
    None ; RUN: opt < %s -tailduplicate -disable-output
    1
    2 define void @ab() {
    3 entry:
    4 br label %loopentry.5
    5 loopentry.5: ; preds = %no_exit.5, %entry
    6 %poscnt.1 = phi i64 [ 0, %entry ], [ %tmp.289, %no_exit.5 ] ; [#uses=1]
    7 %tmp.289 = ashr i64 %poscnt.1, 1 ; [#uses=1]
    8 br i1 false, label %no_exit.5, label %loopexit.5
    9 no_exit.5: ; preds = %loopentry.5
    10 br label %loopentry.5
    11 loopexit.5: ; preds = %loopentry.5
    12 ret void
    13 }
    14