Skip to content

Commit 3dc6742

Browse files
authored
Revert "Fix RemoveUnstructuredLoopExits when an exiting edge jumps out multiple levels of loops. (microsoft#6668)" (microsoft#6685)
This reverts commit 8206fbd. Reason for revert: since landing this, new asserts/crashes have been found.
1 parent 40c76f7 commit 3dc6742

File tree

6 files changed

+0
-663
lines changed

6 files changed

+0
-663
lines changed

lib/Transforms/Scalar/DxilRemoveUnstructuredLoopExits.cpp

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,10 @@
130130
#include "llvm/IR/Constant.h"
131131
#include "llvm/IR/Instructions.h"
132132
#include "llvm/IR/IntrinsicInst.h"
133-
#include "llvm/IR/Module.h"
134133
#include "llvm/IR/Verifier.h"
135134
#include "llvm/Support/Debug.h"
136135
#include "llvm/Support/raw_ostream.h"
137136
#include "llvm/Transforms/Scalar.h"
138-
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
139137
#include "llvm/Transforms/Utils/Local.h"
140138
#include "llvm/Transforms/Utils/LoopUtils.h"
141139

@@ -458,79 +456,6 @@ static SmallVector<Value_Info, 8> CollectExitValues(Value *new_exit_cond,
458456
return exit_values;
459457
}
460458

461-
// Ensures the branch from exiting_block to outside L escapes exactly one
462-
// level of loop nesting, and does not immediately jump into an otherwise
463-
// unrelated loop. Creates a downstream block as needed. If the exiting edge is
464-
// critical, it will be split. Updates dominator tree and loop info. Returns
465-
// true if any changes were made.
466-
static bool EnsureSingleLevelExit(Loop *L, LoopInfo *LI, DominatorTree *DT,
467-
BasicBlock *exiting_block) {
468-
BasicBlock *exit_block = GetExitBlockForExitingBlock(L, exiting_block);
469-
470-
Loop *exit_loop = LI->getLoopFor(exit_block);
471-
assert(L != exit_loop);
472-
473-
Loop *parent_loop = L->getParentLoop();
474-
if (parent_loop != exit_loop) {
475-
// Split the edge between the blocks, returning the newly created block.
476-
BasicBlock *new_bb = SplitEdge(exiting_block, exit_block, DT, LI);
477-
// The new block might be in the middle or at the end.
478-
BasicBlock *middle_bb;
479-
if (new_bb->getSingleSuccessor() == exit_block) {
480-
middle_bb = new_bb;
481-
} else {
482-
middle_bb = exit_block;
483-
exit_block = new_bb;
484-
}
485-
486-
// What loop does middle_bb end up in? SplitEdge has these cases:
487-
// If the edge was critical:
488-
// if source block is not in a loop: ruled out already
489-
// if dest block is not in a loop --> not in any loop.
490-
// if going from outer loop to inner loop: ruled out already
491-
// if going from inner loop to outer loop --> outer loop
492-
// if loops unrelated by containment -> the parent loop of the
493-
// destination block (which must be a loop header because we
494-
// assume irreducible loops).
495-
// If the edge was non-critcial:
496-
// If the exit block only had one incominge edge --> same loop as
497-
// destination block.
498-
// otherwise the exiting block had a single successor.
499-
// This is ruled out because the the exiting block ends with a
500-
// conditional branch, and so has two successors.
501-
502-
// Move the middle_block to the parent loop, if it exists.
503-
// If all goes well, the latch exit block will branch to it.
504-
// If the algorithm bails early, then there is no harm in putting
505-
// it in L's parent loop. At worst it will be an exiting block for
506-
// the parent loop.
507-
LI->removeBlock(middle_bb);
508-
if (parent_loop) {
509-
parent_loop->addBasicBlockToLoop(middle_bb, *LI);
510-
511-
// middle_bb block is now an exiting block, going from parent_loop to
512-
// exit_loop, which we know are different. Make sure it ends in a
513-
// in a conditional branch, as expected by the rest of the algorithm.
514-
auto *br = cast<BranchInst>(middle_bb->getTerminator());
515-
assert(!br->isConditional());
516-
auto *true_val = ConstantInt::getTrue(br->getContext());
517-
br->eraseFromParent();
518-
BasicBlock *parent_latch = parent_loop->getLoopLatch();
519-
BranchInst::Create(exit_block, parent_latch, true_val, middle_bb);
520-
// Fix phis in parent_latch
521-
for (Instruction &inst : *parent_latch) {
522-
PHINode *phi = dyn_cast<PHINode>(&inst);
523-
if (!phi)
524-
break;
525-
// We don't care about the values. The path is never taken.
526-
phi->addIncoming(GetDefaultValue(phi->getType()), middle_bb);
527-
}
528-
}
529-
return true;
530-
}
531-
return false;
532-
}
533-
534459
// Restructures exiting_block so its work, including its exit branch, is moved
535460
// to a block B that dominates the latch block. Let's call B the
536461
// newly-exiting-block.
@@ -540,15 +465,6 @@ static bool RemoveUnstructuredLoopExitsIteration(BasicBlock *exiting_block,
540465
Loop *L, LoopInfo *LI,
541466
DominatorTree *DT) {
542467
BasicBlock *latch = L->getLoopLatch();
543-
544-
if (EnsureSingleLevelExit(L, LI, DT, latch)) {
545-
// Exit early so we're forced to recompute exit blocks.
546-
return true;
547-
}
548-
if (EnsureSingleLevelExit(L, LI, DT, exiting_block)) {
549-
return true;
550-
}
551-
552468
BasicBlock *latch_exit = GetExitBlockForExitingBlock(L, latch);
553469
BasicBlock *exit_block = GetExitBlockForExitingBlock(L, exiting_block);
554470

test/HLSL/passes/dxil_remove_unstructured_loop_exits/exit-to-unrelated-loop.ll

Lines changed: 0 additions & 93 deletions
This file was deleted.

test/HLSL/passes/dxil_remove_unstructured_loop_exits/multi-level-exit-from-latch.ll

Lines changed: 0 additions & 166 deletions
This file was deleted.

0 commit comments

Comments
 (0)