Skip to content

Conversation

@ppenzin
Copy link
Contributor

@ppenzin ppenzin commented Dec 4, 2025

Previously there was an implicit assumption in the code that a CSR can only be saved in one location. There can be scenarios where CSR is saved in different locations.

This has been split out from @mgudim's save_csr_in_ra3 (from #90819), and is PR 1 out of 5.

Co-authored-by: Mikhail Gudim mgudim@ventanamicro.com

Previously there was an implicit assumption in the code that a CSR can
only be saved in one location. There can be scenarious where CSR is
saved in different locations.
@llvmbot
Copy link
Member

llvmbot commented Dec 4, 2025

@llvm/pr-subscribers-backend-risc-v

Author: Petr Penzin (ppenzin)

Changes

Previously there was an implicit assumption in the code that a CSR can only be saved in one location. There can be scenarios where CSR is saved in different locations.

This has been split out from https://github.com/mgudim/llvm-project/tree/save_csr_in_ra3, and is PR 1 out of 5.

Co-authored-by: Mikhail Gudim <mgudim@ventanamicro.com>


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

2 Files Affected:

  • (modified) llvm/lib/CodeGen/CFIInstrInserter.cpp (+197-145)
  • (modified) llvm/test/CodeGen/RISCV/cfi-multiple-locations.mir (+34-6)
diff --git a/llvm/lib/CodeGen/CFIInstrInserter.cpp b/llvm/lib/CodeGen/CFIInstrInserter.cpp
index 1a0e222da98cd..667928304df50 100644
--- a/llvm/lib/CodeGen/CFIInstrInserter.cpp
+++ b/llvm/lib/CodeGen/CFIInstrInserter.cpp
@@ -66,72 +66,103 @@ class CFIInstrInserter : public MachineFunctionPass {
   }
 
  private:
-  struct MBBCFAInfo {
-    MachineBasicBlock *MBB;
-    /// Value of cfa offset valid at basic block entry.
-    int64_t IncomingCFAOffset = -1;
-    /// Value of cfa offset valid at basic block exit.
-    int64_t OutgoingCFAOffset = -1;
-    /// Value of cfa register valid at basic block entry.
-    unsigned IncomingCFARegister = 0;
-    /// Value of cfa register valid at basic block exit.
-    unsigned OutgoingCFARegister = 0;
-    /// Set of callee saved registers saved at basic block entry.
-    BitVector IncomingCSRSaved;
-    /// Set of callee saved registers saved at basic block exit.
-    BitVector OutgoingCSRSaved;
-    /// If in/out cfa offset and register values for this block have already
-    /// been set or not.
-    bool Processed = false;
-  };
-
 #define INVALID_REG UINT_MAX
 #define INVALID_OFFSET INT_MAX
-  /// contains the location where CSR register is saved.
-  struct CSRSavedLocation {
-    CSRSavedLocation(std::optional<unsigned> R, std::optional<int> O)
-        : Reg(R), Offset(O) {}
-    std::optional<unsigned> Reg;
-    std::optional<int> Offset;
-  };
-
-  /// Contains cfa offset and register values valid at entry and exit of basic
-  /// blocks.
-  std::vector<MBBCFAInfo> MBBVector;
-
-  /// Map the callee save registers to the locations where they are saved.
-  SmallDenseMap<unsigned, CSRSavedLocation, 16> CSRLocMap;
-
-  /// Calculate cfa offset and register values valid at entry and exit for all
-  /// basic blocks in a function.
-  void calculateCFAInfo(MachineFunction &MF);
-  /// Calculate cfa offset and register values valid at basic block exit by
-  /// checking the block for CFI instructions. Block's incoming CFA info remains
-  /// the same.
-  void calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo);
-  /// Update in/out cfa offset and register values for successors of the basic
-  /// block.
-  void updateSuccCFAInfo(MBBCFAInfo &MBBInfo);
-
-  /// Check if incoming CFA information of a basic block matches outgoing CFA
-  /// information of the previous block. If it doesn't, insert CFI instruction
-  /// at the beginning of the block that corrects the CFA calculation rule for
-  /// that block.
-  bool insertCFIInstrs(MachineFunction &MF);
-  /// Return the cfa offset value that should be set at the beginning of a MBB
-  /// if needed. The negated value is needed when creating CFI instructions that
-  /// set absolute offset.
-  int64_t getCorrectCFAOffset(MachineBasicBlock *MBB) {
-    return MBBVector[MBB->getNumber()].IncomingCFAOffset;
-  }
-
-  void reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
-  void reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
-  /// Go through each MBB in a function and check that outgoing offset and
-  /// register of its predecessors match incoming offset and register of that
-  /// MBB, as well as that incoming offset and register of its successors match
-  /// outgoing offset and register of the MBB.
-  unsigned verify(MachineFunction &MF);
+   /// contains the location where CSR register is saved.
+   struct CSRSavedLocation {
+     enum Kind { INVALID, REGISTER, CFA_OFFSET };
+     CSRSavedLocation() {
+       K = Kind::INVALID;
+       Reg = 0;
+       Offset = 0;
+     }
+     Kind K;
+     // Dwarf register number
+     unsigned Reg;
+     // CFA offset
+     int64_t Offset;
+     bool isValid() const { return K != Kind::INVALID; }
+     bool operator==(const CSRSavedLocation &RHS) const {
+       switch (K) {
+       case Kind::INVALID:
+         return !RHS.isValid();
+       case Kind::REGISTER:
+         return Reg == RHS.Reg;
+       case Kind::CFA_OFFSET:
+         return Offset == RHS.Offset;
+       }
+       llvm_unreachable("Unknown CSRSavedLocation Kind!");
+     }
+     void dump(raw_ostream &OS) const {
+       switch (K) {
+       case Kind::INVALID:
+         OS << "INVALID";
+         break;
+       case Kind::REGISTER:
+         OS << "In Dwarf register: " << Reg;
+         break;
+       case Kind::CFA_OFFSET:
+         OS << "At CFA offset: " << Offset;
+         break;
+       }
+     }
+   };
+
+   struct MBBCFAInfo {
+     MachineBasicBlock *MBB;
+     /// Value of cfa offset valid at basic block entry.
+     int64_t IncomingCFAOffset = -1;
+     /// Value of cfa offset valid at basic block exit.
+     int64_t OutgoingCFAOffset = -1;
+     /// Value of cfa register valid at basic block entry.
+     unsigned IncomingCFARegister = 0;
+     /// Value of cfa register valid at basic block exit.
+     unsigned OutgoingCFARegister = 0;
+     /// Set of locations where the callee saved registers are at basic block
+     /// entry.
+     SmallVector<CSRSavedLocation> IncomingCSRLocations;
+     /// Set of locations where the callee saved registers are at basic block
+     /// exit.
+     SmallVector<CSRSavedLocation> OutgoingCSRLocations;
+     /// If in/out cfa offset and register values for this block have already
+     /// been set or not.
+     bool Processed = false;
+   };
+
+   /// Contains cfa offset and register values valid at entry and exit of basic
+   /// blocks.
+   std::vector<MBBCFAInfo> MBBVector;
+
+   /// Calculate cfa offset and register values valid at entry and exit for all
+   /// basic blocks in a function.
+   void calculateCFAInfo(MachineFunction &MF);
+   /// Calculate cfa offset and register values valid at basic block exit by
+   /// checking the block for CFI instructions. Block's incoming CFA info
+   /// remains the same.
+   void calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo);
+   /// Update in/out cfa offset and register values for successors of the basic
+   /// block.
+   void updateSuccCFAInfo(MBBCFAInfo &MBBInfo);
+
+   /// Check if incoming CFA information of a basic block matches outgoing CFA
+   /// information of the previous block. If it doesn't, insert CFI instruction
+   /// at the beginning of the block that corrects the CFA calculation rule for
+   /// that block.
+   bool insertCFIInstrs(MachineFunction &MF);
+   /// Return the cfa offset value that should be set at the beginning of a MBB
+   /// if needed. The negated value is needed when creating CFI instructions
+   /// that set absolute offset.
+   int64_t getCorrectCFAOffset(MachineBasicBlock *MBB) {
+     return MBBVector[MBB->getNumber()].IncomingCFAOffset;
+   }
+
+   void reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
+   void reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
+   /// Go through each MBB in a function and check that outgoing offset and
+   /// register of its predecessors match incoming offset and register of that
+   /// MBB, as well as that incoming offset and register of its successors match
+   /// outgoing offset and register of the MBB.
+   unsigned verify(MachineFunction &MF);
 };
 }  // namespace
 
