x86_64: fix switch on mod result

Closes #24541
This commit is contained in:
Jacob Young 2025-07-26 06:23:31 -04:00
parent fc4b7c968a
commit 68cfa736df
2 changed files with 18 additions and 9 deletions

View file

@ -1103,11 +1103,7 @@ const FormatAirData = struct {
inst: Air.Inst.Index, inst: Air.Inst.Index,
}; };
fn formatAir(data: FormatAirData, w: *std.io.Writer) Writer.Error!void { fn formatAir(data: FormatAirData, w: *std.io.Writer) Writer.Error!void {
// not acceptable implementation because it ignores `w`: data.self.air.writeInst(w, data.inst, data.self.pt, data.self.liveness);
//data.self.air.dumpInst(data.inst, data.self.pt, data.self.liveness);
_ = data;
_ = w;
@panic("TODO: unimplemented");
} }
fn fmtAir(self: *CodeGen, inst: Air.Inst.Index) std.fmt.Formatter(FormatAirData, formatAir) { fn fmtAir(self: *CodeGen, inst: Air.Inst.Index) std.fmt.Formatter(FormatAirData, formatAir) {
return .{ .data = .{ .self = self, .inst = inst } }; return .{ .data = .{ .self = self, .inst = inst } };
@ -179300,10 +179296,13 @@ fn lowerSwitchBr(
} else undefined; } else undefined;
const table_start: u31 = @intCast(cg.mir_table.items.len); const table_start: u31 = @intCast(cg.mir_table.items.len);
{ {
const condition_index_reg = if (condition_index.isRegister()) const condition_index_reg = condition_index_reg: {
condition_index.getReg().? if (condition_index.isRegister()) {
else const condition_index_reg = condition_index.getReg().?;
try cg.copyToTmpRegister(.usize, condition_index); if (condition_index_reg.isClass(.general_purpose)) break :condition_index_reg condition_index_reg;
}
break :condition_index_reg try cg.copyToTmpRegister(.usize, condition_index);
};
const condition_index_lock = cg.register_manager.lockReg(condition_index_reg); const condition_index_lock = cg.register_manager.lockReg(condition_index_reg);
defer if (condition_index_lock) |lock| cg.register_manager.unlockReg(lock); defer if (condition_index_lock) |lock| cg.register_manager.unlockReg(lock);
try cg.truncateRegister(condition_ty, condition_index_reg); try cg.truncateRegister(condition_ty, condition_index_reg);

View file

@ -1072,3 +1072,13 @@ test "switch on a signed value smaller than the smallest prong value" {
else => {}, else => {},
} }
} }
test "switch on 8-bit mod result" {
var x: u8 = undefined;
x = 16;
switch (x % 4) {
0 => {},
1, 2, 3 => return error.TestFailed,
else => unreachable,
}
}