Skip to content

Conversation

yingopq
Copy link
Contributor

@yingopq yingopq commented Jul 22, 2025

Fix #145411.

@llvmbot
Copy link
Member

llvmbot commented Jul 22, 2025

@llvm/pr-subscribers-backend-mips

Author: None (yingopq)

Changes

Fix #145411.


Patch is 31.58 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149983.diff

2 Files Affected:

  • (modified) llvm/lib/Target/Mips/MipsExpandPseudo.cpp (+188-25)
  • (modified) llvm/test/CodeGen/Mips/atomic-min-max.ll (+521)
diff --git a/llvm/lib/Target/Mips/MipsExpandPseudo.cpp b/llvm/lib/Target/Mips/MipsExpandPseudo.cpp
index 199474fbd82d7..1c7ed37437aa7 100644
--- a/llvm/lib/Target/Mips/MipsExpandPseudo.cpp
+++ b/llvm/lib/Target/Mips/MipsExpandPseudo.cpp
@@ -433,13 +433,24 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword(
   Register OldVal = I->getOperand(6).getReg();
   Register BinOpRes = I->getOperand(7).getReg();
   Register StoreVal = I->getOperand(8).getReg();
+  bool NoMovnInstr = (IsMin || IsMax) && !STI->hasMips4() && !STI->hasMips32();
 
   const BasicBlock *LLVM_BB = BB.getBasicBlock();
   MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB);
+  MachineBasicBlock *loop1MBB;
+  MachineBasicBlock *loop2MBB;
+  if (NoMovnInstr) {
+    loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB);
+    loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB);
+  }
   MachineBasicBlock *sinkMBB = MF->CreateMachineBasicBlock(LLVM_BB);
   MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB);
   MachineFunction::iterator It = ++BB.getIterator();
   MF->insert(It, loopMBB);
+  if (NoMovnInstr) {
+    MF->insert(It, loop1MBB);
+    MF->insert(It, loop2MBB);
+  }
   MF->insert(It, sinkMBB);
   MF->insert(It, exitMBB);
 
