llvm.org GIT mirror llvm / f1a60c7
Fix updateTerminator to be resiliant to degenerate terminators where both fallthrough and a conditional branch target the same successor. Gracefully delete the conditional branch and introduce any unconditional branch needed to reach the actual successor. This fixes memory corruption in 2009-06-15-RegScavengerAssert.ll and possibly other tests. Also, while I'm here fix a latent bug I spotted by inspection. I never applied the same fundamental fix to this fallthrough successor finding logic that I did to the logic used when there are no conditional branches. As a consequence it would have selected landing pads had they be aligned in just the right way here. I don't have a test case as I spotted this by inspection, and the previous time I found this required have of TableGen's source code to produce it. =/ I hate backend bugs. ;] Thanks to Jim Grosbach for helping me reason through this and reviewing the fix. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154867 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 7 years ago
3 changed file(s) with 31 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
391391 TII->InsertBranch(*this, TBB, 0, Cond, dl);
392392 }
393393 } else {
394 // Walk through the successors and find the successor which is not
395 // a landing pad and is not the conditional branch destination (in TBB)
396 // as the fallthrough successor.
397 MachineBasicBlock *FallthroughBB = 0;
398 for (succ_iterator SI = succ_begin(), SE = succ_end(); SI != SE; ++SI) {
399 if ((*SI)->isLandingPad() || *SI == TBB)
400 continue;
401 assert(!FallthroughBB && "Found more than one fallthrough successor.");
402 FallthroughBB = *SI;
403 }
404 if (!FallthroughBB && canFallThrough()) {
405 // We fallthrough to the same basic block as the conditional jump
406 // targets. Remove the conditional jump, leaving unconditional
407 // fallthrough.
408 // FIXME: This does not seem like a reasonable pattern to support, but it
409 // has been seen in the wild coming out of degenerate ARM test cases.
410 TII->RemoveBranch(*this);
411
412 // Finally update the unconditional successor to be reached via a branch
413 // if it would not be reached by fallthrough.
414 if (!isLayoutSuccessor(TBB))
415 TII->InsertBranch(*this, TBB, 0, Cond, dl);
416 return;
417 }
418
394419 // The block has a fallthrough conditional branch.
395 MachineBasicBlock *MBBA = *succ_begin();
396 MachineBasicBlock *MBBB = *llvm::next(succ_begin());
397 if (MBBA == TBB) std::swap(MBBB, MBBA);
398420 if (isLayoutSuccessor(TBB)) {
399421 if (TII->ReverseBranchCondition(Cond)) {
400422 // We can't reverse the condition, add an unconditional branch.
401423 Cond.clear();
402 TII->InsertBranch(*this, MBBA, 0, Cond, dl);
424 TII->InsertBranch(*this, FallthroughBB, 0, Cond, dl);
403425 return;
404426 }
405427 TII->RemoveBranch(*this);
406 TII->InsertBranch(*this, MBBA, 0, Cond, dl);
407 } else if (!isLayoutSuccessor(MBBA)) {
428 TII->InsertBranch(*this, FallthroughBB, 0, Cond, dl);
429 } else if (!isLayoutSuccessor(FallthroughBB)) {
408430 TII->RemoveBranch(*this);
409 TII->InsertBranch(*this, TBB, MBBA, Cond, dl);
431 TII->InsertBranch(*this, TBB, FallthroughBB, Cond, dl);
410432 }
411433 }
412434 }
8282 entry:
8383 ; CHECK: t2:
8484 ; CHECK: cmp r0, #0
85 ; CHECK: bne
85 ; CHECK: %growMapping.exit
8686 br i1 undef, label %bb.i.i3, label %growMapping.exit
8787
8888 bb.i.i3: ; preds = %entry
0 ; RUN: llc -march=x86-64 < %s | FileCheck %s
11
22 ; CHECK: orq
3 ; CHECK-NEXT: je
3 ; CHECK-NEXT: .LBB0_1
44
55 @_ZN11xercesc_2_513SchemaSymbols21fgURI_SCHEMAFORSCHEMAE = external constant [33 x i16], align 32 ; <[33 x i16]*> [#uses=1]
66 @_ZN11xercesc_2_56XMLUni16fgNotationStringE = external constant [9 x i16], align 16 ; <[9 x i16]*> [#uses=1]