Skip to content

Commit

Permalink
x86_64: fix @bitCast when the operand dies
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobly0 committed May 19, 2023
1 parent 79bdd2b commit 47405b1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/arch/x86_64/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10154,18 +10154,22 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
const dst_rc = regClassForType(dst_ty);
const src_rc = regClassForType(src_ty);
const src_mcv = try self.resolveInst(ty_op.operand);
if (dst_rc.supersetOf(src_rc) and self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
break :result src_mcv;

const src_lock = if (src_mcv.getReg()) |reg| self.register_manager.lockReg(reg) else null;
defer if (src_lock) |lock| self.register_manager.unlockReg(lock);

const dst_mcv = try self.allocRegOrMem(inst, true);
try self.genCopy(
if (!dst_mcv.isMemory() or src_mcv.isMemory()) dst_ty else src_ty,
dst_mcv,
src_mcv,
);
const dst_mcv = if (dst_rc.supersetOf(src_rc) and
self.reuseOperand(inst, ty_op.operand, 0, src_mcv))
src_mcv
else dst: {
const dst_mcv = try self.allocRegOrMem(inst, true);
try self.genCopy(
if (!dst_mcv.isMemory() or src_mcv.isMemory()) dst_ty else src_ty,
dst_mcv,
src_mcv,
);
break :dst dst_mcv;
};

const dst_signedness =
if (dst_ty.isAbiInt()) dst_ty.intInfo(self.target.*).signedness else .unsigned;
Expand Down

0 comments on commit 47405b1

Please sign in to comment.