Skip to content

Commit b763ac6

Browse files
[Mips] Fix for assembler not printing a label
1 parent 380ac53 commit b763ac6

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

llvm/lib/Target/Mips/MipsAsmPrinter.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,23 @@ bool MipsAsmPrinter::isBlockOnlyReachableByFallthrough(const MachineBasicBlock*
502502
if (Pred->empty())
503503
return true;
504504

505+
// Check the terminators in the previous block.
506+
for (const auto &MI : Pred->terminators()) {
507+
// If it is not a simple branch, we are in a table somewhere.
508+
if (!MI.isBranch() || MI.isIndirectBranch())
509+
return false;
510+
511+
// If we are the operands of one of the branches, this is not a fall
512+
// through. Note that targets with delay slots will usually bundle
513+
// terminators with the delay slot instruction.
514+
for (ConstMIBundleOperands OP(MI); OP.isValid(); ++OP) {
515+
if (OP->isJTI())
516+
return false;
517+
if (OP->isMBB() && OP->getMBB() == MBB)
518+
return false;
519+
}
520+
}
521+
505522
// Otherwise, check the last instruction.
506523
// Check if the last terminator is an unconditional branch.
507524
MachineBasicBlock::const_iterator I = Pred->end();

llvm/test/CodeGen/Mips/Fast-ISel/pr40325.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ define void @test(i32 %x, ptr %p) nounwind {
1111
; CHECK-NEXT: andi $1, $4, 1
1212
; CHECK-NEXT: bgtz $1, $BB0_1
1313
; CHECK-NEXT: nop
14-
; CHECK-NEXT: # %bb.1: # %foo
14+
; CHECK-NEXT: $BB0_1: # %foo
1515
; CHECK-NEXT: jr $ra
1616
; CHECK-NEXT: nop
1717
%y = and i32 %x, 1
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc --filetype=asm -march=mips --relocation-model=pic -O0 < %s | FileCheck %s
3+
4+
define void @test(i32 %x) nounwind {
5+
%y = icmp eq i32 %x, 1
6+
br i1 %y, label %bb1, label %bb1
7+
8+
bb1:
9+
ret void
10+
}
11+
12+
; CHECK: bgtz ${{[0-9]+}}, $[[BB1:BB[0-9]+_[0-9]+]]
13+
; CHECK-NEXT: nop
14+
; CHECK-NEXT: $[[BB1]]:

0 commit comments

Comments
 (0)