authorgravatar for joachim.schmidt557@outlook.comJoachim Schmidt <joachim.schmidt557@outlook.com> 2022-03-12 14:59:29+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-03-12 18:33:25+01:00
log01081ce5a59f4e2e57a9ff6e5885269ed3014279
treef2f4f9f71c1168f60d616bfb4df68466f755c21d
parente5d4a694ea7dd251e10d6434c9321b5e0a548d4b

stage2 x86_64: Fix assertion in getResolvedInstValue


1 files changed, 18 insertions(+), 19 deletions(-)

src/arch/x86_64/CodeGen.zig+18-19
......@@ -3741,8 +3741,6 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
37413741 // If the condition dies here in this condbr instruction, process
37423742 // that death now instead of later as this has an effect on
37433743 // whether it needs to be spilled in the branches
3744 // TODO I need investigate how to make this work without removing
3745 // an assertion from getResolvedInstValue()
37463744 if (self.liveness.operandDies(inst, 0)) {
37473745 const op_int = @enumToInt(pl_op.operand);
37483746 if (op_int >= Air.Inst.Ref.typed_value_map.len) {
......@@ -3869,7 +3867,9 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
38693867
38703868 self.branch_stack.pop().deinit(self.gpa);
38713869
3872 return self.finishAir(inst, .unreach, .{ pl_op.operand, .none, .none });
3870 // We already took care of pl_op.operand earlier, so we're going
3871 // to pass .none here
3872 return self.finishAir(inst, .unreach, .{ .none, .none, .none });
38733873}
38743874
38753875fn isNull(self: *Self, inst: Air.Inst.Index, ty: Type, operand: MCValue) !MCValue {
......@@ -4194,6 +4194,17 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
41944194 );
41954195 defer self.gpa.free(liveness.deaths);
41964196
4197 // If the condition dies here in this switch instruction, process
4198 // that death now instead of later as this has an effect on
4199 // whether it needs to be spilled in the branches
4200 if (self.liveness.operandDies(inst, 0)) {
4201 const op_int = @enumToInt(pl_op.operand);
4202 if (op_int >= Air.Inst.Ref.typed_value_map.len) {
4203 const op_index = @intCast(Air.Inst.Index, op_int - Air.Inst.Ref.typed_value_map.len);
4204 self.processDeath(op_index);
4205 }
4206 }
4207
41974208 while (case_i < switch_br.data.cases_len) : (case_i += 1) {
41984209 const case = self.air.extraData(Air.SwitchBr.Case, extra_index);
41994210 const items = @bitCast([]const Air.Inst.Ref, self.air.extra[case.end..][0..case.data.items_len]);
......@@ -4208,19 +4219,6 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
42084219 relocs[item_i] = try self.genCondSwitchMir(condition_ty, condition, item_mcv);
42094220 }
42104221
4211 // If the condition dies here in this condbr instruction, process
4212 // that death now instead of later as this has an effect on
4213 // whether it needs to be spilled in the branches
4214 // TODO I need investigate how to make this work without removing
4215 // an assertion from getResolvedInstValue()
4216 if (self.liveness.operandDies(inst, 0)) {
4217 const op_int = @enumToInt(pl_op.operand);
4218 if (op_int >= Air.Inst.Ref.typed_value_map.len) {
4219 const op_index = @intCast(Air.Inst.Index, op_int - Air.Inst.Ref.typed_value_map.len);
4220 self.processDeath(op_index);
4221 }
4222 }
4223
42244222 // Capture the state of register and stack allocation state so that we can revert to it.
42254223 const parent_next_stack_offset = self.next_stack_offset;
42264224 const parent_free_registers = self.register_manager.free_registers;
......@@ -4276,7 +4274,9 @@ fn airSwitch(self: *Self, inst: Air.Inst.Index) !void {
42764274 // in airCondBr.
42774275 }
42784276
4279 return self.finishAir(inst, .unreach, .{ pl_op.operand, .none, .none });
4277 // We already took care of pl_op.operand earlier, so we're going
4278 // to pass .none here
4279 return self.finishAir(inst, .unreach, .{ .none, .none, .none });
42804280}
42814281
42824282fn performReloc(self: *Self, reloc: Mir.Inst.Index) !void {
......@@ -5630,8 +5630,7 @@ fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) MCValue {
56305630 while (true) {
56315631 i -= 1;
56325632 if (self.branch_stack.items[i].inst_table.get(inst)) |mcv| {
5633 // TODO see comment in `airCondBr` and `airSwitch`
5634 // assert(mcv != .dead);
5633 assert(mcv != .dead);
56355634 return mcv;
56365635 }
56375636 }