[llvm-branch-commits] [llvm] release/23.x: [Mips] Handle division by zero trap on MIPS1 (#201133) (PR #229250)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Oct 12 09:47:08 PDT 2026
================
@@ -1280,19 +1286,62 @@ addLiveIn(MachineFunction &MF, unsigned PReg, const TargetRegisterClass *RC)
return VReg;
}
-static MachineBasicBlock *insertDivByZeroTrap(MachineInstr &MI,
- MachineBasicBlock &MBB,
- const TargetInstrInfo &TII,
- bool Is64Bit, bool IsMicroMips) {
+static MachineBasicBlock *
+insertDivByZeroTrap(MachineInstr &MI, MachineBasicBlock &MBB,
+ const TargetInstrInfo &TII, bool Is64Bit,
+ const DivByZeroTrapKind TrapKind) {
if (NoZeroDivCheck)
return &MBB;
+ MachineOperand &Divisor = MI.getOperand(2);
+
+ if (TrapKind == DivByZeroTrapKind::Break) {
+ // Build instructions:
+ // MBB:
+ // bnez $divisor, $zero, SinkMBB
+ // MI $dst, $dividend, $divisor (delay slot)
+ //
+ // BreakMBB:
+ // break 7
+ //
+ // SinkMBB:
+ // fallthrough
+ const DebugLoc &DL = MI.getDebugLoc();
+ const BasicBlock *BB = MBB.getBasicBlock();
+
+ // Place all instructions after MI into SinkMBB.
+ MachineBasicBlock *SinkMBB = MBB.splitAt(MI, true);
+
+ // BreakMBB setup.
+ MachineFunction *MF = MBB.getParent();
+ MachineBasicBlock *BreakMBB = MF->CreateMachineBasicBlock(BB);
----------------
arsenm wrote:
This probably should be using splitAt
https://github.com/llvm/llvm-project/pull/229250
More information about the llvm-branch-commits
mailing list