authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-06-01 20:04:36-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-02 19:58:01+02:00
loga0c2425e2d607f1b4090b342c41934a31d552c06
tree59c420f63ac5e4a4f17dc507ec3b31bb618923ac
parent3a0d766fc3e86dc9dd9d28ffcc34d8b0ab911173

x86_64: fix cond br saved state

The `copyToTmpRegister` path was completely broken, but it's totally unnecessary, so just avoid it for now. Closes #31133

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

src/codegen/x86_64/CodeGen.zig+15-19
......@@ -176364,7 +176364,7 @@ fn genTry(
176364176364 .close_scope = true,
176365176365 });
176366176366
176367 self.performReloc(reloc);
176367 if (reloc) |r| self.performReloc(r);
176368176368
176369176369 for (liveness_cond_br.then_deaths) |death| try self.processDeath(death, .{});
176370176370
......@@ -176377,30 +176377,26 @@ fn genTry(
176377176377 return result;
176378176378}
176379176379
176380fn genCondBrMir(self: *CodeGen, ty: Type, mcv: MCValue) !Mir.Inst.Index {
176381 const pt = self.pt;
176382 const abi_size = ty.abiSize(pt.zcu);
176380fn genCondBrMir(self: *CodeGen, ty: Type, mcv: MCValue) !?Mir.Inst.Index {
176383176381 switch (mcv) {
176384 .eflags => |cc| {
176385 // Here we map the opposites since the jump is to the false branch.
176386 return self.asmJccReloc(cc.negate(), undefined);
176387 },
176382 .eflags => |cc| return try self.asmJccReloc(cc.negate(), undefined),
176388176383 .register => |reg| {
176389176384 try self.spillEflagsIfOccupied();
176390176385 try self.asmRegisterImmediate(.{ ._, .@"test" }, reg.to8(), .u(1));
176391 return self.asmJccReloc(.z, undefined);
176386 return try self.asmJccReloc(.z, undefined);
176392176387 },
176393 .immediate,
176394 .load_frame,
176395 => {
176388 .immediate => |imm| switch (@as(u1, @truncate(imm))) {
176389 0 => return try self.asmJmpReloc(undefined),
176390 1 => return null,
176391 },
176392 .load_frame => {
176396176393 try self.spillEflagsIfOccupied();
176397 if (abi_size <= 8) {
176398 const reg = try self.copyToTmpRegister(ty, mcv);
176399 return self.genCondBrMir(ty, .{ .register = reg });
176400 }
176401 return self.fail("TODO implement condbr when condition is {f} with abi larger than 8 bytes", .{mcv});
176394 try self.asmMemoryImmediate(.{ ._, .@"test" }, try mcv.mem(self, .{ .size = .byte }), .u(1));
176395 return try self.asmJccReloc(.z, undefined);
176402176396 },
176403 else => return self.fail("TODO implement condbr when condition is {s}", .{@tagName(mcv)}),
176397 else => return self.fail("TODO implement condbr when condition is {f} {s}", .{
176398 ty.fmt(self.pt), @tagName(mcv),
176399 }),
176404176400 }
176405176401}
176406176402
......@@ -176433,7 +176429,7 @@ fn airCondBr(self: *CodeGen, inst: Air.Inst.Index) !void {
176433176429 .close_scope = true,
176434176430 });
176435176431
176436 self.performReloc(reloc);
176432 if (reloc) |r| self.performReloc(r);
176437176433
176438176434 for (liveness_cond_br.else_deaths) |death| try self.processDeath(death, .{});
176439176435 try self.genBodyBlock(else_body);