Index: llvm/lib/Target/ARM/ARMBlockPlacement.cpp =================================================================== --- llvm/lib/Target/ARM/ARMBlockPlacement.cpp +++ llvm/lib/Target/ARM/ARMBlockPlacement.cpp @@ -259,18 +259,22 @@ assert(From->isSuccessor(To) && "'To' is expected to be a successor of 'From'"); MachineInstr &Terminator = *(--From->terminators().end()); - if (!Terminator.isUnconditionalBranch()) { - // The BB doesn't have an unconditional branch so it relied on - // fall-through. Fix by adding an unconditional branch to the moved BB. - MachineInstrBuilder MIB = - BuildMI(From, Terminator.getDebugLoc(), TII->get(ARM::t2B)); - MIB.addMBB(To); - MIB.addImm(ARMCC::CondCodes::AL); - MIB.addReg(ARM::NoRegister); - LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Adding unconditional branch from " - << From->getName() << " to " << To->getName() << ": " - << *MIB.getInstr()); - } + if (!TII->isPredicated(Terminator) && + (isUncondBranchOpcode(Terminator.getOpcode()) || + isIndirectBranchOpcode(Terminator.getOpcode()) || + isJumpTableBranchOpcode(Terminator.getOpcode()) || + Terminator.isReturn())) + return; + // The BB doesn't have an unconditional branch so it relied on + // fall-through. Fix by adding an unconditional branch to the moved BB. + MachineInstrBuilder MIB = + BuildMI(From, Terminator.getDebugLoc(), TII->get(ARM::t2B)); + MIB.addMBB(To); + MIB.addImm(ARMCC::CondCodes::AL); + MIB.addReg(ARM::NoRegister); + LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Adding unconditional branch from " + << From->getName() << " to " << To->getName() << ": " + << *MIB.getInstr()); }; // Fix fall-through to the moved BB from the one that used to be before it. Index: llvm/test/CodeGen/Thumb2/mve-wls-block-placement.mir =================================================================== --- llvm/test/CodeGen/Thumb2/mve-wls-block-placement.mir +++ llvm/test/CodeGen/Thumb2/mve-wls-block-placement.mir @@ -821,7 +821,6 @@ ; CHECK-NEXT: renamable $r5 = t2LEApcrelJT %jump-table.0, 14 /* CC::al */, $noreg ; CHECK-NEXT: renamable $r5 = t2ADDrs killed renamable $r5, renamable $r0, 18, 14 /* CC::al */, $noreg, $noreg ; CHECK-NEXT: t2BR_JT killed renamable $r5, killed renamable $r0, %jump-table.0 - ; CHECK-NEXT: t2B %bb.1, 14 /* CC::al */, $noreg ; CHECK-NEXT: {{ $}} ; CHECK-NEXT: bb.4: ; CHECK-NEXT: successors: %bb.4(0x7c000000), %bb.2(0x04000000)