diff --git a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp --- a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp @@ -1755,6 +1755,13 @@ MachineRegisterInfo &MRI = MF.getRegInfo(); switch (I.getOpcode()) { + case TargetOpcode::G_BR: + // If the branch jumps to the fallthrough block, don't bother emitting it. + if (MBB.isLayoutSuccessor(I.getOperand(0).getMBB())) { + I.eraseFromParent(); + return true; + } + break; case TargetOpcode::G_SHL: return earlySelectSHL(I, MRI); case TargetOpcode::G_CONSTANT: { diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/select-binop.mir b/llvm/test/CodeGen/AArch64/GlobalISel/select-binop.mir --- a/llvm/test/CodeGen/AArch64/GlobalISel/select-binop.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/select-binop.mir @@ -330,7 +330,6 @@ ; CHECK: bb.0: ; CHECK: successors: %bb.1(0x80000000) ; CHECK: [[COPY:%[0-9]+]]:gpr32sp = COPY $w0 - ; CHECK: B %bb.1 ; CHECK: bb.1: ; CHECK: [[ADDWri:%[0-9]+]]:gpr32sp = ADDWri [[COPY]], 1, 0 ; CHECK: $w0 = COPY [[ADDWri]] diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/select-jump-table-brjt-constrain.mir b/llvm/test/CodeGen/AArch64/GlobalISel/select-jump-table-brjt-constrain.mir --- a/llvm/test/CodeGen/AArch64/GlobalISel/select-jump-table-brjt-constrain.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/select-jump-table-brjt-constrain.mir @@ -35,7 +35,6 @@ ; CHECK: BR %6 ; CHECK: bb.2: ; CHECK: successors: %bb.3(0x80000000) - ; CHECK: B %bb.3 ; CHECK: bb.3: ; CHECK: RET_ReallyLR bb.1: diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/select-returnaddress-liveins.mir b/llvm/test/CodeGen/AArch64/GlobalISel/select-returnaddress-liveins.mir --- a/llvm/test/CodeGen/AArch64/GlobalISel/select-returnaddress-liveins.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/select-returnaddress-liveins.mir @@ -19,7 +19,6 @@ ; CHECK: successors: %bb.1(0x80000000) ; CHECK: liveins: $w0, $x0, $lr ; CHECK: [[COPY:%[0-9]+]]:gpr64sp = COPY $lr - ; CHECK: B %bb.1 ; CHECK: bb.1: ; CHECK: [[COPY1:%[0-9]+]]:gpr64 = COPY [[COPY]] ; CHECK: $x0 = COPY [[COPY1]] @@ -47,7 +46,6 @@ ; CHECK: successors: %bb.1(0x80000000) ; CHECK: liveins: $w0, $x0, $lr ; CHECK: [[COPY:%[0-9]+]]:gpr64sp = COPY $lr - ; CHECK: B %bb.1 ; CHECK: bb.1: ; CHECK: [[COPY1:%[0-9]+]]:gpr64 = COPY [[COPY]] ; CHECK: $x0 = COPY [[COPY1]] @@ -78,7 +76,6 @@ ; CHECK: liveins: $w0, $x0, $lr ; CHECK: [[COPY:%[0-9]+]]:gpr64sp = COPY $lr ; CHECK: [[COPY1:%[0-9]+]]:gpr64 = COPY [[COPY]] - ; CHECK: B %bb.1 ; CHECK: bb.1: ; CHECK: $x0 = COPY [[COPY1]] ; CHECK: [[COPY2:%[0-9]+]]:gpr64 = COPY [[COPY]] diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/select-xor.mir b/llvm/test/CodeGen/AArch64/GlobalISel/select-xor.mir --- a/llvm/test/CodeGen/AArch64/GlobalISel/select-xor.mir +++ b/llvm/test/CodeGen/AArch64/GlobalISel/select-xor.mir @@ -132,7 +132,6 @@ ; CHECK-LABEL: name: xor_constant_n1_s32_gpr_2bb ; CHECK: bb.0: ; CHECK: successors: %bb.1(0x80000000) - ; CHECK: B %bb.1 ; CHECK: bb.1: ; CHECK: [[COPY:%[0-9]+]]:gpr32 = COPY $w0 ; CHECK: [[ORNWrr:%[0-9]+]]:gpr32 = ORNWrr $wzr, [[COPY]]