@@ -162,10 +193,18 @@ void CFIInstrInserter::calculateCFAInfo(MachineFunction &MF) {
     MBBInfo.OutgoingCFAOffset = InitialOffset;
     MBBInfo.IncomingCFARegister = DwarfInitialRegister;
     MBBInfo.OutgoingCFARegister = DwarfInitialRegister;
-    MBBInfo.IncomingCSRSaved.resize(NumRegs);
-    MBBInfo.OutgoingCSRSaved.resize(NumRegs);
+    MBBInfo.IncomingCSRLocations.resize(NumRegs);
+    MBBInfo.OutgoingCSRLocations.resize(NumRegs);
+  }
+
+  // Record the initial location of all registers.
+  MBBCFAInfo &EntryMBBInfo = MBBVector[MF.front().getNumber()];
+  const MCPhysReg *CSRegs = MF.getRegInfo().getCalleeSavedRegs();
+  for (int i = 0; CSRegs[i]; ++i) {
+    unsigned Reg = TRI.getDwarfRegNum(CSRegs[i], true);
+    CSRSavedLocation &CSRLoc = EntryMBBInfo.IncomingCSRLocations[Reg];
+    CSRLoc.Reg = Reg;
   }
-  CSRLocMap.clear();
 
   // Set in/out cfa info for all blocks in the function. This traversal is based
   // on the assumption that the first block in the function is the entry block
