Skip to content

Commit edb3347

Browse files
MaskRaytstellar
authored andcommitted
[MIPS] Use generic isBlockOnlyReachableByFallthrough (llvm#80799)
FastISel may create a redundant BGTZ terminal which fallthroughes. ``` BGTZ %2:gpr32, %bb.1, implicit-def $at bb.1.bb1: ; predecessors: %bb.0 ``` The `!I->isBarrier()` check in MipsAsmPrinter::isBlockOnlyReachableByFallthrough will incorrectly not print a label, leading to a `Undefined temporary symbol ` error when we try assembling the output assembly file. See the updated `Fast-ISel/pr40325.ll` and rust-lang/rust#108835 In addition, the `SwitchInst` condition is too conservative and prints many unneeded labels (see the updated tests). Just use the generic isBlockOnlyReachableByFallthrough, updated by commit 1995b9f for SPARC, which also handles MIPS. (cherry picked from commit 6b2fd7a)
1 parent dd7fed9 commit edb3347

File tree

8 files changed

+17
-58
lines changed

8 files changed

+17
-58
lines changed

llvm/lib/Target/Mips/MipsAsmPrinter.cpp

-39
Original file line numberDiff line numberDiff line change
@@ -471,45 +471,6 @@ void MipsAsmPrinter::emitBasicBlockEnd(const MachineBasicBlock &MBB) {
471471
TS.emitDirectiveInsn();
472472
}
473473

474-
/// isBlockOnlyReachableByFallthough - Return true if the basic block has
475-
/// exactly one predecessor and the control transfer mechanism between
476-
/// the predecessor and this block is a fall-through.
477-
bool MipsAsmPrinter::isBlockOnlyReachableByFallthrough(const MachineBasicBlock*
478-
MBB) const {
479-
// The predecessor has to be immediately before this block.
480-
const MachineBasicBlock *Pred = *MBB->pred_begin();
481-
482-
// If the predecessor is a switch statement, assume a jump table
483-
// implementation, so it is not a fall through.
484-
if (const BasicBlock *bb = Pred->getBasicBlock())
485-
if (isa<SwitchInst>(bb->getTerminator()))
486-
return false;
487-
488-
// If this is a landing pad, it isn't a fall through. If it has no preds,
489-
// then nothing falls through to it.
490-
if (MBB->isEHPad() || MBB->pred_empty())
491-
return false;
492-
493-
// If there isn't exactly one predecessor, it can't be a fall through.
494-
if (MBB->pred_size() != 1)
495-
return false;
496-
497-
// The predecessor has to be immediately before this block.
498-
if (!Pred->isLayoutSuccessor(MBB))
499-
return false;
500-
501-
// If the block is completely empty, then it definitely does fall through.
502-
if (Pred->empty())
503-
return true;
504-
505-
// Otherwise, check the last instruction.
506-
// Check if the last terminator is an unconditional branch.
507-
MachineBasicBlock::const_iterator I = Pred->end();
508-
while (I != Pred->begin() && !(--I)->isTerminator()) ;
509-
510-
return !I->isBarrier();
511-
}
512-
513474
// Print out an operand for an inline asm expression.
514475
bool MipsAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,
515476
const char *ExtraCode, raw_ostream &O) {

llvm/lib/Target/Mips/MipsAsmPrinter.h

-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
142142
void emitFunctionBodyStart() override;
143143
void emitFunctionBodyEnd() override;
144144
void emitBasicBlockEnd(const MachineBasicBlock &MBB) override;
145-
bool isBlockOnlyReachableByFallthrough(
146-
const MachineBasicBlock* MBB) const override;
147145
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
148146
const char *ExtraCode, raw_ostream &O) override;
149147
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,

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

