From 89b4195c69c53e8b1fdd3f5ddd2c9658a61daaac Mon Sep 17 00:00:00 2001 From: Koakuma Date: Sat, 28 May 2022 09:06:25 +0700 Subject: [PATCH] stage2: sparc64: Account for delay slot in airBlock --- src/arch/sparc64/CodeGen.zig | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/arch/sparc64/CodeGen.zig b/src/arch/sparc64/CodeGen.zig index a4c6635b4c..bc73ea02b3 100644 --- a/src/arch/sparc64/CodeGen.zig +++ b/src/arch/sparc64/CodeGen.zig @@ -991,9 +991,14 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { const relocs = &self.blocks.getPtr(inst).?.relocs; if (relocs.items.len > 0 and relocs.items[relocs.items.len - 1] == self.mir_instructions.len - 1) { // If the last Mir instruction is the last relocation (which - // would just jump one instruction further), it can be safely + // would just jump two instruction further), it can be safely // removed - self.mir_instructions.orderedRemove(relocs.pop()); + const index = relocs.pop(); + + // First, remove the delay slot, then remove + // the branch instruction itself. + self.mir_instructions.orderedRemove(index + 1); + self.mir_instructions.orderedRemove(index); } for (relocs.items) |reloc| { try self.performReloc(reloc);