@@ -176,14 +215,18 @@ void CFIInstrInserter::calculateCFAInfo(MachineFunction &MF) {
 
 void CFIInstrInserter::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
   // Outgoing cfa offset set by the block.
-  int64_t SetOffset = MBBInfo.IncomingCFAOffset;
+  int64_t &OutgoingCFAOffset = MBBInfo.OutgoingCFAOffset;
+  OutgoingCFAOffset = MBBInfo.IncomingCFAOffset;
   // Outgoing cfa register set by the block.
-  unsigned SetRegister = MBBInfo.IncomingCFARegister;
+  unsigned &OutgoingCFARegister = MBBInfo.OutgoingCFARegister;
+  OutgoingCFARegister = MBBInfo.IncomingCFARegister;
+  // Outgoing locations for each callee-saved register set by the block.
+  SmallVector<CSRSavedLocation> &OutgoingCSRLocations =
+      MBBInfo.OutgoingCSRLocations;
+  OutgoingCSRLocations = MBBInfo.IncomingCSRLocations;
+
   MachineFunction *MF = MBBInfo.MBB->getParent();
   const std::vector<MCCFIInstruction> &Instrs = MF->getFrameInstructions();
-  const TargetRegisterInfo &TRI = *MF->getSubtarget().getRegisterInfo();
-  unsigned NumRegs = TRI.getNumSupportedRegs(*MF);
-  BitVector CSRSaved(NumRegs), CSRRestored(NumRegs);
 
 #ifndef NDEBUG
   int RememberState = 0;
@@ -192,36 +235,51 @@ void CFIInstrInserter::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
   // Determine cfa offset and register set by the block.
   for (MachineInstr &MI : *MBBInfo.MBB) {
     if (MI.isCFIInstruction()) {
-      std::optional<unsigned> CSRReg;
-      std::optional<int64_t> CSROffset;
       unsigned CFIIndex = MI.getOperand(0).getCFIIndex();
       const MCCFIInstruction &CFI = Instrs[CFIIndex];
       switch (CFI.getOperation()) {
-      case MCCFIInstruction::OpDefCfaRegister:
-        SetRegister = CFI.getRegister();
+      case MCCFIInstruction::OpDefCfaRegister: {
+        OutgoingCFARegister = CFI.getRegister();
         break;
-      case MCCFIInstruction::OpDefCfaOffset:
-        SetOffset = CFI.getOffset();
+      }
+      case MCCFIInstruction::OpDefCfaOffset: {
+        OutgoingCFAOffset = CFI.getOffset();
         break;
-      case MCCFIInstruction::OpAdjustCfaOffset:
-        SetOffset += CFI.getOffset();
+      }
+      case MCCFIInstruction::OpAdjustCfaOffset: {
+        OutgoingCFAOffset += CFI.getOffset();
         break;
-      case MCCFIInstruction::OpDefCfa:
-        SetRegister = CFI.getRegister();
-        SetOffset = CFI.getOffset();
+      }
+      case MCCFIInstruction::OpDefCfa: {
+        OutgoingCFARegister = CFI.getRegister();
+        OutgoingCFAOffset = CFI.getOffset();
         break;
-      case MCCFIInstruction::OpOffset:
-        CSROffset = CFI.getOffset();
+      }
+      case MCCFIInstruction::OpOffset: {
+        CSRSavedLocation &CSRLocation = OutgoingCSRLocations[CFI.getRegister()];
+        CSRLocation.K = CSRSavedLocation::Kind::CFA_OFFSET;
+        CSRLocation.Offset = CFI.getOffset();
         break;
-      case MCCFIInstruction::OpRegister:
-        CSRReg = CFI.getRegister2();
+      }
+      case MCCFIInstruction::OpRegister: {
+        CSRSavedLocation &CSRLocation = OutgoingCSRLocations[CFI.getRegister()];
+        CSRLocation.K = CSRSavedLocation::Kind::REGISTER;
+        CSRLocation.Reg = CFI.getRegister2();
         break;
-      case MCCFIInstruction::OpRelOffset:
-        CSROffset = CFI.getOffset() - SetOffset;
+      }
+      case MCCFIInstruction::OpRelOffset: {
+        CSRSavedLocation &CSRLocation = OutgoingCSRLocations[CFI.getRegister()];
+        CSRLocation.K = CSRSavedLocation::Kind::CFA_OFFSET;
+        CSRLocation.Offset = CFI.getOffset() - OutgoingCFAOffset;
         break;
-      case MCCFIInstruction::OpRestore:
-        CSRRestored.set(CFI.getRegister());
+      }
+      case MCCFIInstruction::OpRestore: {
+        unsigned Reg = CFI.getRegister();
+        CSRSavedLocation &CSRLocation = OutgoingCSRLocations[Reg];
+        CSRLocation.K = CSRSavedLocation::Kind::REGISTER;
+        CSRLocation.Reg = Reg;
         break;
+      }
       case MCCFIInstruction::OpLLVMDefAspaceCfa:
         // TODO: Add support for handling cfi_def_aspace_cfa.
 #ifndef NDEBUG
@@ -266,17 +324,6 @@ void CFIInstrInserter::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
       case MCCFIInstruction::OpValOffset:
         break;
       }
-      if (CSRReg || CSROffset) {
-        auto It = CSRLocMap.find(CFI.getRegister());
-        if (It == CSRLocMap.end()) {
-          CSRLocMap.insert(
-              {CFI.getRegister(), CSRSavedLocation(CSRReg, CSROffset)});
-        } else if (It->second.Reg != CSRReg || It->second.Offset != CSROffset) {
-          reportFatalInternalError(
-              "Different saved locations for the same CSR");
-        }
-        CSRSaved.set(CFI.getRegister());
-      }
     }
   }
 
@@ -289,15 +336,6 @@ void CFIInstrInserter::calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo) {
 #endif
 
   MBBInfo.Processed = true;
-
-  // Update outgoing CFA info.
-  MBBInfo.OutgoingCFAOffset = SetOffset;
-  MBBInfo.OutgoingCFARegister = SetRegister;
-
-  // Update outgoing CSR info.
-  BitVector::apply([](auto x, auto y, auto z) { return (x | y) & ~z; },
-                   MBBInfo.OutgoingCSRSaved, MBBInfo.IncomingCSRSaved, CSRSaved,
-                   CSRRestored);
 }
 
 void CFIInstrInserter::updateSuccCFAInfo(MBBCFAInfo &MBBInfo) {
@@ -313,7 +351,7 @@ void CFIInstrInserter::updateSuccCFAInfo(MBBCFAInfo &MBBInfo) {
       if (!SuccInfo.Processed) {
         SuccInfo.IncomingCFAOffset = CurrentInfo.OutgoingCFAOffset;
         SuccInfo.IncomingCFARegister = CurrentInfo.OutgoingCFARegister;
-        SuccInfo.IncomingCSRSaved = CurrentInfo.OutgoingCSRSaved;
+        SuccInfo.IncomingCSRLocations = CurrentInfo.OutgoingCSRLocations;
         Stack.push_back(Succ);
       }
     }
@@ -325,7 +363,6 @@ bool CFIInstrInserter::insertCFIInstrs(MachineFunction &MF) {
   const TargetInstrInfo *TII = MF.getSubtarget().getInstrInfo();
   bool InsertedCFIInstr = false;
 
-  BitVector SetDifference;
   for (MachineBasicBlock &MBB : MF) {
     // Skip the first MBB in a function
     if (MBB.getNumber() == MF.front().getNumber()) continue;
@@ -377,32 +414,34 @@ bool CFIInstrInserter::insertCFIInstrs(MachineFunction &MF) {
       continue;
     }
 
-    BitVector::apply([](auto x, auto y) { return x & ~y; }, SetDifference,
-                     PrevMBBInfo->OutgoingCSRSaved, MBBInfo.IncomingCSRSaved);
-    for (int Reg : SetDifference.set_bits()) {
-      unsigned CFIIndex =
-          MF.addFrameInst(MCCFIInstruction::createRestore(nullptr, Reg));
-      BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
-          .addCFIIndex(CFIIndex);
-      InsertedCFIInstr = true;
-    }
-
-    BitVector::apply([](auto x, auto y) { return x & ~y; }, SetDifference,
-                     MBBInfo.IncomingCSRSaved, PrevMBBInfo->OutgoingCSRSaved);
-    for (int Reg : SetDifference.set_bits()) {
-      auto it = CSRLocMap.find(Reg);
-      assert(it != CSRLocMap.end() && "Reg should have an entry in CSRLocMap");
-      unsigned CFIIndex;
-      CSRSavedLocation RO = it->second;
-      if (!RO.Reg && RO.Offset) {
-        CFIIndex = MF.addFrameInst(
-            MCCFIInstruction::createOffset(nullptr, Reg, *RO.Offset));
-      } else if (RO.Reg && !RO.Offset) {
+    for (unsigned i = 0; i < PrevMBBInfo->OutgoingCSRLocations.size(); ++i) {
+      const CSRSavedLocation &PrevOutgoingCSRLoc =
+          PrevMBBInfo->OutgoingCSRLocations[i];
+      const CSRSavedLocation &HasToBeCSRLoc = MBBInfo.IncomingCSRLocations[i];
+      // Ignore non-callee-saved registers, they remain uninitialized (invalid).
+      if (!HasToBeCSRLoc.isValid())
+        continue;
+      if (HasToBeCSRLoc == PrevOutgoingCSRLoc)
+        continue;
+
+      unsigned CFIIndex = (unsigned)(-1);
+      if (HasToBeCSRLoc.K == CSRSavedLocation::Kind::CFA_OFFSET &&
+          HasToBeCSRLoc.Offset != PrevOutgoingCSRLoc.Offset) {
         CFIIndex = MF.addFrameInst(
-            MCCFIInstruction::createRegister(nullptr, Reg, *RO.Reg));
-      } else {
-        llvm_unreachable("RO.Reg and RO.Offset cannot both be valid/invalid");
-      }
+            MCCFIInstruction::createOffset(nullptr, i, HasToBeCSRLoc.Offset));
+      } else if (HasToBeCSRLoc.K == CSRSavedLocation::Kind::REGISTER &&
+                 (HasToBeCSRLoc.Reg != PrevOutgoingCSRLoc.Reg)) {
+        unsigned NewReg = HasToBeCSRLoc.Reg;
+        unsigned DwarfEHReg = i;
+        if (NewReg == DwarfEHReg) {
+          CFIIndex = MF.addFrameInst(
+              MCCFIInstruction::createRestore(nullptr, DwarfEHReg));
+        } else {
+          CFIIndex = MF.addFrameInst(
+              MCCFIInstruction::createRegister(nullptr, i, HasToBeCSRLoc.Reg));
+        }
+      } else
+        llvm_unreachable("Unexpected CSR location.");
       BuildMI(*MBBInfo.MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
           .addCFIIndex(CFIIndex);
       InsertedCFIInstr = true;
@@ -435,13 +474,23 @@ void CFIInstrInserter::reportCSRError(const MBBCFAInfo &Pred,
          << Pred.MBB->getParent()->getName() << " ***\n";
   errs() << "Pred: " << Pred.MBB->getName() << " #" << Pred.MBB->getNumber()
          << " outgoing CSR Saved: ";
-  for (int Reg : Pred.OutgoingCSRSaved.set_bits())
-    errs() << Reg << " ";
+  for (const CSRSavedLocation &OutgoingCSRLocation :
+       Pred.OutgoingCSRLocations) {
+    if (OutgoingCSRLocation.isValid()) {
+      OutgoingCSRLocation.dump(errs());
+      errs() << " ";
+    }
+  }
   errs() << "\n";
   errs() << "Succ: " << Succ.MBB->getName() << " #" << Succ.MBB->getNumber()
          << " incoming CSR Saved: ";
-  for (int Reg : Succ.IncomingCSRSaved.set_bits())
-    errs() << Reg << " ";
+  for (const CSRSavedLocation &IncomingCSRLocation :
+       Succ.IncomingCSRLocations) {
+    if (IncomingCSRLocation.isValid()) {
+      IncomingCSRLocation.dump(errs());
+      errs() << " ";
+    }
+  }
   errs() << "\n";
 }
 
@@ -464,9 +513,12 @@ unsigned CFIInstrInserter::verify(MachineFunction &MF) {
       }
       // Check that IncomingCSRSaved of every successor matches the
       // OutgoingCSRSaved of CurrMBB
-      if (SuccMBBInfo.IncomingCSRSaved != CurrMBBInfo.OutgoingCSRSaved) {
-        reportCSRError(CurrMBBInfo, SuccMBBInfo);
-        ErrorNum++;
+      for (unsigned i = 0; i < CurrMBBInfo.OutgoingCSRLocations.size(); ++i) {
+        if (!(CurrMBBInfo.OutgoingCSRLocations[i] ==
+              SuccMBBInfo.IncomingCSRLocations[i])) {
+          reportCSRError(CurrMBBInfo, SuccMBBInfo);
+          ErrorNum++;
+        }
       }
     }
   }
diff --git a/llvm/test/CodeGen/RISCV/cfi-multiple-locations.mir b/llvm/test/CodeGen/RISCV/cfi-multiple-locations.mir
index aa7de092bf99e..ba9d342ae488c 100644
--- a/llvm/test/CodeGen/RISCV/cfi-multiple-locations.mir
+++ b/llvm/test/CodeGen/RISCV/cfi-multiple-locations.mir
@@ -1,16 +1,44 @@
-# RUN: not --crash llc %s -mtriple=riscv64 \
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
+# RUN: llc %s -mtriple=riscv64 \
 # RUN: -run-pass=cfi-instr-inserter \
 # RUN: -riscv-enable-cfi-instr-inserter=true \
-# RUN: -o /dev/null 2>&1 | FileCheck %s
+# RUN: -o - | FileCheck %s
 
-# CHECK: LLVM ERROR: Different saved locations for the same CSR
-
-# Technically, it is possible that a callee-saved register is saved in multiple different locations.
-# CFIInstrInserter should handle this, but currently it does not.
+# It is possible that the a callee-saved register is saved in different locations.
 ---
 name: multiple_locations
 tracksRegLiveness: true
 body:             |
+  ; CHECK-LABEL: name: multiple_locations
+  ; CHECK: bb.0.entry:
+  ; CHECK-NEXT:   successors: %bb.3(0x40000000), %bb.2(0x40000000)
+  ; CHECK-NEXT:   liveins: $x10, $x9, $x2
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   BEQ $x10, $x0, %bb.3
+  ; CHECK-NEXT:   PseudoBR %bb.2
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.1:
+  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
+  ; CHECK-NEXT:   liveins: $x10, $x9, $x2
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   $x5 = COPY $x9
+  ; CHECK-NEXT:   CFI_INSTRUCTION register $x9, $x5
+  ; CHECK-NEXT:   $x9 = COPY $x5
+  ; CHECK-NEXT:   CFI_INSTRUCTION register $x9, $x9
+  ; CHECK-NEXT:   PseudoBR %bb.3
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT: bb.2:
+  ; CHECK-NEXT:   successors: %bb.3(0x80000000)
+  ; CHECK-NEXT:   liveins: $x10, $x9, $x2
+  ; CHECK-NEXT: {{  $}}
+  ; ...
[truncated]

@github-actions
Copy link

github-actions bot commented Dec 4, 2025

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/CodeGen/CFIInstrInserter.cpp --diff_from_common_commit

⚠️
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing origin/main to the base branch/commit you want to compare against.
⚠️

View the diff from clang-format here.
diff --git a/llvm/lib/CodeGen/CFIInstrInserter.cpp b/llvm/lib/CodeGen/CFIInstrInserter.cpp
index 667928304..20fe26afe 100644
--- a/llvm/lib/CodeGen/CFIInstrInserter.cpp
+++ b/llvm/lib/CodeGen/CFIInstrInserter.cpp
@@ -65,104 +65,104 @@ class CFIInstrInserter : public MachineFunctionPass {
     return insertedCFI;
   }
 
- private:
+private:
 #define INVALID_REG UINT_MAX
 #define INVALID_OFFSET INT_MAX
-   /// contains the location where CSR register is saved.
-   struct CSRSavedLocation {
-     enum Kind { INVALID, REGISTER, CFA_OFFSET };
-     CSRSavedLocation() {
-       K = Kind::INVALID;
-       Reg = 0;
-       Offset = 0;
-     }
-     Kind K;
-     // Dwarf register number
-     unsigned Reg;
-     // CFA offset
-     int64_t Offset;
-     bool isValid() const { return K != Kind::INVALID; }
-     bool operator==(const CSRSavedLocation &RHS) const {
-       switch (K) {
-       case Kind::INVALID:
-         return !RHS.isValid();
-       case Kind::REGISTER:
-         return Reg == RHS.Reg;
-       case Kind::CFA_OFFSET:
-         return Offset == RHS.Offset;
-       }
-       llvm_unreachable("Unknown CSRSavedLocation Kind!");
-     }
-     void dump(raw_ostream &OS) const {
-       switch (K) {
-       case Kind::INVALID:
-         OS << "INVALID";
-         break;
-       case Kind::REGISTER:
-         OS << "In Dwarf register: " << Reg;
-         break;
-       case Kind::CFA_OFFSET:
-         OS << "At CFA offset: " << Offset;
-         break;
-       }
-     }
-   };
-
-   struct MBBCFAInfo {
-     MachineBasicBlock *MBB;
-     /// Value of cfa offset valid at basic block entry.
-     int64_t IncomingCFAOffset = -1;
-     /// Value of cfa offset valid at basic block exit.
-     int64_t OutgoingCFAOffset = -1;
-     /// Value of cfa register valid at basic block entry.
-     unsigned IncomingCFARegister = 0;
-     /// Value of cfa register valid at basic block exit.
-     unsigned OutgoingCFARegister = 0;
-     /// Set of locations where the callee saved registers are at basic block
-     /// entry.
-     SmallVector<CSRSavedLocation> IncomingCSRLocations;
-     /// Set of locations where the callee saved registers are at basic block
-     /// exit.
-     SmallVector<CSRSavedLocation> OutgoingCSRLocations;
-     /// If in/out cfa offset and register values for this block have already
-     /// been set or not.
-     bool Processed = false;
-   };
-
-   /// Contains cfa offset and register values valid at entry and exit of basic
-   /// blocks.
-   std::vector<MBBCFAInfo> MBBVector;
-
-   /// Calculate cfa offset and register values valid at entry and exit for all
-   /// basic blocks in a function.
-   void calculateCFAInfo(MachineFunction &MF);
-   /// Calculate cfa offset and register values valid at basic block exit by
-   /// checking the block for CFI instructions. Block's incoming CFA info
-   /// remains the same.
-   void calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo);
-   /// Update in/out cfa offset and register values for successors of the basic
-   /// block.
-   void updateSuccCFAInfo(MBBCFAInfo &MBBInfo);
-
-   /// Check if incoming CFA information of a basic block matches outgoing CFA
-   /// information of the previous block. If it doesn't, insert CFI instruction
-   /// at the beginning of the block that corrects the CFA calculation rule for
-   /// that block.
-   bool insertCFIInstrs(MachineFunction &MF);
-   /// Return the cfa offset value that should be set at the beginning of a MBB
-   /// if needed. The negated value is needed when creating CFI instructions
-   /// that set absolute offset.
-   int64_t getCorrectCFAOffset(MachineBasicBlock *MBB) {
-     return MBBVector[MBB->getNumber()].IncomingCFAOffset;
-   }
-
-   void reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
-   void reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
-   /// Go through each MBB in a function and check that outgoing offset and
-   /// register of its predecessors match incoming offset and register of that
-   /// MBB, as well as that incoming offset and register of its successors match
-   /// outgoing offset and register of the MBB.
-   unsigned verify(MachineFunction &MF);
+  /// contains the location where CSR register is saved.
+  struct CSRSavedLocation {
+    enum Kind { INVALID, REGISTER, CFA_OFFSET };
+    CSRSavedLocation() {
+      K = Kind::INVALID;
+      Reg = 0;
+      Offset = 0;
+    }
+    Kind K;
+    // Dwarf register number
+    unsigned Reg;
+    // CFA offset
+    int64_t Offset;
+    bool isValid() const { return K != Kind::INVALID; }
+    bool operator==(const CSRSavedLocation &RHS) const {
+      switch (K) {
+      case Kind::INVALID:
+        return !RHS.isValid();
+      case Kind::REGISTER:
+        return Reg == RHS.Reg;
+      case Kind::CFA_OFFSET:
+        return Offset == RHS.Offset;
+      }
+      llvm_unreachable("Unknown CSRSavedLocation Kind!");
+    }
+    void dump(raw_ostream &OS) const {
+      switch (K) {
+      case Kind::INVALID:
+        OS << "INVALID";
+        break;
+      case Kind::REGISTER:
+        OS << "In Dwarf register: " << Reg;
+        break;
+      case Kind::CFA_OFFSET:
+        OS << "At CFA offset: " << Offset;
+        break;
+      }
+    }
+  };
+
+  struct MBBCFAInfo {
+    MachineBasicBlock *MBB;
+    /// Value of cfa offset valid at basic block entry.
+    int64_t IncomingCFAOffset = -1;
+    /// Value of cfa offset valid at basic block exit.
+    int64_t OutgoingCFAOffset = -1;
+    /// Value of cfa register valid at basic block entry.
+    unsigned IncomingCFARegister = 0;
+    /// Value of cfa register valid at basic block exit.
+    unsigned OutgoingCFARegister = 0;
+    /// Set of locations where the callee saved registers are at basic block
+    /// entry.
+    SmallVector<CSRSavedLocation> IncomingCSRLocations;
+    /// Set of locations where the callee saved registers are at basic block
+    /// exit.
+    SmallVector<CSRSavedLocation> OutgoingCSRLocations;
+    /// If in/out cfa offset and register values for this block have already
+    /// been set or not.
+    bool Processed = false;
+  };
+
+  /// Contains cfa offset and register values valid at entry and exit of basic
+  /// blocks.
+  std::vector<MBBCFAInfo> MBBVector;
+
+  /// Calculate cfa offset and register values valid at entry and exit for all
+  /// basic blocks in a function.
+  void calculateCFAInfo(MachineFunction &MF);
+  /// Calculate cfa offset and register values valid at basic block exit by
+  /// checking the block for CFI instructions. Block's incoming CFA info
+  /// remains the same.
+  void calculateOutgoingCFAInfo(MBBCFAInfo &MBBInfo);
+  /// Update in/out cfa offset and register values for successors of the basic
+  /// block.
+  void updateSuccCFAInfo(MBBCFAInfo &MBBInfo);
+
+  /// Check if incoming CFA information of a basic block matches outgoing CFA
+  /// information of the previous block. If it doesn't, insert CFI instruction
+  /// at the beginning of the block that corrects the CFA calculation rule for
+  /// that block.
+  bool insertCFIInstrs(MachineFunction &MF);
+  /// Return the cfa offset value that should be set at the beginning of a MBB
+  /// if needed. The negated value is needed when creating CFI instructions
+  /// that set absolute offset.
+  int64_t getCorrectCFAOffset(MachineBasicBlock *MBB) {
+    return MBBVector[MBB->getNumber()].IncomingCFAOffset;
+  }
+
+  void reportCFAError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
+  void reportCSRError(const MBBCFAInfo &Pred, const MBBCFAInfo &Succ);
+  /// Go through each MBB in a function and check that outgoing offset and
+  /// register of its predecessors match incoming offset and register of that
+  /// MBB, as well as that incoming offset and register of its successors match
+  /// outgoing offset and register of the MBB.
+  unsigned verify(MachineFunction &MF);
 };
 }  // namespace
 

@ppenzin ppenzin changed the title Allow multiple location for the same CSR. [WIP][CodeGen][RISCV] Allow multiple location for the same CSR. Dec 4, 2025
@ppenzin ppenzin requested a review from mgudim December 4, 2025 06:39
@github-actions
Copy link

github-actions bot commented Dec 4, 2025

🐧 Linux x64 Test Results

  • 166723 tests passed
  • 2909 tests skipped
  • 6 tests failed

Failed Tests

(click on a test name to see its output)

LLVM

LLVM.CodeGen/X86/cfi-inserter-callee-save-register-2.mir
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -o - /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register-2.mir -mtriple=x86_64-- -verify-cfiinstrs      -run-pass=cfi-instr-inserter 2>&1 | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register-2.mir
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -o - /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register-2.mir -mtriple=x86_64-- -verify-cfiinstrs -run-pass=cfi-instr-inserter
# note: command had no output on stdout or stderr
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register-2.mir
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register-2.mir:12:10: error: CHECK: expected string not found in input
# | # CHECK: CFI_INSTRUCTION offset $rbp, -16
# |          ^
# | <stdin>:123:7: note: scanning from here
# |  bb.3:
# |       ^
# | <stdin>:126:2: note: possible intended match here
# |  CFI_INSTRUCTION def_cfa $rbp, 16
# |  ^
# | 
# | Input file: <stdin>
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register-2.mir
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             .
# |             .
# |             .
# |           118:  CFI_INSTRUCTION restore $r13 
# |           119:  CFI_INSTRUCTION restore $r14 
# |           120:  CFI_INSTRUCTION def_cfa $rsp, 8 
# |           121:  RET 0, killed $rax 
# |           122:   
# |           123:  bb.3: 
# | check:12'0           X error: no match found
# |           124:  successors: %bb.4(0x80000000) 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           125:   
# | check:12'0     ~~
# |           126:  CFI_INSTRUCTION def_cfa $rbp, 16 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | check:12'1      ?                                 possible intended match
# |           127:  CFI_INSTRUCTION register $r13, $rcx 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           128:  renamable $rdi = IMPLICIT_DEF 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           129:  renamable $rsi = IMPLICIT_DEF 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           130:   
# | check:12'0     ~~
# |           131:  bb.4: 
# | check:12'0     ~~~~~~~
# |             .
# |             .
# |             .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

LLVM.CodeGen/X86/cfi-inserter-callee-save-register.mir
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -o - /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register.mir -mtriple=x86_64-- -verify-cfiinstrs      -run-pass=cfi-instr-inserter 2>&1 | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register.mir
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -o - /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register.mir -mtriple=x86_64-- -verify-cfiinstrs -run-pass=cfi-instr-inserter
# note: command had no output on stdout or stderr
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register.mir
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register.mir:12:10: error: CHECK: expected string not found in input
# | # CHECK: CFI_INSTRUCTION restore $rbx
# |          ^
# | <stdin>:84:7: note: scanning from here
# |  bb.3:
# |       ^
# | <stdin>:85:2: note: possible intended match here
# |  RET 0, $rax
# |  ^
# | 
# | Input file: <stdin>
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-callee-save-register.mir
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             .
# |             .
# |             .
# |            79:  CFI_INSTRUCTION def_cfa_register $rbp 
# |            80:  CFI_INSTRUCTION offset $rbx, -24 
# |            81:  CFI_INSTRUCTION def_cfa $rsp, 8 
# |            82:  RET 0, $rax 
# |            83:   
# |            84:  bb.3: 
# | check:12'0           X error: no match found
# |            85:  RET 0, $rax 
# | check:12'0     ~~~~~~~~~~~~~
# | check:12'1      ?            possible intended match
# |            86: ... 
# | check:12'0     ~~~~
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

LLVM.CodeGen/X86/cfi-inserter-verify-inconsistent-loc.mir
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
not --crash /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -o - /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-verify-inconsistent-loc.mir -mtriple=x86_64--      -run-pass=cfi-instr-inserter 2>&1 | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-verify-inconsistent-loc.mir
# executed command: not --crash /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -o - /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-verify-inconsistent-loc.mir -mtriple=x86_64-- -run-pass=cfi-instr-inserter
# note: command had no output on stdout or stderr
# error: command failed with exit status: 1
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-verify-inconsistent-loc.mir
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-verify-inconsistent-loc.mir:12:10: error: CHECK: expected string not found in input
# | # CHECK: LLVM ERROR: Different saved locations for the same CSR
# |          ^
# | <stdin>:1:1: note: scanning from here
# | --- |
# | ^
# | <stdin>:33:1: note: possible intended match here
# | failsVerification: false
# | ^
# | 
# | Input file: <stdin>
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-verify-inconsistent-loc.mir
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             1: --- | 
# | check:12'0     X~~~~~ error: no match found
# |             2:  ; ModuleID = '/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-verify-inconsistent-loc.mir' 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |             3:  source_filename = "/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/cfi-inserter-verify-inconsistent-loc.mir" 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |             4:  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |             5:  target triple = "x86_64-unknown-unknown" 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |             6:   
# | check:12'0     ~~
# |             .
# |             .
# |             .
# |            28: hasEHContTarget: false 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~
# |            29: hasEHScopes: false 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~
# |            30: hasEHFunclets: false 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~
# |            31: isOutlined: false 
# | check:12'0     ~~~~~~~~~~~~~~~~~~
# |            32: debugInstrRef: false 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~
# |            33: failsVerification: false 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~
# | check:12'1     ?                         possible intended match
# |            34: tracksDebugUserValues: false 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            35: registers: [] 
# | check:12'0     ~~~~~~~~~~~~~~
# |            36: liveins: [] 
# | check:12'0     ~~~~~~~~~~~~
# |            37: frameInfo: 
# | check:12'0     ~~~~~~~~~~~
# |            38:  isFrameAddressTaken: false 
# | check:12'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |             .
# |             .
# |             .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

LLVM.CodeGen/X86/segmented-stacks-dynamic.ll
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc < /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/segmented-stacks-dynamic.ll -mcpu=generic -mtriple=i686-linux -verify-machineinstrs | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/segmented-stacks-dynamic.ll -check-prefix=X86
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -mcpu=generic -mtriple=i686-linux -verify-machineinstrs
# note: command had no output on stdout or stderr
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/segmented-stacks-dynamic.ll -check-prefix=X86
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/segmented-stacks-dynamic.ll:64:13: error: X86-NEXT: expected string not found in input
# | ; X86-NEXT: .cfi_restore %ebp
# |             ^
# | <stdin>:57:9: note: scanning from here
# | .LBB0_1:
# |         ^
# | <stdin>:65:2: note: possible intended match here
# |  .cfi_endproc
# |  ^
# | 
# | Input file: <stdin>
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/segmented-stacks-dynamic.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |            .
# |            .
# |            .
# |           52:  leal -4(%ebp), %esp 
# |           53:  popl %esi 
# |           54:  popl %ebp 
# |           55:  .cfi_def_cfa %esp, 4 
# |           56:  retl 
# |           57: .LBB0_1: 
# | next:64'0             X error: no match found
# |           58:  pushl $4 
# | next:64'0     ~~~~~~~~~~
# |           59:  pushl $12 
# | next:64'0     ~~~~~~~~~~~
# |           60:  calll __morestack 
# | next:64'0     ~~~~~~~~~~~~~~~~~~~
# |           61:  retl 
# | next:64'0     ~~~~~~
# |           62:  jmp .LBB0_2 
# | next:64'0     ~~~~~~~~~~~~~
# |           63: .Lfunc_end0: 
# | next:64'0     ~~~~~~~~~~~~~
# |           64:  .size test_basic, .Lfunc_end0-test_basic 
# | next:64'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           65:  .cfi_endproc 
# | next:64'0     ~~~~~~~~~~~~~~
# | next:64'1      ?             possible intended match
# |           66:  # -- End function 
# | next:64'0     ~~~~~~~~~~~~~~~~~~~
# |           67:  .section ".note.GNU-split-stack","",@progbits 
# | next:64'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |           68:  .section ".note.GNU-stack","",@progbits 
# | next:64'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

LLVM.CodeGen/X86/segmented-stacks.ll
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc < /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/segmented-stacks.ll -mcpu=generic -mtriple=i686-linux -verify-machineinstrs | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/segmented-stacks.ll -check-prefix=X86-Linux
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -mcpu=generic -mtriple=i686-linux -verify-machineinstrs
# note: command had no output on stdout or stderr
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/segmented-stacks.ll -check-prefix=X86-Linux
# .---command stderr------------
# | /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/segmented-stacks.ll:306:19: error: X86-Linux-NEXT: expected string not found in input
# | ; X86-Linux-NEXT: .cfi_restore %esi
# |                   ^
# | <stdin>:65:9: note: scanning from here
# | .LBB1_1:
# |         ^
# | <stdin>:73:2: note: possible intended match here
# |  .cfi_endproc
# |  ^
# | 
# | Input file: <stdin>
# | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/CodeGen/X86/segmented-stacks.ll
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<<<<<
# |             .
# |             .
# |             .
# |            60:  addl $40, %esp 
# |            61:  .cfi_def_cfa_offset 8 
# |            62:  popl %esi 
# |            63:  .cfi_def_cfa_offset 4 
# |            64:  retl 
# |            65: .LBB1_1: 
# | next:306'0             X error: no match found
# |            66:  pushl $4 
# | next:306'0     ~~~~~~~~~~
# |            67:  pushl $44 
# | next:306'0     ~~~~~~~~~~~
# |            68:  calll __morestack 
# | next:306'0     ~~~~~~~~~~~~~~~~~~~
# |            69:  retl 
# | next:306'0     ~~~~~~
# |            70:  jmp .LBB1_2 
# | next:306'0     ~~~~~~~~~~~~~
# |            71: .Lfunc_end1: 
# | next:306'0     ~~~~~~~~~~~~~
# |            72:  .size test_nested, .Lfunc_end1-test_nested 
# | next:306'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            73:  .cfi_endproc 
# | next:306'0     ~~~~~~~~~~~~~~
# | next:306'1      ?             possible intended match
# |            74:  # -- End function 
# | next:306'0     ~~~~~~~~~~~~~~~~~~~
# |            75:  .globl test_large # -- Begin function test_large 
# | next:306'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            76:  .p2align 4 
# | next:306'0     ~~~~~~~~~~~~
# |            77:  .type test_large,@function 
# | next:306'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |            78: test_large: # @test_large 
# | next:306'0     ~~~~~~~~~~~
# |             .
# |             .
# |             .
# | >>>>>>
# `-----------------------------
# error: command failed with exit status: 1

--

LLVM.DebugInfo/MIR/X86/no-cfi-loc.mir
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 3
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -start-after=prologepilog -mtriple=x86_64 -use-unknown-locations=Enable /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/DebugInfo/MIR/X86/no-cfi-loc.mir -o - | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/DebugInfo/MIR/X86/no-cfi-loc.mir
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -start-after=prologepilog -mtriple=x86_64 -use-unknown-locations=Enable /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/DebugInfo/MIR/X86/no-cfi-loc.mir -o -
# .---command stderr------------
# | llc: /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/ADT/SmallVector.h:295: reference llvm::SmallVectorTemplateCommon<(anonymous namespace)::CFIInstrInserter::CSRSavedLocation>::operator[](size_type) [T = (anonymous namespace)::CFIInstrInserter::CSRSavedLocation]: Assertion `idx < size()' 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: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc -start-after=prologepilog -mtriple=x86_64 -use-unknown-locations=Enable /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/DebugInfo/MIR/X86/no-cfi-loc.mir -o -
# | 1.	Running pass 'Function Pass Manager' on module '/home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/DebugInfo/MIR/X86/no-cfi-loc.mir'.
# | 2.	Running pass 'Check CFA info and insert CFI instructions if needed' on function '@foo'
# |  #0 0x0000000007f26918 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:834:13
# |  #1 0x0000000007f24025 llvm::sys::RunSignalHandlers() /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Signals.cpp:105:18
# |  #2 0x0000000007f276e1 SignalHandler(int, siginfo_t*, void*) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/Support/Unix/Signals.inc:426:38
# |  #3 0x00007b6ebb727330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
# |  #4 0x00007b6ebb780b2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
# |  #5 0x00007b6ebb72727e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
# |  #6 0x00007b6ebb70a8ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
# |  #7 0x00007b6ebb70a81b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
# |  #8 0x00007b6ebb71d517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
# |  #9 0x0000000006d3b16a back /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/CodeGen/MachineBasicBlock.h:359:0
# | #10 0x0000000006d3b16a isReturnBlock /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/include/llvm/CodeGen/MachineBasicBlock.h:982:24
# | #11 0x0000000006d3b16a verify /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/CodeGen/CFIInstrInserter.cpp:509:64
# | #12 0x0000000006d3b16a (anonymous namespace)::CFIInstrInserter::runOnMachineFunction(llvm::MachineFunction&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/CodeGen/CFIInstrInserter.cpp:59:31
# | #13 0x0000000006f2fe93 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:0:10
# | #14 0x00000000074a15a5 llvm::FPPassManager::runOnFunction(llvm::Function&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1398:27
# | #15 0x00000000074a9552 llvm::FPPassManager::runOnModule(llvm::Module&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1444:13
# | #16 0x00000000074a204c runOnModule /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1513:27
# | #17 0x00000000074a204c llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:531:44
# | #18 0x0000000004de0222 compileModule(char**, llvm::LLVMContext&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&) /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/tools/llc/llc.cpp:0:8
# | #19 0x0000000004ddd520 main /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/tools/llc/llc.cpp:450:13
# | #20 0x00007b6ebb70c1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
# | #21 0x00007b6ebb70c28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
# | #22 0x0000000004dd8fa5 _start (/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/llc+0x4dd8fa5)
# `-----------------------------
# error: command failed with exit status: -6
# executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/DebugInfo/MIR/X86/no-cfi-loc.mir
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/llvm/test/DebugInfo/MIR/X86/no-cfi-loc.mir
# `-----------------------------
# error: command failed with exit status: 2

--

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

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.

3 participants