| ... | @@ -443,14 +443,17 @@ fn gen(self: *Self) !void { | ... | @@ -443,14 +443,17 @@ fn gen(self: *Self) !void { |
| 443 | }); | 443 | }); |
| 444 | | 444 | |
| 445 | // exitlude jumps | 445 | // exitlude jumps |
| 446 | if (self.exitlude_jump_relocs.items.len == 1) { | 446 | if (self.exitlude_jump_relocs.items.len > 0 and |
| 447 | // There is only one relocation. Hence, | 447 | self.exitlude_jump_relocs.items[self.exitlude_jump_relocs.items.len - 1] == self.mir_instructions.len - 2) |
| 448 | // this relocation must be at the end of | 448 | { |
| 449 | // the code. Therefore, we can just delete | 449 | // If the last Mir instruction (apart from the |
| 450 | // the space initially reserved for the | 450 | // dbg_epilogue_begin) is the last exitlude jump |
| 451 | // jump | 451 | // relocation (which would just jump one instruction |
| 452 | self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.items[0]); | 452 | // further), it can be safely removed |
| 453 | } else for (self.exitlude_jump_relocs.items) |jmp_reloc| { | 453 | self.mir_instructions.orderedRemove(self.exitlude_jump_relocs.pop()); |
| | 454 | } |
| | 455 | |
| | 456 | for (self.exitlude_jump_relocs.items) |jmp_reloc| { |
| 454 | self.mir_instructions.set(jmp_reloc, .{ | 457 | self.mir_instructions.set(jmp_reloc, .{ |
| 455 | .tag = .b, | 458 | .tag = .b, |
| 456 | .data = .{ .inst = @intCast(u32, self.mir_instructions.len) }, | 459 | .data = .{ .inst = @intCast(u32, self.mir_instructions.len) }, |
| ... | @@ -2958,7 +2961,17 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -2958,7 +2961,17 @@ fn airBlock(self: *Self, inst: Air.Inst.Index) !void { |
| 2958 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; | 2961 | const body = self.air.extra[extra.end..][0..extra.data.body_len]; |
| 2959 | try self.genBody(body); | 2962 | try self.genBody(body); |
| 2960 | | 2963 | |
| 2961 | for (self.blocks.getPtr(inst).?.relocs.items) |reloc| try self.performReloc(reloc); | 2964 | // relocations for `br` instructions |
| | 2965 | const relocs = &self.blocks.getPtr(inst).?.relocs; |
| | 2966 | if (relocs.items.len > 0 and relocs.items[relocs.items.len - 1] == self.mir_instructions.len - 1) { |
| | 2967 | // If the last Mir instruction is the last relocation (which |
| | 2968 | // would just jump one instruction further), it can be safely |
| | 2969 | // removed |
| | 2970 | self.mir_instructions.orderedRemove(relocs.pop()); |
| | 2971 | } |
| | 2972 | for (relocs.items) |reloc| { |
| | 2973 | try self.performReloc(reloc); |
| | 2974 | } |
| 2962 | | 2975 | |
| 2963 | const result = self.blocks.getPtr(inst).?.mcv; | 2976 | const result = self.blocks.getPtr(inst).?.mcv; |
| 2964 | return self.finishAir(inst, result, .{ .none, .none, .none }); | 2977 | return self.finishAir(inst, result, .{ .none, .none, .none }); |