Skip to content

Commit 8255472

Browse files
committed
[LoongArch] Eliminate extra un-accounted-for successors
Specifically: ``` *** Bad machine code: MBB has unexpected successors which are not branch targets, fallthrough, EHPads, or inlineasm_br targets. *** - function: atomicrmw_umax_i8_acquire - basic block: %bb.3 (0x1b90bd8) *** Bad machine code: Non-terminator instruction after the first terminator *** - function: atomicrmw_umax_i8_acquire - basic block: %bb.3 (0x1b90bd8) - instruction: DBAR 1792 ``` Differential Revision: https://reviews.llvm.org/D137884
1 parent 45e57a5 commit 8255472

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,20 +347,23 @@ bool LoongArchExpandAtomicPseudo::expandAtomicMinMaxOp(
347347
auto LoopHeadMBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
348348
auto LoopIfBodyMBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
349349
auto LoopTailMBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
350+
auto TailMBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
350351
auto DoneMBB = MF->CreateMachineBasicBlock(MBB.getBasicBlock());
351352

352353
// Insert new MBBs.
353354
MF->insert(++MBB.getIterator(), LoopHeadMBB);
354355
MF->insert(++LoopHeadMBB->getIterator(), LoopIfBodyMBB);
355356
MF->insert(++LoopIfBodyMBB->getIterator(), LoopTailMBB);
356-
MF->insert(++LoopTailMBB->getIterator(), DoneMBB);
357+
MF->insert(++LoopTailMBB->getIterator(), TailMBB);
358+
MF->insert(++TailMBB->getIterator(), DoneMBB);
357359

358360
// Set up successors and transfer remaining instructions to DoneMBB.
359361
LoopHeadMBB->addSuccessor(LoopIfBodyMBB);
360362
LoopHeadMBB->addSuccessor(LoopTailMBB);
361363
LoopIfBodyMBB->addSuccessor(LoopTailMBB);
362364
LoopTailMBB->addSuccessor(LoopHeadMBB);
363-
LoopTailMBB->addSuccessor(DoneMBB);
365+
LoopTailMBB->addSuccessor(TailMBB);
366+
TailMBB->addSuccessor(DoneMBB);
364367
DoneMBB->splice(DoneMBB->end(), &MBB, MI, MBB.end());
365368
DoneMBB->transferSuccessors(&MBB);
366369
MBB.addSuccessor(LoopHeadMBB);
@@ -427,7 +430,10 @@ bool LoongArchExpandAtomicPseudo::expandAtomicMinMaxOp(
427430
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::BEQZ))
428431
.addReg(Scratch1Reg)
429432
.addMBB(LoopHeadMBB);
430-
BuildMI(LoopTailMBB, DL, TII->get(LoongArch::DBAR)).addImm(0x700);
433+
434+
// .tail:
435+
// dbar 0x700
436+
BuildMI(TailMBB, DL, TII->get(LoongArch::DBAR)).addImm(0x700);
431437

432438
NextMBBI = MBB.end();
433439
MI.eraseFromParent();
@@ -436,6 +442,7 @@ bool LoongArchExpandAtomicPseudo::expandAtomicMinMaxOp(
436442
computeAndAddLiveIns(LiveRegs, *LoopHeadMBB);
437443
computeAndAddLiveIns(LiveRegs, *LoopIfBodyMBB);
438444
computeAndAddLiveIns(LiveRegs, *LoopTailMBB);
445+
computeAndAddLiveIns(LiveRegs, *TailMBB);
439446
computeAndAddLiveIns(LiveRegs, *DoneMBB);
440447

441448
return true;

llvm/test/CodeGen/LoongArch/ir-instruction/atomicrmw-minmax.ll

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2-
; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s --check-prefix=LA64
2+
; RUN: llc --mtriple=loongarch64 --verify-machineinstrs < %s | \
3+
; RUN: FileCheck %s --check-prefix=LA64
34

45
;; TODO: Testing for LA32 architecture will be added later
56

@@ -28,8 +29,9 @@ define i8 @atomicrmw_umax_i8_acquire(ptr %a, i8 %b) nounwind {
2829
; LA64-NEXT: .LBB0_3: # in Loop: Header=BB0_1 Depth=1
2930
; LA64-NEXT: sc.w $a5, $a2, 0
3031
; LA64-NEXT: beqz $a5, .LBB0_1
31-
; LA64-NEXT: dbar 1792
3232
; LA64-NEXT: # %bb.4:
33+
; LA64-NEXT: dbar 1792
34+
; LA64-NEXT: # %bb.5:
3335
; LA64-NEXT: srl.w $a0, $a4, $a0
3436
; LA64-NEXT: ret
3537
%1 = atomicrmw umax ptr %a, i8 %b acquire
@@ -62,8 +64,9 @@ define i16 @atomicrmw_umax_i16_acquire(ptr %a, i16 %b) nounwind {
6264
; LA64-NEXT: .LBB1_3: # in Loop: Header=BB1_1 Depth=1
6365
; LA64-NEXT: sc.w $a5, $a2, 0
6466
; LA64-NEXT: beqz $a5, .LBB1_1
65-
; LA64-NEXT: dbar 1792
6667
; LA64-NEXT: # %bb.4:
68+
; LA64-NEXT: dbar 1792
69+
; LA64-NEXT: # %bb.5:
6770
; LA64-NEXT: srl.w $a0, $a4, $a0
6871
; LA64-NEXT: ret
6972
%1 = atomicrmw umax ptr %a, i16 %b acquire
@@ -115,8 +118,9 @@ define i8 @atomicrmw_umin_i8_acquire(ptr %a, i8 %b) nounwind {
115118
; LA64-NEXT: .LBB4_3: # in Loop: Header=BB4_1 Depth=1
116119
; LA64-NEXT: sc.w $a5, $a2, 0
117120
; LA64-NEXT: beqz $a5, .LBB4_1
118-
; LA64-NEXT: dbar 1792
119121
; LA64-NEXT: # %bb.4:
122+
; LA64-NEXT: dbar 1792
123+
; LA64-NEXT: # %bb.5:
120124
; LA64-NEXT: srl.w $a0, $a4, $a0
121125
; LA64-NEXT: ret
122126
%1 = atomicrmw umin ptr %a, i8 %b acquire
@@ -149,8 +153,9 @@ define i16 @atomicrmw_umin_i16_acquire(ptr %a, i16 %b) nounwind {
149153
; LA64-NEXT: .LBB5_3: # in Loop: Header=BB5_1 Depth=1
150154
; LA64-NEXT: sc.w $a5, $a2, 0
151155
; LA64-NEXT: beqz $a5, .LBB5_1
152-
; LA64-NEXT: dbar 1792
153156
; LA64-NEXT: # %bb.4:
157+
; LA64-NEXT: dbar 1792
158+
; LA64-NEXT: # %bb.5:
154159
; LA64-NEXT: srl.w $a0, $a4, $a0
155160
; LA64-NEXT: ret
156161
%1 = atomicrmw umin ptr %a, i16 %b acquire

0 commit comments

Comments
 (0)