llvm/test/CodeGen/Mips/GlobalISel/llvm-ir/jump_table_and_brjt.ll

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ define i32 @mod4_0_to_11(i32 %a) {
2525
; MIPS32-NEXT: sltu $1, $1, $2
2626
; MIPS32-NEXT: bnez $1, $BB0_6
2727
; MIPS32-NEXT: nop
28-
; MIPS32-NEXT: $BB0_1: # %entry
28+
; MIPS32-NEXT: # %bb.1: # %entry
2929
; MIPS32-NEXT: lw $2, 28($sp) # 4-byte Folded Reload
3030
; MIPS32-NEXT: lui $1, %hi($JTI0_0)
3131
; MIPS32-NEXT: sll $2, $2, 2
@@ -65,7 +65,7 @@ define i32 @mod4_0_to_11(i32 %a) {
6565
; MIPS32-NEXT: sltu $1, $1, $2
6666
; MIPS32-NEXT: bnez $1, $BB0_13
6767
; MIPS32-NEXT: nop
68-
; MIPS32-NEXT: $BB0_8: # %sw.epilog
68+
; MIPS32-NEXT: # %bb.8: # %sw.epilog
6969
; MIPS32-NEXT: lw $2, 0($sp) # 4-byte Folded Reload
7070
; MIPS32-NEXT: lui $1, %hi($JTI0_1)
7171
; MIPS32-NEXT: sll $2, $2, 2
@@ -125,7 +125,7 @@ define i32 @mod4_0_to_11(i32 %a) {
125125
; MIPS32_PIC-NEXT: sltu $1, $1, $2
126126
; MIPS32_PIC-NEXT: bnez $1, $BB0_6
127127
; MIPS32_PIC-NEXT: nop
128-
; MIPS32_PIC-NEXT: $BB0_1: # %entry
128+
; MIPS32_PIC-NEXT: # %bb.1: # %entry
129129
; MIPS32_PIC-NEXT: lw $2, 8($sp) # 4-byte Folded Reload
130130
; MIPS32_PIC-NEXT: lw $3, 36($sp) # 4-byte Folded Reload
131131
; MIPS32_PIC-NEXT: lw $1, %got($JTI0_0)($2)
@@ -167,7 +167,7 @@ define i32 @mod4_0_to_11(i32 %a) {
167167
; MIPS32_PIC-NEXT: sltu $1, $1, $2
168168
; MIPS32_PIC-NEXT: bnez $1, $BB0_13
169169
; MIPS32_PIC-NEXT: nop
170-
; MIPS32_PIC-NEXT: $BB0_8: # %sw.epilog
170+
; MIPS32_PIC-NEXT: # %bb.8: # %sw.epilog
171171
; MIPS32_PIC-NEXT: lw $2, 8($sp) # 4-byte Folded Reload
172172
; MIPS32_PIC-NEXT: lw $3, 4($sp) # 4-byte Folded Reload
173173
; MIPS32_PIC-NEXT: lw $1, %got($JTI0_1)($2)

llvm/test/CodeGen/Mips/compactbranches/unsafe-in-forbidden-slot.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ sw.bb: ; preds = %entry
1818
br label %sw.epilog
1919
; CHECK: beqzc
2020
; CHECK-NEXT: nop
21-
; CHECK-NEXT: .LBB
21+
; CHECK-NEXT: # %bb.1
2222
; CHECK-NEXT: j
2323

2424
sw.bb1: ; preds = %entry, %entry
2525
store volatile i32 2, ptr @boo, align 4
2626
br label %sw.epilog
2727
; CHECK: bnezc
2828
; CHECK-NEXT: nop
29-
; CHECK-NEXT: .LBB
29+
; CHECK-NEXT: # %bb.3
3030
; CHECK-NEXT: j
3131

3232
sw.epilog: ; preds = %entry, %sw.bb1, %sw.bb

llvm/test/CodeGen/Mips/indirect-jump-hazard/jumptables.ll

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ define ptr @_Z3fooi(i32 signext %Letter) {
4242
; MIPS32R2-NEXT: sltiu $1, $4, 7
4343
; MIPS32R2-NEXT: beqz $1, $BB0_6
4444
; MIPS32R2-NEXT: sw $4, 4($sp)
45-
; MIPS32R2-NEXT: $BB0_1: # %entry
45+
; MIPS32R2-NEXT: # %bb.1: # %entry
4646
; MIPS32R2-NEXT: sll $1, $4, 2
4747
; MIPS32R2-NEXT: lui $2, %hi($JTI0_0)
4848
; MIPS32R2-NEXT: addu $1, $1, $2
@@ -100,7 +100,7 @@ define ptr @_Z3fooi(i32 signext %Letter) {
100100
; MIPS32R6-NEXT: sltiu $1, $4, 7
101101
; MIPS32R6-NEXT: beqz $1, $BB0_6
102102
; MIPS32R6-NEXT: sw $4, 4($sp)
103-
; MIPS32R6-NEXT: $BB0_1: # %entry
103+
; MIPS32R6-NEXT: # %bb.1: # %entry
104104
; MIPS32R6-NEXT: sll $1, $4, 2
105105
; MIPS32R6-NEXT: lui $2, %hi($JTI0_0)
106106
; MIPS32R6-NEXT: addu $1, $1, $2
@@ -159,7 +159,7 @@ define ptr @_Z3fooi(i32 signext %Letter) {
159159
; MIPS64R2-NEXT: sltiu $1, $2, 7
160160
; MIPS64R2-NEXT: beqz $1, .LBB0_6
161161
; MIPS64R2-NEXT: sw $4, 4($sp)
162-
; MIPS64R2-NEXT: .LBB0_1: # %entry
162+
; MIPS64R2-NEXT: # %bb.1: # %entry
163163
; MIPS64R2-NEXT: dsll $1, $2, 3
164164
; MIPS64R2-NEXT: lui $2, %highest(.LJTI0_0)
165165
; MIPS64R2-NEXT: daddiu $2, $2, %higher(.LJTI0_0)
@@ -254,7 +254,7 @@ define ptr @_Z3fooi(i32 signext %Letter) {
254254
; MIPS64R6-NEXT: sltiu $1, $2, 7
255255
; MIPS64R6-NEXT: beqz $1, .LBB0_6
256256
; MIPS64R6-NEXT: sw $4, 4($sp)
257-
; MIPS64R6-NEXT: .LBB0_1: # %entry
257+
; MIPS64R6-NEXT: # %bb.1: # %entry
258258
; MIPS64R6-NEXT: dsll $1, $2, 3
259259
; MIPS64R6-NEXT: lui $2, %highest(.LJTI0_0)
260260
; MIPS64R6-NEXT: daddiu $2, $2, %higher(.LJTI0_0)
@@ -351,7 +351,7 @@ define ptr @_Z3fooi(i32 signext %Letter) {
351351
; PIC-MIPS32R2-NEXT: sltiu $1, $4, 7
352352
; PIC-MIPS32R2-NEXT: beqz $1, $BB0_6
353353
; PIC-MIPS32R2-NEXT: sw $4, 4($sp)
354-
; PIC-MIPS32R2-NEXT: $BB0_1: # %entry
354+
; PIC-MIPS32R2-NEXT: # %bb.1: # %entry
355355
; PIC-MIPS32R2-NEXT: sll $1, $4, 2
356356
; PIC-MIPS32R2-NEXT: lw $3, %got($JTI0_0)($2)
357357
; PIC-MIPS32R2-NEXT: addu $1, $1, $3
@@ -413,7 +413,7 @@ define ptr @_Z3fooi(i32 signext %Letter) {
413413
; PIC-MIPS32R6-NEXT: sltiu $1, $4, 7
414414
; PIC-MIPS32R6-NEXT: beqz $1, $BB0_6
415415
; PIC-MIPS32R6-NEXT: sw $4, 4($sp)
416-
; PIC-MIPS32R6-NEXT: $BB0_1: # %entry
416+
; PIC-MIPS32R6-NEXT: # %bb.1: # %entry
417417
; PIC-MIPS32R6-NEXT: sll $1, $4, 2
418418
; PIC-MIPS32R6-NEXT: lw $3, %got($JTI0_0)($2)
419419
; PIC-MIPS32R6-NEXT: addu $1, $1, $3
@@ -476,7 +476,7 @@ define ptr @_Z3fooi(i32 signext %Letter) {
476476
; PIC-MIPS64R2-NEXT: sltiu $1, $3, 7
477477
; PIC-MIPS64R2-NEXT: beqz $1, .LBB0_6
478478
; PIC-MIPS64R2-NEXT: sw $4, 4($sp)
479-
; PIC-MIPS64R2-NEXT: .LBB0_1: # %entry
479+
; PIC-MIPS64R2-NEXT: # %bb.1: # %entry
480480
; PIC-MIPS64R2-NEXT: dsll $1, $3, 3
481481
; PIC-MIPS64R2-NEXT: ld $3, %got_page(.LJTI0_0)($2)
482482
; PIC-MIPS64R2-NEXT: daddu $1, $1, $3
@@ -539,7 +539,7 @@ define ptr @_Z3fooi(i32 signext %Letter) {
539539
; PIC-MIPS64R6-NEXT: sltiu $1, $3, 7
540540
; PIC-MIPS64R6-NEXT: beqz $1, .LBB0_6
541541
; PIC-MIPS64R6-NEXT: sw $4, 4($sp)
542-
; PIC-MIPS64R6-NEXT: .LBB0_1: # %entry
542+
; PIC-MIPS64R6-NEXT: # %bb.1: # %entry
543543
; PIC-MIPS64R6-NEXT: dsll $1, $3, 3
544544
; PIC-MIPS64R6-NEXT: ld $3, %got_page(.LJTI0_0)($2)
545545
; PIC-MIPS64R6-NEXT: daddu $1, $1, $3

llvm/test/CodeGen/Mips/jump-table-mul.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define i64 @test(i64 %arg) {
1010
; CHECK-NEXT: sltiu $1, $4, 11
1111
; CHECK-NEXT: beqz $1, .LBB0_4
1212
; CHECK-NEXT: nop
13-
; CHECK-NEXT: .LBB0_1: # %entry
13+
; CHECK-NEXT: # %bb.1: # %entry
1414
; CHECK-NEXT: daddiu $1, $2, %lo(%neg(%gp_rel(test)))
1515
; CHECK-NEXT: dsll $2, $4, 3
1616
; CHECK-NEXT: ld $3, %got_page(.LJTI0_0)($1)

llvm/test/CodeGen/Mips/pseudo-jump-fill.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ define i32 @test(i32 signext %x, i32 signext %c) {
1414
; CHECK-NEXT: sltiu $1, $5, 4
1515
; CHECK-NEXT: beqz $1, $BB0_6
1616
; CHECK-NEXT: addu $3, $2, $25
17-
; CHECK-NEXT: $BB0_1: # %entry
17+
; CHECK-NEXT: # %bb.1: # %entry
1818
; CHECK-NEXT: li16 $2, 0
1919
; CHECK-NEXT: sll16 $5, $5, 2
2020
; CHECK-NEXT: lw $6, %got($JTI0_0)($3)

0 commit comments

Comments
 (0)