@@ -447,9 +458,19 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword(
   exitMBB->transferSuccessorsAndUpdatePHIs(&BB);
 
   BB.addSuccessor(loopMBB, BranchProbability::getOne());
-  loopMBB->addSuccessor(sinkMBB);
-  loopMBB->addSuccessor(loopMBB);
+  if (NoMovnInstr) {
+    loopMBB->addSuccessor(loop1MBB);
+    loopMBB->addSuccessor(loop2MBB);
+  } else {
+    loopMBB->addSuccessor(sinkMBB);
+    loopMBB->addSuccessor(loopMBB);
+  }
   loopMBB->normalizeSuccProbs();
+  if (NoMovnInstr) {
+    loop1MBB->addSuccessor(loop2MBB);
+    loop2MBB->addSuccessor(loopMBB);
+    loop2MBB->addSuccessor(exitMBB, BranchProbability::getOne());
+  }
 
   BuildMI(loopMBB, DL, TII->get(LL), OldVal).addReg(Ptr).addImm(0);
   if (IsNand) {
@@ -526,7 +547,7 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword(
       BuildMI(loopMBB, DL, TII->get(OR), BinOpRes)
           .addReg(BinOpRes)
           .addReg(Scratch4);
-    } else {
+    } else if (STI->hasMips4() || STI->hasMips32()) {
       // max: move BinOpRes, StoreVal
       //      movn BinOpRes, Incr, Scratch4, BinOpRes
       // min: move BinOpRes, StoreVal
@@ -538,12 +559,59 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword(
           .addReg(Incr)
           .addReg(Scratch4)
           .addReg(BinOpRes);
+    } else {
+      // if min:
+      // loopMBB:  move BinOpRes, StoreVal
+      //           beq Scratch4, 0, loop1MBB
+      //           j loop2MBB
+      // loop1MBB: move BinOpRes, Incr
+      // loop2MBB: and BinOpRes, BinOpRes, Mask
+      //           and StoreVal, OlddVal, Mask2
+      //           or StoreVal, StoreVal, BinOpRes
+      //           StoreVal<tied1> = sc StoreVal, 0(Ptr)
+      //           beq StoreVal, zero, loopMBB
+      //
+      // if max:
+      // loopMBB:  move BinOpRes, Incr
+      //           beq Scratch4, 0, loop1MBB
+      //           j loop2MBB
+      // loop1MBB: move BinOpRes, StoreVal
+      // loop2MBB: and BinOpRes, BinOpRes, Mask
+      //           and StoreVal, OlddVal, Mask2
+      //           or StoreVal, StoreVal, BinOpRes
+      //           StoreVal<tied1> = sc StoreVal, 0(Ptr)
+      //           beq StoreVal, zero, loopMBB
+      if (IsMin) {
+        BuildMI(loopMBB, DL, TII->get(OR), BinOpRes)
+            .addReg(StoreVal)
+            .addReg(Mips::ZERO);
+        BuildMI(loop1MBB, DL, TII->get(OR), BinOpRes)
+            .addReg(Incr)
+            .addReg(Mips::ZERO);
+      } else {
+        BuildMI(loopMBB, DL, TII->get(OR), BinOpRes)
+            .addReg(Incr)
+            .addReg(Mips::ZERO);
+        BuildMI(loop1MBB, DL, TII->get(OR), BinOpRes)
+            .addReg(StoreVal)
+            .addReg(Mips::ZERO);
+      }
+      BuildMI(loopMBB, DL, TII->get(BEQ))
+          .addReg(Scratch4)
+          .addReg(Mips::ZERO)
+          .addMBB(loop1MBB);
+      BuildMI(loopMBB, DL, TII->get(Mips::J)).addMBB(loop2MBB);
     }
 
     //  and BinOpRes, BinOpRes, Mask
-    BuildMI(loopMBB, DL, TII->get(Mips::AND), BinOpRes)
-        .addReg(BinOpRes)
-        .addReg(Mask);
+    if (NoMovnInstr)
+      BuildMI(loop2MBB, DL, TII->get(Mips::AND), BinOpRes)
+          .addReg(BinOpRes)
+          .addReg(Mask);
+    else
+      BuildMI(loopMBB, DL, TII->get(Mips::AND), BinOpRes)
+          .addReg(BinOpRes)
+          .addReg(Mask);
 
   } else if (!IsSwap) {
     //  <binop> binopres, oldval, incr2
@@ -565,14 +633,37 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword(
   // or StoreVal, StoreVal, BinOpRes
   // StoreVal<tied1> = sc StoreVal, 0(Ptr)
   // beq StoreVal, zero, loopMBB
-  BuildMI(loopMBB, DL, TII->get(Mips::AND), StoreVal)
-    .addReg(OldVal).addReg(Mask2);
-  BuildMI(loopMBB, DL, TII->get(Mips::OR), StoreVal)
-    .addReg(StoreVal).addReg(BinOpRes);
-  BuildMI(loopMBB, DL, TII->get(SC), StoreVal)
-    .addReg(StoreVal).addReg(Ptr).addImm(0);
-  BuildMI(loopMBB, DL, TII->get(BEQ))
-    .addReg(StoreVal).addReg(Mips::ZERO).addMBB(loopMBB);
+  if (NoMovnInstr) {
+    BuildMI(loop2MBB, DL, TII->get(Mips::AND), StoreVal)
+        .addReg(OldVal)
+        .addReg(Mask2);
+    BuildMI(loop2MBB, DL, TII->get(Mips::OR), StoreVal)
+        .addReg(StoreVal)
+        .addReg(BinOpRes);
+    BuildMI(loop2MBB, DL, TII->get(SC), StoreVal)
+        .addReg(StoreVal)
+        .addReg(Ptr)
+        .addImm(0);
+    BuildMI(loop2MBB, DL, TII->get(BEQ))
+        .addReg(StoreVal)
+        .addReg(Mips::ZERO)
+        .addMBB(loopMBB);
+  } else {
+    BuildMI(loopMBB, DL, TII->get(Mips::AND), StoreVal)
+        .addReg(OldVal)
+        .addReg(Mask2);
+    BuildMI(loopMBB, DL, TII->get(Mips::OR), StoreVal)
+        .addReg(StoreVal)
+        .addReg(BinOpRes);
+    BuildMI(loopMBB, DL, TII->get(SC), StoreVal)
+        .addReg(StoreVal)
+        .addReg(Ptr)
+        .addImm(0);
+    BuildMI(loopMBB, DL, TII->get(BEQ))
+        .addReg(StoreVal)
+        .addReg(Mips::ZERO)
+        .addMBB(loopMBB);
+  }
 
   //  sinkMBB:
   //    and     maskedoldval1,oldval,mask
@@ -601,6 +692,10 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword(
 
   LivePhysRegs LiveRegs;
   computeAndAddLiveIns(LiveRegs, *loopMBB);
+  if (NoMovnInstr) {
+    computeAndAddLiveIns(LiveRegs, *loop1MBB);
+    computeAndAddLiveIns(LiveRegs, *loop2MBB);
+  }
   computeAndAddLiveIns(LiveRegs, *sinkMBB);
   computeAndAddLiveIns(LiveRegs, *exitMBB);
 
@@ -747,20 +842,41 @@ bool MipsExpandPseudo::expandAtomicBinOp(MachineBasicBlock &BB,
     llvm_unreachable("Unknown pseudo atomic!");
   }
 
+  bool NoMovnInstr = (IsMin || IsMax) && !STI->hasMips4() && !STI->hasMips32();
   const BasicBlock *LLVM_BB = BB.getBasicBlock();
   MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB);
+  MachineBasicBlock *loop1MBB;
+  MachineBasicBlock *loop2MBB;
+  if (NoMovnInstr) {
+    loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB);
+    loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB);
+  }
   MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB);
   MachineFunction::iterator It = ++BB.getIterator();
   MF->insert(It, loopMBB);
+  if (NoMovnInstr) {
+    MF->insert(It, loop1MBB);
+    MF->insert(It, loop2MBB);
+  }
   MF->insert(It, exitMBB);
 
   exitMBB->splice(exitMBB->begin(), &BB, std::next(I), BB.end());
   exitMBB->transferSuccessorsAndUpdatePHIs(&BB);
 
   BB.addSuccessor(loopMBB, BranchProbability::getOne());
-  loopMBB->addSuccessor(exitMBB);
-  loopMBB->addSuccessor(loopMBB);
+  if (NoMovnInstr) {
+    loopMBB->addSuccessor(loop1MBB);
+    loopMBB->addSuccessor(loop2MBB);
+  } else {
+    loopMBB->addSuccessor(exitMBB);
+    loopMBB->addSuccessor(loopMBB);
+  }
   loopMBB->normalizeSuccProbs();
+  if (NoMovnInstr) {
+    loop1MBB->addSuccessor(loop2MBB);
+    loop2MBB->addSuccessor(loopMBB);
+    loop2MBB->addSuccessor(exitMBB, BranchProbability::getOne());
+  }
 
   BuildMI(loopMBB, DL, TII->get(LL), OldVal).addReg(Ptr).addImm(0);
   assert((OldVal != Ptr) && "Clobbered the wrong ptr reg!");
@@ -803,7 +919,7 @@ bool MipsExpandPseudo::expandAtomicBinOp(MachineBasicBlock &BB,
       BuildMI(loopMBB, DL, TII->get(OR), Scratch)
           .addReg(Scratch)
           .addReg(Scratch2);
-    } else {
+    } else if (STI->hasMips4() || STI->hasMips32()) {
       // max: move Scratch, OldVal
       //      movn Scratch, Incr, Scratch2, Scratch
       // min: move Scratch, OldVal
@@ -815,6 +931,38 @@ bool MipsExpandPseudo::expandAtomicBinOp(MachineBasicBlock &BB,
           .addReg(Incr)
           .addReg(Scratch2)
           .addReg(Scratch);
+    } else {
+      // if min:
+      // loopMBB:  move Scratch, OldVal
+      //           beq Scratch2_32, 0, loop1MBB
+      //           j loop2MBB
+      // loop1MBB: move Scratch, Incr
+      // loop2MBB: sc $2, 0($4)
+      //           beqz	$2, $BB0_1
+      //           nop
+      //
+      // if max:
+      // loopMBB:  move Scratch, Incr
+      //           beq Scratch2_32, 0, loop1MBB
+      //           j loop2MBB
+      // loop1MBB: move Scratch, OldVal
+      // loop2MBB: sc $2, 0($4)
+      //           beqz	$2, $BB0_1
+      //           nop
+      if (IsMin) {
+        BuildMI(loopMBB, DL, TII->get(OR), Scratch).addReg(OldVal).addReg(ZERO);
+        BuildMI(loop1MBB, DL, TII->get(OR), Scratch).addReg(Incr).addReg(ZERO);
+      } else {
+        BuildMI(loopMBB, DL, TII->get(OR), Scratch).addReg(Incr).addReg(ZERO);
+        BuildMI(loop1MBB, DL, TII->get(OR), Scratch)
+            .addReg(OldVal)
+            .addReg(ZERO);
+      }
+      BuildMI(loopMBB, DL, TII->get(BEQ))
+          .addReg(Scratch2_32)
+          .addReg(ZERO)
+          .addMBB(loop1MBB);
+      BuildMI(loopMBB, DL, TII->get(Mips::J)).addMBB(loop2MBB);
     }
 
   } else if (Opcode) {
@@ -830,20 +978,35 @@ bool MipsExpandPseudo::expandAtomicBinOp(MachineBasicBlock &BB,
     BuildMI(loopMBB, DL, TII->get(OR), Scratch).addReg(Incr).addReg(ZERO);
   }
 
-  BuildMI(loopMBB, DL, TII->get(SC), Scratch)
-      .addReg(Scratch)
-      .addReg(Ptr)
-      .addImm(0);
-  BuildMI(loopMBB, DL, TII->get(BEQ))
-      .addReg(Scratch)
-      .addReg(ZERO)
-      .addMBB(loopMBB);
+  if (NoMovnInstr) {
+    BuildMI(loop2MBB, DL, TII->get(SC), Scratch)
+        .addReg(Scratch)
+        .addReg(Ptr)
+        .addImm(0);
+    BuildMI(loop2MBB, DL, TII->get(BEQ))
+        .addReg(Scratch)
+        .addReg(ZERO)
+        .addMBB(loopMBB);
+  } else {
+    BuildMI(loopMBB, DL, TII->get(SC), Scratch)
+        .addReg(Scratch)
+        .addReg(Ptr)
+        .addImm(0);
+    BuildMI(loopMBB, DL, TII->get(BEQ))
+        .addReg(Scratch)
+        .addReg(ZERO)
+        .addMBB(loopMBB);
+  }
 
   NMBBI = BB.end();
   I->eraseFromParent();
 
   LivePhysRegs LiveRegs;
   computeAndAddLiveIns(LiveRegs, *loopMBB);
+  if (!STI->hasMips4() && !STI->hasMips32()) {
+    computeAndAddLiveIns(LiveRegs, *loop1MBB);
+    computeAndAddLiveIns(LiveRegs, *loop2MBB);
+  }
   computeAndAddLiveIns(LiveRegs, *exitMBB);
 
   return true;
diff --git a/llvm/test/CodeGen/Mips/atomic-min-max.ll b/llvm/test/CodeGen/Mips/atomic-min-max.ll
index 85bf6d02c7d8f..050b3217fc577 100644
--- a/llvm/test/CodeGen/Mips/atomic-min-max.ll
+++ b/llvm/test/CodeGen/Mips/atomic-min-max.ll
@@ -3,6 +3,7 @@
 ; RUN: llc -mtriple=mips-elf -O0 -mcpu=mips32r6 -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=MIPSR6
 ; RUN: llc -mtriple=mips-elf -O0 -mcpu=mips32r2 -mattr=+micromips -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=MM
 ; RUN: llc -mtriple=mips-elf -O0 -mcpu=mips32r6 -mattr=+micromips -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=MMR6
+; RUN: llc -mtriple=mipsel-elf -O0 -mcpu=mips2 %s -o - | FileCheck %s --check-prefix=MIPS2
 ; RUN: llc -mtriple=mipsel-elf -O0 -mcpu=mips32 -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=MIPS32
 ; RUN: llc -mtriple=mipsel-elf -O0 -mcpu=mips32r2 -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=MIPSEL
 ; RUN: llc -mtriple=mipsel-elf -O0 -mcpu=mips32r6 -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=MIPSELR6
@@ -31,6 +32,33 @@ define i32 @test_max_32(ptr nocapture %ptr, i32 signext %val) {
 ; MIPS-NEXT:    jr $ra
 ; MIPS-NEXT:    nop
 ;
+; MIPS2-LABEL: test_max_32:
+; MIPS2:       # %bb.0: # %entry
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:  $BB0_1: # %entry
+; MIPS2-NEXT:    # =>This Inner Loop Header: Depth=1
+; MIPS2-NEXT:    ll $2, 0($4)
+; MIPS2-NEXT:    slt $3, $2, $5
+; MIPS2-NEXT:    move $1, $5
+; MIPS2-NEXT:    beqz $3, $BB0_3
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.2: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB0_1 Depth=1
+; MIPS2-NEXT:    j $BB0_4
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  $BB0_3: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB0_1 Depth=1
+; MIPS2-NEXT:    move $1, $2
+; MIPS2-NEXT:  $BB0_4: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB0_1 Depth=1
+; MIPS2-NEXT:    sc $1, 0($4)
+; MIPS2-NEXT:    beqz $1, $BB0_1
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.5: # %entry
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:    jr $ra
+; MIPS2-NEXT:    nop
+;
 ; MIPSR6-LABEL: test_max_32:
 ; MIPSR6:       # %bb.0: # %entry
 ; MIPSR6-NEXT:    sync
@@ -251,6 +279,33 @@ define i32 @test_min_32(ptr nocapture %ptr, i32 signext %val) {
 ; MIPS-NEXT:    jr $ra
 ; MIPS-NEXT:    nop
 ;
+; MIPS2-LABEL: test_min_32:
+; MIPS2:       # %bb.0: # %entry
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:  $BB1_1: # %entry
+; MIPS2-NEXT:    # =>This Inner Loop Header: Depth=1
+; MIPS2-NEXT:    ll $2, 0($4)
+; MIPS2-NEXT:    slt $3, $2, $5
+; MIPS2-NEXT:    move $1, $2
+; MIPS2-NEXT:    beqz $3, $BB1_3
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.2: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB1_1 Depth=1
+; MIPS2-NEXT:    j $BB1_4
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  $BB1_3: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB1_1 Depth=1
+; MIPS2-NEXT:    move $1, $5
+; MIPS2-NEXT:  $BB1_4: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB1_1 Depth=1
+; MIPS2-NEXT:    sc $1, 0($4)
+; MIPS2-NEXT:    beqz $1, $BB1_1
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.5: # %entry
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:    jr $ra
+; MIPS2-NEXT:    nop
+;
 ; MIPSR6-LABEL: test_min_32:
 ; MIPSR6:       # %bb.0: # %entry
 ; MIPSR6-NEXT:    sync
@@ -471,6 +526,33 @@ define i32 @test_umax_32(ptr nocapture %ptr, i32 signext %val) {
 ; MIPS-NEXT:    jr $ra
 ; MIPS-NEXT:    nop
 ;
+; MIPS2-LABEL: test_umax_32:
+; MIPS2:       # %bb.0: # %entry
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:  $BB2_1: # %entry
+; MIPS2-NEXT:    # =>This Inner Loop Header: Depth=1
+; MIPS2-NEXT:    ll $2, 0($4)
+; MIPS2-NEXT:    sltu $3, $2, $5
+; MIPS2-NEXT:    move $1, $5
+; MIPS2-NEXT:    beqz $3, $BB2_3
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.2: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB2_1 Depth=1
+; MIPS2-NEXT:    j $BB2_4
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  $BB2_3: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB2_1 Depth=1
+; MIPS2-NEXT:    move $1, $2
+; MIPS2-NEXT:  $BB2_4: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB2_1 Depth=1
+; MIPS2-NEXT:    sc $1, 0($4)
+; MIPS2-NEXT:    beqz $1, $BB2_1
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.5: # %entry
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:    jr $ra
+; MIPS2-NEXT:    nop
+;
 ; MIPSR6-LABEL: test_umax_32:
 ; MIPSR6:       # %bb.0: # %entry
 ; MIPSR6-NEXT:    sync
@@ -691,6 +773,33 @@ define i32 @test_umin_32(ptr nocapture %ptr, i32 signext %val) {
 ; MIPS-NEXT:    jr $ra
 ; MIPS-NEXT:    nop
 ;
+; MIPS2-LABEL: test_umin_32:
+; MIPS2:       # %bb.0: # %entry
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:  $BB3_1: # %entry
+; MIPS2-NEXT:    # =>This Inner Loop Header: Depth=1
+; MIPS2-NEXT:    ll $2, 0($4)
+; MIPS2-NEXT:    sltu $3, $2, $5
+; MIPS2-NEXT:    move $1, $2
+; MIPS2-NEXT:    beqz $3, $BB3_3
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.2: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB3_1 Depth=1
+; MIPS2-NEXT:    j $BB3_4
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  $BB3_3: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB3_1 Depth=1
+; MIPS2-NEXT:    move $1, $5
+; MIPS2-NEXT:  $BB3_4: # %entry
+; MIPS2-NEXT:    # in Loop: Header=BB3_1 Depth=1
+; MIPS2-NEXT:    sc $1, 0($4)
+; MIPS2-NEXT:    beqz $1, $BB3_1
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.5: # %entry
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:    jr $ra
+; MIPS2-NEXT:    nop
+;
 ; MIPSR6-LABEL: test_umin_32:
 ; MIPSR6:       # %bb.0: # %entry
 ; MIPSR6-NEXT:    sync
@@ -936,6 +1045,58 @@ define i16 @test_max_16(ptr nocapture %ptr, i16 signext %val) {
 ; MIPS-NEXT:    jr $ra
 ; MIPS-NEXT:    nop
 ;
+; MIPS2-LABEL: test_max_16:
+; MIPS2:       # %bb.0: # %entry
+; MIPS2-NEXT:    addiu $sp, $sp, -8
+; MIPS2-NEXT:    .cfi_def_cfa_offset 8
+; MIPS2-NEXT:    # kill: def $at killed $a1
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:    addiu $1, $zero, -4
+; MIPS2-NEXT:    and $6, $4, $1
+; MIPS2-NEXT:    andi $1, $4, 3
+; MIPS2-NEXT:    sll $10, $1, 3
+; MIPS2-NEXT:    ori $1, $zero, 65535
+; MIPS2-NEXT:    sllv $8, $1, $10
+; MIPS2-NEXT:    nor $9, $zero, $8
+; MIPS2-NEXT:    sllv $7, $5, $10
+; MIPS2-NEXT:  $BB4_1: # %entry
+; MIPS2-NEXT:    # =>This Inner Loop Header: Depth=1
+; MIPS2-NEXT:    ll $2, 0($6)
+; MIPS2-NEXT:    srav $4, $2, $10
+; MIPS2-NEXT:    sll $4, $4, 16
+; MIPS2-NEXT:    sra $4, $4, 16
+; MIPS2-NEXT:    or $1, $zero, $4
+; MIPS2-NEXT:    sllv $4, $4, $10
+; MIPS2-NEXT:    slt $5, $4, $7
+; MIPS2-NEXT:    move $3, $7
+; MIPS2-NEXT:    beqz $5, $BB4_3
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.2: # %entry
+; MIPS2-NEXT:    #   in Loop: Header=BB4_1 Depth=1
+; MIPS2-NEXT:    j $BB4_4
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  $BB4_3: # %entry
+; MIPS2-NEXT:    #   in Loop: Header=BB4_1 Depth=1
+; MIPS2-NEXT:    move $3, $4
+; MIPS2-NEXT:  $BB4_4: # %entry
+; MIPS2-NEXT:    #   in Loop: Header=BB4_1 Depth=1
+; MIPS2-NEXT:    and $3, $3, $8
+; MIPS2-NEXT:    and $4, $2, $9
+; MIPS2-NEXT:    or $4, $4, $3
+; MIPS2-NEXT:    sc $4, 0($6)
+; MIPS2-NEXT:    beqz $4, $BB4_1
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.5: # %entry
+; MIPS2-NEXT:    .insn
+; MIPS2-NEXT:  $BB4_6: # %entry
+; MIPS2-NEXT:    sw $1, 4($sp) # 4-byte Folded Spill
+; MIPS2-NEXT:  # %bb.7: # %entry
+; MIPS2-NEXT:    lw $2, 4($sp) # 4-byte Folded Reload
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:    addiu $sp, $sp, 8
+; MIPS2-NEXT:    jr $ra
+; MIPS2-NEXT:    nop
+;
 ; MIPSR6-LABEL: test_max_16:
 ; MIPSR6:       # %bb.0: # %entry
 ; MIPSR6-NEXT:    addiu $sp, $sp, -8
@@ -1476,6 +1637,58 @@ define i16 @test_min_16(ptr nocapture %ptr, i16 signext %val) {
 ; MIPS-NEXT:    jr $ra
 ; MIPS-NEXT:    nop
 ;
+; MIPS2-LABEL: test_min_16:
+; MIPS2:       # %bb.0: # %entry
+; MIPS2-NEXT:    addiu $sp, $sp, -8
+; MIPS2-NEXT:    .cfi_def_cfa_offset 8
+; MIPS2-NEXT:    # kill: def $at killed $a1
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:    addiu $1, $zero, -4
+; MIPS2-NEXT:    and $6, $4, $1
+; MIPS2-NEXT:    andi $1, $4, 3
+; MIPS2-NEXT:    sll $10, $1, 3
+; MIPS2-NEXT:    ori $1, $zero, 65535
+; MIPS2-NEXT:    sllv $8, $1, $10
+; MIPS2-NEXT:    nor $9, $zero, $8
+; MIPS2-NEXT:    sllv $7, $5, $10
+; MIPS2-NEXT:  $BB5_1: # %entry
+; MIPS2-NEXT:    # =>This Inner Loop Header: Depth=1
+; MIPS2-NEXT:    ll $2, 0($6)
+; MIPS2-NEXT:    srav $4, $2, $10
+; MIPS2-NEXT:    sll $4, $4, 16
+; MIPS2-NEXT:    sra $4, $4, 16
+; MIPS2-NEXT:    or $1, $zero, $4
+; MIPS2-NEXT:    sllv $4, $4, $10
+; MIPS2-NEXT:    slt $5, $4, $7
+; MIPS2-NEXT:    move $3, $4
+; MIPS2-NEXT:    beqz $5, $BB5_3
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.2: # %entry
+; MIPS2-NEXT:    #   in Loop: Header=BB5_1 Depth=1
+; MIPS2-NEXT:    j $BB5_4
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  $BB5_3: # %entry
+; MIPS2-NEXT:    #   in Loop: Header=BB5_1 Depth=1
+; MIPS2-NEXT:    move $3, $7
+; MIPS2-NEXT:  $BB5_4: # %entry
+; MIPS2-NEXT:    #   in Loop: Header=BB5_1 Depth=1
+; MIPS2-NEXT:    and $3, $3, $8
+; MIPS2-NEXT:    and $4, $2, $9
+; MIPS2-NEXT:    or $4, $4, $3
+; MIPS2-NEXT:    sc $4, 0($6)
+; MIPS2-NEXT:    beqz $4, $BB5_1
+; MIPS2-NEXT:    nop
+; MIPS2-NEXT:  # %bb.5: # %entry
+; MIPS2-NEXT:    .insn
+; MIPS2-NEXT:  $BB5_6: # %entry
+; MIPS2-NEXT:    sw $1, 4($sp) # 4-byte Folded Spill
+; MIPS2-NEXT:  # %bb.7: # %entry
+; MIPS2-NEXT:    lw $2, 4($sp) # 4-byte Folded Reload
+; MIPS2-NEXT:    sync
+; MIPS2-NEXT:    addiu $sp, $sp, 8
+; MIPS2-NEXT:    jr $ra
+; MIPS2-NEXT:    nop
+;
 ; MIPSR6-LABEL: test_min_16:
 ; MIPSR6:       # %bb.0: # %entry
 ; MIPSR6-NEXT:    addiu $sp, $sp, -8
@@ -2015,6 +2228,57 @@ de...
[truncated]

@Sirius902
Copy link

I built this PR from source on macOS and tried compiling the same program shown in #145411 but it seems the compiler ended up crashing.

❯ clang -c --target=mips-linux-gnu -mips2 -Oz -o main.o main.c
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: clang -c --target=mips-linux-gnu -mips2 -Oz -o main.o main.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'main.c'.
4.      Running pass 'Mips Branch Expansion Pass' on function '@min'
#0 0x00000001056704b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Users/chris/Dev/c/llvm-project/build/bin/clang-21+0x1026f44b8)
#1 0x000000010566e408 llvm::sys::RunSignalHandlers() (/Users/chris/Dev/c/llvm-project/build/bin/clang-21+0x1026f2408)
#2 0x000000010566f9b8 llvm::sys::CleanupOnSignal(unsigned long) (/Users/chris/Dev/c/llvm-project/build/bin/clang-21+0x1026f39b8)
#3 0x00000001055b6de8 CrashRecoverySignalHandler(int) (/Users/chris/Dev/c/llvm-project/build/bin/clang-21+0x10263ade8)
#4 0x000000019d114624 (/usr/lib/system/libsystem_platform.dylib+0x1804ac624)
#5 0x0000000103b4dec4 (anonymous namespace)::MipsBranchExpansion::handlePossibleLongBranch() (/Users/chris/Dev/c/llvm-project/build/bin/clang-21+0x100bd1ec4)
#6 0x0000000103b4dec4 (anonymous namespace)::MipsBranchExpansion::handlePossibleLongBranch() (/Users/chris/Dev/c/llvm-project/build/bin/clang-21+0x100bd1ec4)
clang: error: clang frontend command failed with exit code 139 (use -v to see invocation)
clang version 21.0.0git ([email protected]:yingopq/llvm-project.git 74af81c71078cdaf647d4435ee4c448edd88e8b8)
Target: mips-unknown-linux-gnu
Thread model: posix
InstalledDir: /Users/chris/Dev/c/llvm-project/build/bin
clang: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /var/folders/tr/9sy58s854pj87w4pzstgbjcw0000gn/T/main-4881f1.c
clang: note: diagnostic msg: /var/folders/tr/9sy58s854pj87w4pzstgbjcw0000gn/T/main-4881f1.sh
clang: note: diagnostic msg: Crash backtrace is located in
clang: note: diagnostic msg: /Users/chris/Library/Logs/DiagnosticReports/clang-21_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
clang: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
clang: note: diagnostic msg:

********************

@yingopq
Copy link
Contributor Author

yingopq commented Jul 31, 2025

Thanks, I would see this error.
I tested this issue using sudo ./build/bin/clang --target=mipsel-unknown-linux-gnu -march=mips2 -emit-llvm -S 1.c and sudo ./build/bin/clang --target=mipsel-unknown-linux-gnu -fuse-ld=/usr/bin/mipsel-linux-gnu-ld 1.ll -o a1main, so I did not find this error.

@yingopq yingopq force-pushed the Fix_bug_issue_145411 branch from 74af81c to cea3ce0 Compare August 1, 2025 07:21
@yingopq
Copy link
Contributor Author

yingopq commented Aug 1, 2025

Hi @Sirius902,
I have fixed this error, could you help test again, thanks!

@yingopq yingopq force-pushed the Fix_bug_issue_145411 branch from cea3ce0 to 1e6567f Compare August 1, 2025 08:33
@Sirius902
Copy link

Hi @Sirius902, I have fixed this error, could you help test again, thanks!

Looks good to me, thanks! :)

❯ objdump -d main.o

main.o: file format elf32-mips

Disassembly of section .text:

00000000 <min>:
       0: 00 00 00 0f   sync <min>
       4: c0 82 00 00   ll      $2, 0x0($4)
       8: 00 45 18 2a   slt     $3, $2, $5
       c: 10 60 00 03   beqz    $3, 0x1c <min+0x1c>
      10: 00 40 08 25   move    $1, $2
      14: 10 00 00 02   b       0x20 <min+0x20>
      18: 00 00 00 00   nop <min>
      1c: 00 a0 08 25   move    $1, $5
      20: e0 81 00 00   sc      $1, 0x0($4)
      24: 10 20 ff f7   beqz    $1, 0x4 <min+0x4>
      28: 00 00 00 00   nop <min>
      2c: 00 00 00 0f   sync <min>
      30: 03 e0 00 08   jr      $ra
      34: 00 00 00 00   nop <min>

00000038 <max>:
      38: 00 00 00 0f   sync <min>
      3c: c0 82 00 00   ll      $2, 0x0($4)
      40: 00 45 18 2a   slt     $3, $2, $5
      44: 10 60 00 03   beqz    $3, 0x54 <max+0x1c>
      48: 00 a0 08 25   move    $1, $5
      4c: 10 00 00 02   b       0x58 <max+0x20>
      50: 00 00 00 00   nop <min>
      54: 00 40 08 25   move    $1, $2
      58: e0 81 00 00   sc      $1, 0x0($4)
      5c: 10 20 ff f7   beqz    $1, 0x3c <max+0x4>
      60: 00 00 00 00   nop <min>
      64: 00 00 00 0f   sync <min>
      68: 03 e0 00 08   jr      $ra
      6c: 00 00 00 00   nop <min>

@brad0
Copy link
Contributor

brad0 commented Aug 1, 2025

cc @wzssyqa @topperc @MaskRay

@brad0
Copy link
Contributor

brad0 commented Aug 17, 2025

cc @arsenm @topperc

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason mips is reinventing all this stuff in a machine pass? AtomicExpand should already handle all of this?

@yingopq
Copy link
Contributor Author

yingopq commented Aug 19, 2025

Is there a reason mips is reinventing all this stuff in a machine pass? AtomicExpand should already handle all of this?

Sorry, I did not find this reason.

@yingopq
Copy link
Contributor Author

yingopq commented Aug 21, 2025

Is there a reason mips is reinventing all this stuff in a machine pass? AtomicExpand should already handle all of this?

@nikic Did you the reason? Thanks.

@nikic
Copy link
Contributor

nikic commented Aug 21, 2025

I think this is related to the problems in #25900 / #31368, where it's invalid to introduce additional intermediate stores from spilling.

@jrtc27
Copy link
Collaborator

jrtc27 commented Aug 21, 2025

Yeah AtomicExpand is fundamentally broken for LL/SC expansion unless your architecture places no limits on the number and type of instructions that can appear between the LL and SC.

@brad0
Copy link
Contributor

brad0 commented Aug 28, 2025

@arsenm Ping.

@yingopq
Copy link
Contributor Author

yingopq commented Sep 16, 2025

@arsenm Can you help review again?

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but we should probably do something about the atomic expand LLSC issue generically. AArch64 has that totally busted assumption about which RA is in use

@yingopq
Copy link
Contributor Author

yingopq commented Sep 17, 2025

LGTM but we should probably do something about the atomic expand LLSC issue generically. AArch64 has that totally busted assumption about which RA is in use

Thanks, I will continue to investigate later.

@yingopq yingopq enabled auto-merge (squash) September 17, 2025 09:36
@yingopq yingopq merged commit b7f68cb into llvm:main Sep 17, 2025
9 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 17, 2025

LLVM Buildbot has detected a new failure on builder lldb-x86_64-debian running on lldb-x86_64-debian while building llvm at step 6 "test".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/162/builds/31301

Here is the relevant piece of the build log for the reference
Step 6 (test) failure: build (failure)
...
PASS: lldb-api :: functionalities/thread/backtrace_limit/TestBacktraceLimit.py (860 of 3192)
PASS: lldb-api :: lang/cpp/crtp/TestCppCRTP.py (861 of 3192)
PASS: lldb-shell :: ObjectFile/ELF/many-sections.s (862 of 3192)
PASS: lldb-api :: python_api/section/TestSectionAPI.py (863 of 3192)
PASS: lldb-shell :: Register/x86-multithread-read.test (864 of 3192)
PASS: lldb-api :: commands/disassemble/basic/TestFrameDisassemble.py (865 of 3192)
PASS: lldb-shell :: Commands/command-expr-diagnostics.test (866 of 3192)
PASS: lldb-api :: commands/frame/var-dil/basics/Indirection/TestFrameVarDILIndirection.py (867 of 3192)
PASS: lldb-api :: lang/cpp/alignas_base_class/TestAlignAsBaseClass.py (868 of 3192)
PASS: lldb-api :: commands/target/create-no-such-arch/TestNoSuchArch.py (869 of 3192)
FAIL: lldb-api :: functionalities/postmortem/netbsd-core/TestNetBSDCore.py (870 of 3192)
******************** TEST 'lldb-api :: functionalities/postmortem/netbsd-core/TestNetBSDCore.py' FAILED ********************
Script:
--
/usr/bin/python3 /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/dotest.py -u CXXFLAGS -u CFLAGS --env LLVM_LIBS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./lib --env LLVM_INCLUDE_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/include --env LLVM_TOOLS_DIR=/home/worker/2.0.1/lldb-x86_64-debian/build/./bin --arch x86_64 --build-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex --lldb-module-cache-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-lldb/lldb-api --clang-module-cache-dir /home/worker/2.0.1/lldb-x86_64-debian/build/lldb-test-build.noindex/module-cache-clang/lldb-api --executable /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/lldb --compiler /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/clang --dsymutil /home/worker/2.0.1/lldb-x86_64-debian/build/./bin/dsymutil --make /usr/bin/gmake --llvm-tools-dir /home/worker/2.0.1/lldb-x86_64-debian/build/./bin --lldb-obj-root /home/worker/2.0.1/lldb-x86_64-debian/build/tools/lldb --lldb-libs-dir /home/worker/2.0.1/lldb-x86_64-debian/build/./lib --cmake-build-type Release -t /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/functionalities/postmortem/netbsd-core -p TestNetBSDCore.py
--
Exit Code: -6

Command Output (stdout):
--
lldb version 22.0.0git (https://github.com/llvm/llvm-project.git revision b7f68cb08ca6e6d4a935640e8065d54b1590d144)
  clang revision b7f68cb08ca6e6d4a935640e8065d54b1590d144
  llvm revision b7f68cb08ca6e6d4a935640e8065d54b1590d144
Skipping the following test categories: ['libc++', 'msvcstl', 'dsym', 'gmodules', 'debugserver', 'objc']

--
Command Output (stderr):
--
Change dir to: /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/API/functionalities/postmortem/netbsd-core
runCmd: settings clear --all

output: 

runCmd: settings set symbols.enable-external-lookup false

output: 

runCmd: settings set target.inherit-tcc true

output: 

runCmd: settings set target.disable-aslr false

output: 

runCmd: settings set target.detach-on-error false

output: 


@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 17, 2025

LLVM Buildbot has detected a new failure on builder ml-opt-dev-x86-64 running on ml-opt-dev-x86-64-b1 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/137/builds/25679

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: CodeGen/WebAssembly/cfg-stackify-eh.ll' FAILED ********************
Exit Code: -6

Command Output (stdout):
--
# RUN: at line 2
/b/ml-opt-dev-x86-64-b1/build/bin/llc < /b/ml-opt-dev-x86-64-b1/llvm-project/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh.ll -disable-wasm-fallthrough-return-opt -disable-block-placement -verify-machineinstrs -fast-isel=false -machine-sink-split-probability-threshold=0 -cgp-freq-ratio-to-skip-merge=1000 -wasm-enable-eh -wasm-use-legacy-eh=false -exception-model=wasm -mattr=+exception-handling,bulk-memory | /b/ml-opt-dev-x86-64-b1/build/bin/FileCheck /b/ml-opt-dev-x86-64-b1/llvm-project/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh.ll
# executed command: /b/ml-opt-dev-x86-64-b1/build/bin/llc -disable-wasm-fallthrough-return-opt -disable-block-placement -verify-machineinstrs -fast-isel=false -machine-sink-split-probability-threshold=0 -cgp-freq-ratio-to-skip-merge=1000 -wasm-enable-eh -wasm-use-legacy-eh=false -exception-model=wasm -mattr=+exception-handling,bulk-memory
# executed command: /b/ml-opt-dev-x86-64-b1/build/bin/FileCheck /b/ml-opt-dev-x86-64-b1/llvm-project/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh.ll
# RUN: at line 3
/b/ml-opt-dev-x86-64-b1/build/bin/llc < /b/ml-opt-dev-x86-64-b1/llvm-project/llvm/test/CodeGen/WebAssembly/cfg-stackify-eh.ll -disable-wasm-fallthrough-return-opt -disable-block-placement -verify-machineinstrs -fast-isel=false -machine-sink-split-probability-threshold=0 -cgp-freq-ratio-to-skip-merge=1000 -wasm-enable-eh -wasm-use-legacy-eh=false -exception-model=wasm -mattr=+exception-handling,bulk-memory
# executed command: /b/ml-opt-dev-x86-64-b1/build/bin/llc -disable-wasm-fallthrough-return-opt -disable-block-placement -verify-machineinstrs -fast-isel=false -machine-sink-split-probability-threshold=0 -cgp-freq-ratio-to-skip-merge=1000 -wasm-enable-eh -wasm-use-legacy-eh=false -exception-model=wasm -mattr=+exception-handling,bulk-memory
# .---command stderr------------
# | llc: /b/ml-opt-dev-x86-64-b1/llvm-project/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From *) [To = llvm::Instruction, From = llvm::User]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' failed.
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
# | Stack dump:
# | 0.	Program arguments: /b/ml-opt-dev-x86-64-b1/build/bin/llc -disable-wasm-fallthrough-return-opt -disable-block-placement -verify-machineinstrs -fast-isel=false -machine-sink-split-probability-threshold=0 -cgp-freq-ratio-to-skip-merge=1000 -wasm-enable-eh -wasm-use-legacy-eh=false -exception-model=wasm -mattr=+exception-handling,bulk-memory
# | 1.	Running pass 'Function Pass Manager' on module '<stdin>'.
# | 2.	Running pass 'Windows exception handling preparation' on function '@exception_grouping_2'
# |  #0 0x00005577b319ead8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/b/ml-opt-dev-x86-64-b1/build/bin/llc+0x7c5fad8)
# |  #1 0x00005577b319c1f5 llvm::sys::RunSignalHandlers() (/b/ml-opt-dev-x86-64-b1/build/bin/llc+0x7c5d1f5)
# |  #2 0x00005577b319f851 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
# |  #3 0x00007fbf4f65a050 (/lib/x86_64-linux-gnu/libc.so.6+0x3c050)
# |  #4 0x00007fbf4f6a8eec (/lib/x86_64-linux-gnu/libc.so.6+0x8aeec)
# |  #5 0x00007fbf4f659fb2 raise (/lib/x86_64-linux-gnu/libc.so.6+0x3bfb2)
# |  #6 0x00007fbf4f644472 abort (/lib/x86_64-linux-gnu/libc.so.6+0x26472)
# |  #7 0x00007fbf4f644395 (/lib/x86_64-linux-gnu/libc.so.6+0x26395)
# |  #8 0x00007fbf4f652ec2 (/lib/x86_64-linux-gnu/libc.so.6+0x34ec2)
# |  #9 0x00005577b31df5c5 llvm::detachDeadBlocks(llvm::ArrayRef<llvm::BasicBlock*>, llvm::SmallVectorImpl<llvm::cfg::Update<llvm::BasicBlock*>>*, bool) (/b/ml-opt-dev-x86-64-b1/build/bin/llc+0x7ca05c5)
# | #10 0x00005577b31dfdd4 llvm::DeleteDeadBlocks(llvm::ArrayRef<llvm::BasicBlock*>, llvm::DomTreeUpdater*, bool) (/b/ml-opt-dev-x86-64-b1/build/bin/llc+0x7ca0dd4)
# | #11 0x00005577b3262565 llvm::removeUnreachableBlocks(llvm::Function&, llvm::DomTreeUpdater*, llvm::MemorySSAUpdater*) (/b/ml-opt-dev-x86-64-b1/build/bin/llc+0x7d23565)
# | #12 0x00005577b2567e23 (anonymous namespace)::WinEHPrepareImpl::prepareExplicitEH(llvm::Function&) WinEHPrepare.cpp:0:0
# | #13 0x00005577b2567de5 (anonymous namespace)::WinEHPrepare::runOnFunction(llvm::Function&) WinEHPrepare.cpp:0:0
# | #14 0x00005577b27411f5 llvm::FPPassManager::runOnFunction(llvm::Function&) (/b/ml-opt-dev-x86-64-b1/build/bin/llc+0x72021f5)
# | #15 0x00005577b2749072 llvm::FPPassManager::runOnModule(llvm::Module&) (/b/ml-opt-dev-x86-64-b1/build/bin/llc+0x720a072)
# | #16 0x00005577b2741c66 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/b/ml-opt-dev-x86-64-b1/build/bin/llc+0x7202c66)
# | #17 0x00005577b01817ee compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
# | #18 0x00005577b017eded main (/b/ml-opt-dev-x86-64-b1/build/bin/llc+0x4c3fded)
# | #19 0x00007fbf4f64524a (/lib/x86_64-linux-gnu/libc.so.6+0x2724a)
# | #20 0x00007fbf4f645305 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27305)
# | #21 0x00005577b017ad61 _start (/b/ml-opt-dev-x86-64-b1/build/bin/llc+0x4c3bd61)
# `-----------------------------
# error: command failed with exit status: -6

--

********************


@vvereschaka
Copy link
Contributor

@yingopq

https://lab.llvm.org/buildbot/#/builders/187/builds/11459

broken atomic-min-max.ll test on the expensive builder

******************** TEST 'LLVM :: CodeGen/Mips/atomic-min-max.ll' FAILED ********************
Exit Code: 1
Command Output (stdout):
--
# RUN: at line 2
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r2 -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o - | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPS
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r2 -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPS
# RUN: at line 3
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r6 -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o - | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPSR6
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r6 -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPSR6
# RUN: at line 4
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r2 -mattr=+micromips -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o - | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MM
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r2 -mattr=+micromips -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MM
# RUN: at line 5
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r6 -mattr=+micromips -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o - | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MMR6
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r6 -mattr=+micromips -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MMR6
# RUN: at line 6
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mipsel-elf -O0 -mcpu=mips2 /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o - | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPS2
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mipsel-elf -O0 -mcpu=mips2 /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# .---command stderr------------
# | 
# | # After Mips pseudo instruction expansion pass
# | # Machine code for function test_max_16: NoPHIs, TracksLiveness, NoVRegs, TiedOpsRewritten
# | Frame Objects:
# |   fi#0: size=4, align=4, at location [SP-4]
# | save/restore points:
# | save points are empty
# | restore points are empty
# | Function Live Ins: $a0, $a1
# | 
# | bb.0.entry:
# |   successors: %bb.1(0x80000000); %bb.1(100.00%)
# |   liveins: $a0, $a1
# |   $sp = ADDiu $sp, -8
# |   CFI_INSTRUCTION def_cfa_offset 8
# |   dead renamable $at = KILL renamable $a1
# |   SYNC 0
# |   renamable $at = ADDiu $zero, -4
# |   renamable $a2 = AND renamable $a0, killed renamable $at
# |   renamable $at = ANDi killed renamable $a0, 3
# |   renamable $t2 = SLL killed renamable $at, 3
# |   renamable $at = ORi $zero, 65535
# |   renamable $t0 = SLLV killed renamable $at, renamable $t2
# |   renamable $t1 = NOR $zero, renamable $t0
# |   renamable $a3 = SLLV killed renamable $a1, renamable $t2
# | 
# | bb.1.entry:
# | ; predecessors: %bb.0, %bb.3
# |   successors: %bb.2(0x40000000), %bb.3(0x40000000); %bb.2(50.00%), %bb.3(50.00%)
# |   liveins: $a3, $t2, $a2
# |   $v0 = LL $a2, 0
# |   $a0 = SRAV $v0, $t2
# |   $a0 = SLL killed $a0, 16
# |   $a0 = SRA killed $a0, 16
# |   $at = OR $zero, $a0
# |   $a0 = SLLV $a0, $t2
# |   $a1 = SLT $a0, $a3
# |   $v1 = OR $a3, $zero
# |   BEQ $a1, $zero, %bb.2, implicit-def $at
# |   B %bb.3, implicit-def $at
# | 
# | bb.2.entry:
# | ; predecessors: %bb.1
# |   successors: %bb.3(0x80000000); %bb.3(100.00%)
# |   liveins: $a0
# |   $v1 = OR $a0, $zero
# | 
# | bb.3.entry:
# | ; predecessors: %bb.1, %bb.2
# |   successors: %bb.1(0x00000000), %bb.5(0x80000000); %bb.1(0.00%), %bb.5(100.00%)
# |   liveins: $a3, $t2, $a2, $t1, $v0, $v1, $t0
# |   $v1 = AND $v1, $t0
# |   $a0 = AND $v0, $t1
# |   $a0 = OR $a0, $v1
# |   $a0 = SC $a0(tied-def 0), $a2, 0
# |   BEQ $a0, $zero, %bb.1, implicit-def $at
# | 
# | bb.4.entry:
# | 
# | bb.5.entry:
# | ; predecessors: %bb.3
# |   successors: %bb.6(0x80000000); %bb.6(100.00%)
# |   liveins: $at
# |   SW killed $at, $sp, 4 :: (store (s32) into %stack.0)
# | 
# | bb.6.entry:
# | ; predecessors: %bb.5
# | 
# |   $v0 = LW $sp, 4 :: (load (s32) from %stack.0)
# |   SYNC 0
# |   $sp = ADDiu $sp, 8
# |   PseudoReturn undef $ra, implicit killed $v0
# | 
# | # End machine code for function test_max_16.
# | 
# | *** Bad machine code: MBB exits via conditional branch/fall-through but the CFG successors don't match the actual successors! ***
# | - function:    test_max_16
# | - basic block: %bb.3 entry (0x5c77e2bdab88)
# | 
# | *** Bad machine code: MBB has unexpected successors which are not branch targets, fallthrough, EHPads, or inlineasm_br targets. ***
# | - function:    test_max_16
# | - basic block: %bb.3 entry (0x5c77e2bdab88)
# | LLVM ERROR: Found 2 machine code errors.
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
# | Stack dump:
# | 0.	Program arguments: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mipsel-elf -O0 -mcpu=mips2 /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# | 1.	Running pass 'Function Pass Manager' on module '/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll'.
# | 2.	Running pass 'Verify generated machine code' on function '@test_max_16'
# |  #0 0x00005c77bfa75808 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x7bc9808)
# |  #1 0x00005c77bfa72f15 llvm::sys::RunSignalHandlers() (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x7bc6f15)
# |  #2 0x00005c77bfa765d1 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
# |  #3 0x00007c2f22c45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
# |  #4 0x00007c2f22c9eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
# |  #5 0x00007c2f22c4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
# |  #6 0x00007c2f22c288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
# |  #7 0x00005c77bf9dbaf5 llvm::report_fatal_error(llvm::Twine const&, bool) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x7b2faf5)
# |  #8 0x00005c77bebbc5fe (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x6d105fe)
# |  #9 0x00005c77bebbd5db (anonymous namespace)::MachineVerifierLegacyPass::runOnMachineFunction(llvm::MachineFunction&) MachineVerifier.cpp:0:0
# | #10 0x00005c77bea9a543 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x6bee543)
# | #11 0x00005c77beff180b llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x714580b)
# | #12 0x00005c77beff9872 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x714d872)
# | #13 0x00005c77beff232a llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x714632a)
# | #14 0x00005c77bc9da459 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
# | #15 0x00005c77bc9d7a9d main (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x4b2ba9d)
# | #16 0x00007c2f22c2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
# | #17 0x00007c2f22c2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
# | #18 0x00005c77bc9d39e5 _start (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x4b279e5)
# `-----------------------------
# error: command failed with exit status: -6
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPS2
# .---command stderr------------
# | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll:1048:16: error: MIPS2-LABEL: expected string not found in input
# | ; MIPS2-LABEL: test_max_16:
# |                ^
# | <stdin>:154:14: note: scanning from here
# | test_umin_32: 
# |              ^
# | 
# | Input file: <stdin>
# | Check file: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             .
# |             .
# |             .
# |           149:  .p2align 2 
# |           150:  .type test_umin_32,@function 
# |           151:  .set nomicromips 
# |           152:  .set nomips16 
# |           153:  .ent test_umin_32 
# |           154: test_umin_32: 
# | label:1048                  X error: no match found
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1
--
********************

@yingopq
Copy link
Contributor Author

yingopq commented Sep 18, 2025

@yingopq

https://lab.llvm.org/buildbot/#/builders/187/builds/11459

broken atomic-min-max.ll test on the expensive builder

******************** TEST 'LLVM :: CodeGen/Mips/atomic-min-max.ll' FAILED ********************
Exit Code: 1
Command Output (stdout):
--
# RUN: at line 2
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r2 -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o - | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPS
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r2 -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPS
# RUN: at line 3
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r6 -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o - | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPSR6
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r6 -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPSR6
# RUN: at line 4
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r2 -mattr=+micromips -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o - | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MM
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r2 -mattr=+micromips -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MM
# RUN: at line 5
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r6 -mattr=+micromips -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o - | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MMR6
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mips-elf -O0 -mcpu=mips32r6 -mattr=+micromips -verify-machineinstrs /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MMR6
# RUN: at line 6
/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mipsel-elf -O0 -mcpu=mips2 /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o - | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPS2
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mipsel-elf -O0 -mcpu=mips2 /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# .---command stderr------------
# | 
# | # After Mips pseudo instruction expansion pass
# | # Machine code for function test_max_16: NoPHIs, TracksLiveness, NoVRegs, TiedOpsRewritten
# | Frame Objects:
# |   fi#0: size=4, align=4, at location [SP-4]
# | save/restore points:
# | save points are empty
# | restore points are empty
# | Function Live Ins: $a0, $a1
# | 
# | bb.0.entry:
# |   successors: %bb.1(0x80000000); %bb.1(100.00%)
# |   liveins: $a0, $a1
# |   $sp = ADDiu $sp, -8
# |   CFI_INSTRUCTION def_cfa_offset 8
# |   dead renamable $at = KILL renamable $a1
# |   SYNC 0
# |   renamable $at = ADDiu $zero, -4
# |   renamable $a2 = AND renamable $a0, killed renamable $at
# |   renamable $at = ANDi killed renamable $a0, 3
# |   renamable $t2 = SLL killed renamable $at, 3
# |   renamable $at = ORi $zero, 65535
# |   renamable $t0 = SLLV killed renamable $at, renamable $t2
# |   renamable $t1 = NOR $zero, renamable $t0
# |   renamable $a3 = SLLV killed renamable $a1, renamable $t2
# | 
# | bb.1.entry:
# | ; predecessors: %bb.0, %bb.3
# |   successors: %bb.2(0x40000000), %bb.3(0x40000000); %bb.2(50.00%), %bb.3(50.00%)
# |   liveins: $a3, $t2, $a2
# |   $v0 = LL $a2, 0
# |   $a0 = SRAV $v0, $t2
# |   $a0 = SLL killed $a0, 16
# |   $a0 = SRA killed $a0, 16
# |   $at = OR $zero, $a0
# |   $a0 = SLLV $a0, $t2
# |   $a1 = SLT $a0, $a3
# |   $v1 = OR $a3, $zero
# |   BEQ $a1, $zero, %bb.2, implicit-def $at
# |   B %bb.3, implicit-def $at
# | 
# | bb.2.entry:
# | ; predecessors: %bb.1
# |   successors: %bb.3(0x80000000); %bb.3(100.00%)
# |   liveins: $a0
# |   $v1 = OR $a0, $zero
# | 
# | bb.3.entry:
# | ; predecessors: %bb.1, %bb.2
# |   successors: %bb.1(0x00000000), %bb.5(0x80000000); %bb.1(0.00%), %bb.5(100.00%)
# |   liveins: $a3, $t2, $a2, $t1, $v0, $v1, $t0
# |   $v1 = AND $v1, $t0
# |   $a0 = AND $v0, $t1
# |   $a0 = OR $a0, $v1
# |   $a0 = SC $a0(tied-def 0), $a2, 0
# |   BEQ $a0, $zero, %bb.1, implicit-def $at
# | 
# | bb.4.entry:
# | 
# | bb.5.entry:
# | ; predecessors: %bb.3
# |   successors: %bb.6(0x80000000); %bb.6(100.00%)
# |   liveins: $at
# |   SW killed $at, $sp, 4 :: (store (s32) into %stack.0)
# | 
# | bb.6.entry:
# | ; predecessors: %bb.5
# | 
# |   $v0 = LW $sp, 4 :: (load (s32) from %stack.0)
# |   SYNC 0
# |   $sp = ADDiu $sp, 8
# |   PseudoReturn undef $ra, implicit killed $v0
# | 
# | # End machine code for function test_max_16.
# | 
# | *** Bad machine code: MBB exits via conditional branch/fall-through but the CFG successors don't match the actual successors! ***
# | - function:    test_max_16
# | - basic block: %bb.3 entry (0x5c77e2bdab88)
# | 
# | *** Bad machine code: MBB has unexpected successors which are not branch targets, fallthrough, EHPads, or inlineasm_br targets. ***
# | - function:    test_max_16
# | - basic block: %bb.3 entry (0x5c77e2bdab88)
# | LLVM ERROR: Found 2 machine code errors.
# | PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
# | Stack dump:
# | 0.	Program arguments: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc -mtriple=mipsel-elf -O0 -mcpu=mips2 /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll -o -
# | 1.	Running pass 'Function Pass Manager' on module '/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll'.
# | 2.	Running pass 'Verify generated machine code' on function '@test_max_16'
# |  #0 0x00005c77bfa75808 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x7bc9808)
# |  #1 0x00005c77bfa72f15 llvm::sys::RunSignalHandlers() (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x7bc6f15)
# |  #2 0x00005c77bfa765d1 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
# |  #3 0x00007c2f22c45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
# |  #4 0x00007c2f22c9eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
# |  #5 0x00007c2f22c4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
# |  #6 0x00007c2f22c288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
# |  #7 0x00005c77bf9dbaf5 llvm::report_fatal_error(llvm::Twine const&, bool) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x7b2faf5)
# |  #8 0x00005c77bebbc5fe (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x6d105fe)
# |  #9 0x00005c77bebbd5db (anonymous namespace)::MachineVerifierLegacyPass::runOnMachineFunction(llvm::MachineFunction&) MachineVerifier.cpp:0:0
# | #10 0x00005c77bea9a543 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x6bee543)
# | #11 0x00005c77beff180b llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x714580b)
# | #12 0x00005c77beff9872 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x714d872)
# | #13 0x00005c77beff232a llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x714632a)
# | #14 0x00005c77bc9da459 compileModule(char**, llvm::LLVMContext&) llc.cpp:0:0
# | #15 0x00005c77bc9d7a9d main (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x4b2ba9d)
# | #16 0x00007c2f22c2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
# | #17 0x00007c2f22c2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
# | #18 0x00005c77bc9d39e5 _start (/home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/llc+0x4b279e5)
# `-----------------------------
# error: command failed with exit status: -6
# executed command: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/build/bin/FileCheck /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll --check-prefix=MIPS2
# .---command stderr------------
# | /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll:1048:16: error: MIPS2-LABEL: expected string not found in input
# | ; MIPS2-LABEL: test_max_16:
# |                ^
# | <stdin>:154:14: note: scanning from here
# | test_umin_32: 
# |              ^
# | 
# | Input file: <stdin>
# | Check file: /home/buildbot/worker/as-builder-4/ramdisk/expensive-checks/llvm-project/llvm/test/CodeGen/Mips/atomic-min-max.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             .
# |             .
# |             .
# |           149:  .p2align 2 
# |           150:  .type test_umin_32,@function 
# |           151:  .set nomicromips 
# |           152:  .set nomips16 
# |           153:  .ent test_umin_32 
# |           154: test_umin_32: 
# | label:1048                  X error: no match found
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1
--
********************

Sorry, I would check this and revert this now.

yingopq added a commit that referenced this pull request Sep 18, 2025
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Sep 18, 2025
yingopq added a commit to yingopq/llvm-project that referenced this pull request Sep 25, 2025
…for mips2

Modify instr movn/movz to mixture of beq, move, and sc.

Because atomic-min-max.ll test broken on the expensive builder, I revert
llvm#149983 and resubmit this PR.

The broken reason:
  In i16/i8 function expandAtomicBinOpSubword, we use two successor
after loop2MBB, one does not specify the second parameter, the other
use BranchProbability::getOne() that means 100% probability. This is
contradictory. And the second successor is also specified incorrectly.

The changess:
* llvm/lib/Target/Mips/MipsExpandPseudo.cpp:
  Change loop2MBB`s second successor to correct one and delete the
second parameter BranchProbability::getOne().
* llvm/test/CodeGen/Mips/atomic-min-max.ll:
  Add -verify-machineinstrs option in RUN command;
  Modify i16 test and i8 test according to the changes.

Fix llvm#145411.
brad0 pushed a commit that referenced this pull request Sep 26, 2025
…for mips2 (#159717)

Modify instr movn/movz to mixture of beq, move, and sc.

Because atomic-min-max.ll test broken on the expensive builder, I revert
#149983 and resubmit this PR.
The broken reason:
  In i16/i8 function expandAtomicBinOpSubword, we use two successor
after loop2MBB, one does not specify the second parameter, the other
use BranchProbability::getOne() that means 100% probability. This is
contradictory. And the second successor is also specified incorrectly.

The changess:
* llvm/lib/Target/Mips/MipsExpandPseudo.cpp:
  Change loop2MBB`s second successor to correct one and delete the
second parameter BranchProbability::getOne().
* llvm/test/CodeGen/Mips/atomic-min-max.ll:
  Add -verify-machineinstrs option in RUN command;
  Modify i16 test and i8 test according to the changes.

Fix #145411.
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Sep 26, 2025
… compiling for mips2 (#159717)

Modify instr movn/movz to mixture of beq, move, and sc.

Because atomic-min-max.ll test broken on the expensive builder, I revert
llvm/llvm-project#149983 and resubmit this PR.
The broken reason:
  In i16/i8 function expandAtomicBinOpSubword, we use two successor
after loop2MBB, one does not specify the second parameter, the other
use BranchProbability::getOne() that means 100% probability. This is
contradictory. And the second successor is also specified incorrectly.

The changess:
* llvm/lib/Target/Mips/MipsExpandPseudo.cpp:
  Change loop2MBB`s second successor to correct one and delete the
second parameter BranchProbability::getOne().
* llvm/test/CodeGen/Mips/atomic-min-max.ll:
  Add -verify-machineinstrs option in RUN command;
  Modify i16 test and i8 test according to the changes.

Fix #145411.
dyung pushed a commit to llvmbot/llvm-project that referenced this pull request Oct 1, 2025
…for mips2 (llvm#159717)

Modify instr movn/movz to mixture of beq, move, and sc.

Because atomic-min-max.ll test broken on the expensive builder, I revert
llvm#149983 and resubmit this PR.
The broken reason:
  In i16/i8 function expandAtomicBinOpSubword, we use two successor
after loop2MBB, one does not specify the second parameter, the other
use BranchProbability::getOne() that means 100% probability. This is
contradictory. And the second successor is also specified incorrectly.

The changess:
* llvm/lib/Target/Mips/MipsExpandPseudo.cpp:
  Change loop2MBB`s second successor to correct one and delete the
second parameter BranchProbability::getOne().
* llvm/test/CodeGen/Mips/atomic-min-max.ll:
  Add -verify-machineinstrs option in RUN command;
  Modify i16 test and i8 test according to the changes.

Fix llvm#145411.

(cherry picked from commit 114b3b8)
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Oct 3, 2025
…for mips2 (llvm#159717)

Modify instr movn/movz to mixture of beq, move, and sc.

Because atomic-min-max.ll test broken on the expensive builder, I revert
llvm#149983 and resubmit this PR.
The broken reason:
  In i16/i8 function expandAtomicBinOpSubword, we use two successor
after loop2MBB, one does not specify the second parameter, the other
use BranchProbability::getOne() that means 100% probability. This is
contradictory. And the second successor is also specified incorrectly.

The changess:
* llvm/lib/Target/Mips/MipsExpandPseudo.cpp:
  Change loop2MBB`s second successor to correct one and delete the
second parameter BranchProbability::getOne().
* llvm/test/CodeGen/Mips/atomic-min-max.ll:
  Add -verify-machineinstrs option in RUN command;
  Modify i16 test and i8 test according to the changes.

Fix llvm#145411.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[clang] mips4 instructions generated when compiling for mips2

9 participants