Index: lib/CodeGen/BranchFolding.cpp =================================================================== --- lib/CodeGen/BranchFolding.cpp +++ lib/CodeGen/BranchFolding.cpp @@ -811,9 +811,11 @@ dbgs() << "\n"; if (SuccBB) { dbgs() << " with successor BB#" << SuccBB->getNumber() << '\n'; - if (PredBB) + if (PredBB) { dbgs() << " which has fall-through from BB#" << PredBB->getNumber() << "\n"; + assert(PredBB->isSuccessor(SuccBB) && "Merging non-cfg successor."); + } } dbgs() << "Looking for common tails of at least " << minCommonTailLength << " instruction" @@ -964,6 +966,8 @@ SmallPtrSet UniquePreds; MachineBasicBlock *IBB = &*I; MachineBasicBlock *PredBB = &*std::prev(I); + if (PredBB && !PredBB->isSuccessor(IBB)) + PredBB = nullptr; MergePotentials.clear(); for (MachineBasicBlock *PBB : I->predecessors()) { if (MergePotentials.size() == TailMergeThreshold) @@ -1186,6 +1190,9 @@ MachineFunction::iterator FallThrough = MBB->getIterator(); ++FallThrough; + if (FallThrough != MF.end() && !MBB->isSuccessor(&*FallThrough)) + FallThrough = MF.end(); + // Make sure MBB and FallThrough belong to the same funclet. bool SameFunclet = true; if (!FuncletMembership.empty() && FallThrough != MF.end()) { Index: test/CodeGen/ARM/call-tc.ll =================================================================== --- test/CodeGen/ARM/call-tc.ll +++ test/CodeGen/ARM/call-tc.ll @@ -118,14 +118,14 @@ %and1 = and i32 %x, 2 %tobool2 = icmp eq i32 %and1, 0 br i1 %tobool2, label %if.end5, label %if.then3 +; CHECKT2D: beq.w _c +; CHECKT2D: b.w _b if.then3: ; preds = %if.end -; CHECKT2D: bne.w _b %call4 = tail call i32 @b(i32 %x) nounwind br label %return if.end5: ; preds = %if.end -; CHECKT2D: b.w _c %call6 = tail call i32 @c(i32 %x) nounwind br label %return Index: test/CodeGen/ARM/test-sharedidx.ll =================================================================== --- test/CodeGen/ARM/test-sharedidx.ll +++ test/CodeGen/ARM/test-sharedidx.ll @@ -1,4 +1,4 @@ -; RUN: llc < %s -mtriple=armv7-apple-ios -mcpu=cortex-a9 -stress-ivchain | FileCheck %s +; RUN: llc < %s -mtriple=armv7-apple-ios -mcpu=cortex-a9 -stress-ivchain -disable-ifcvt-triangle | FileCheck %s ; REQUIRES: asserts ; @sharedidx is an unrolled variant of this loop: Index: test/CodeGen/Hexagon/always-ext.ll =================================================================== --- test/CodeGen/Hexagon/always-ext.ll +++ test/CodeGen/Hexagon/always-ext.ll @@ -1,4 +1,4 @@ -; RUN: llc -march=hexagon < %s | FileCheck %s +; RUN: llc -march=hexagon -disable-ifcvt-triangle-false < %s | FileCheck %s ; Check that we don't generate an invalid packet with too many instructions ; due to a store that has a must-extend operand. Index: test/CodeGen/Mips/eh.ll =================================================================== --- test/CodeGen/Mips/eh.ll +++ test/CodeGen/Mips/eh.ll @@ -24,7 +24,7 @@ lpad: ; preds = %entry ; CHECK-EL: # %lpad -; CHECK-EL: beq $5 +; CHECK-EL: bne $5 %exn.val = landingpad { i8*, i32 } cleanup Index: test/CodeGen/SPARC/missinglabel.ll =================================================================== --- test/CodeGen/SPARC/missinglabel.ll +++ test/CodeGen/SPARC/missinglabel.ll @@ -4,14 +4,14 @@ define void @f() align 2 { entry: -; CHECK: %xcc, .LBB0_1 +; CHECK: %xcc, .LBB0_2 %cmp = icmp eq i64 undef, 0 br i1 %cmp, label %targetblock, label %cond.false cond.false: unreachable -; CHECK: .LBB0_1: ! %targetblock +; CHECK: .LBB0_2: ! %targetblock targetblock: br i1 undef, label %cond.false.i83, label %exit.i85 Index: test/CodeGen/Thumb2/thumb2-cbnz.ll =================================================================== --- test/CodeGen/Thumb2/thumb2-cbnz.ll +++ test/CodeGen/Thumb2/thumb2-cbnz.ll @@ -5,6 +5,7 @@ define void @t(i32 %c, double %b) { entry: +; CHECK: cmp r0, #0 %cmp1 = icmp ne i32 %c, 0 br i1 %cmp1, label %bb3, label %bb1 @@ -23,8 +24,7 @@ br i1 %cmp3, label %bb11, label %bb9 bb9: ; preds = %bb7 -; CHECK: cmp r0, #0 -; CHECK-NEXT: cbnz +; CHECK: cbnz %0 = tail call double @foo(double %b) nounwind readnone ; [#uses=0] br label %bb11 Index: test/CodeGen/Thumb2/thumb2-ifcvt3.ll =================================================================== --- test/CodeGen/Thumb2/thumb2-ifcvt3.ll +++ test/CodeGen/Thumb2/thumb2-ifcvt3.ll @@ -22,8 +22,8 @@ ret i1 false bb52: ; preds = %newFuncRoot -; CHECK: movne -; CHECK: moveq +; CHECK-DAG: movne +; CHECK-DAG: moveq ; CHECK: pop %0 = load i64, i64* @posed, align 4 ; [#uses=3] %1 = sub i64 %0, %.reload78 ; [#uses=1] Index: test/CodeGen/X86/br-fold.ll =================================================================== --- test/CodeGen/X86/br-fold.ll +++ test/CodeGen/X86/br-fold.ll @@ -5,9 +5,11 @@ ; RUN: llc -mtriple=x86_64-scei-ps4 < %s | FileCheck -check-prefix=PS4 %s ; X64_DARWIN: orq +; X64_DARWIN-NEXT: jne ; X64_DARWIN-NEXT: %bb8.i329 ; X64_LINUX: orq %rax, %rcx +; X64_LINUX-NEXT: jne ; X64_LINUX-NEXT: %bb8.i329 ; X64_WINDOWS: orq %rax, %rcx Index: test/CodeGen/X86/catchret-regmask.ll =================================================================== --- test/CodeGen/X86/catchret-regmask.ll +++ test/CodeGen/X86/catchret-regmask.ll @@ -35,7 +35,7 @@ ; CHECK: movq -[[arg_slot]](%rbp), %rax # 8-byte Reload ; CHECK: retq -; CHECK: "?catch$3@?0?reload_out_of_pad@4HA": +; CHECK: "?catch$2@?0?reload_out_of_pad@4HA": ; CHECK-NOT: Reload ; CHECK: retq @@ -65,7 +65,7 @@ ; CHECK: movq -[[val_slot:[0-9]+]](%rbp), %rax # 8-byte Reload ; CHECK: retq -; CHECK: "?catch$3@?0?spill_in_pad@4HA": +; CHECK: "?catch$2@?0?spill_in_pad@4HA": ; CHECK: callq getval ; CHECK: movq %rax, -[[val_slot]](%rbp) # 8-byte Spill ; CHECK: retq Index: test/CodeGen/X86/fp-une-cmp.ll =================================================================== --- test/CodeGen/X86/fp-une-cmp.ll +++ test/CodeGen/X86/fp-une-cmp.ll @@ -84,11 +84,11 @@ ; CHECK: # BB#0: # %entry ; CHECK-NEXT: xorps %xmm1, %xmm1 ; CHECK-NEXT: ucomiss %xmm1, %xmm0 -; CHECK-NEXT: jne .LBB2_2 -; CHECK-NEXT: jnp .LBB2_1 -; CHECK-NEXT: .LBB2_2: # %if.then +; CHECK-NEXT: jne .LBB2_1 +; CHECK-NEXT: jnp .LBB2_2 +; CHECK-NEXT: .LBB2_1: # %if.then ; CHECK-NEXT: jmp a # TAILCALL -; CHECK-NEXT: .LBB2_1: # %if.end +; CHECK-NEXT: .LBB2_2: # %if.end ; CHECK-NEXT: retq entry: %cmp = fcmp une float %f, 0.000000e+00 Index: test/CodeGen/X86/implicit-null-check.ll =================================================================== --- test/CodeGen/X86/implicit-null-check.ll +++ test/CodeGen/X86/implicit-null-check.ll @@ -105,13 +105,13 @@ ; CHECK-LABEL: _imp_null_check_via_mem_comparision ; CHECK: [[BB0_imp_null_check_via_mem_comparision:L[^:]+]]: ; CHECK: cmpl %esi, 4(%rdi) -; CHECK: jge LBB4_2 +; CHECK: jge LBB4_4 ; CHECK: movl $100, %eax ; CHECK: retq ; CHECK: [[BB1_imp_null_check_via_mem_comparision:LBB4_[0-9]+]]: ; CHECK: movl $42, %eax ; CHECK: retq -; CHECK: LBB4_2: +; CHECK: LBB4_4: ; CHECK: movl $200, %eax ; CHECK: retq