authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-11-07 20:50:00+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-11-08 13:42:58+01:00
log45f65c84457f3b52209fd4f4595130d6528ebecd
treee71850df7c7153fc9ea7acf221d5aa97c0a5e073
parent0d556877af4d12e1e0d5c0146ab80273e91f211c

aarch64: fix implementation of .is_null and .is_non_null


1 files changed, 16 insertions(+), 24 deletions(-)

src/arch/aarch64/CodeGen.zig+16-24
......@@ -1548,7 +1548,7 @@ fn allocRegs(
15481548 };
15491549 const raw_reg = try self.register_manager.allocReg(track_inst, gp);
15501550 arg.reg.* = self.registerAlias(raw_reg, arg.ty);
1551 read_locks[i] = self.register_manager.lockReg(arg.reg.*);
1551 read_locks[i] = self.register_manager.lockRegAssumeUnused(arg.reg.*);
15521552 }
15531553 }
15541554
......@@ -2920,13 +2920,13 @@ fn optionalPayload(self: *Self, inst: Air.Inst.Index, mcv: MCValue, optional_ty:
29202920 Mir.Inst.Tag.lsr_immediate,
29212921 .data = .{ .rr_shift = .{
29222922 .rd = dest_reg,
2923 .rn = source_reg,
2923 .rn = source_reg.toX(),
29242924 .shift = shift,
29252925 } },
29262926 });
29272927 }
29282928
2929 return MCValue{ .register = dest_reg };
2929 return MCValue{ .register = self.registerAlias(dest_reg, payload_ty) };
29302930 },
29312931 .stack_argument_offset => |off| {
29322932 return MCValue{ .stack_argument_offset = off + offset };
......@@ -4215,18 +4215,16 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallOptions.
42154215
42164216 const result: MCValue = result: {
42174217 switch (info.return_value) {
4218 .register => |reg| {
4219 if (RegisterManager.indexOfReg(&callee_preserved_regs, reg) == null) {
4220 // Save function return value in a callee saved register
4221 break :result try self.copyToNewRegister(inst, info.return_value);
4222 }
4218 .register => {
4219 // Save function return value in a callee saved register
4220 break :result try self.copyToNewRegister(inst, info.return_value);
42234221 },
42244222 else => {},
42254223 }
42264224 break :result info.return_value;
42274225 };
42284226
4229 if (args.len + 1 <= Liveness.bpi - 1) {
4227 if (args.len <= Liveness.bpi - 2) {
42304228 var buf = [1]Air.Inst.Ref{.none} ** (Liveness.bpi - 1);
42314229 buf[0] = callee;
42324230 std.mem.copy(Air.Inst.Ref, buf[1..], args);
......@@ -4642,19 +4640,13 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
46424640}
46434641
46444642fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
4645 if (operand_ty.isPtrLikeOptional()) {
4646 assert(operand_ty.abiSize(self.target.*) == 8);
4647
4648 const imm_bind: ReadArg.Bind = .{ .mcv = .{ .immediate = 0 } };
4649 return self.cmp(operand_bind, imm_bind, Type.usize, .eq);
4650 } else {
4643 const sentinel_ty: Type = if (!operand_ty.isPtrLikeOptional()) blk: {
46514644 var buf: Type.Payload.ElemType = undefined;
46524645 const payload_ty = operand_ty.optionalChild(&buf);
4653 const sentinel_ty = if (payload_ty.hasRuntimeBitsIgnoreComptime()) Type.bool else operand_ty;
4654
4655 const imm_bind: ReadArg.Bind = .{ .mcv = .{ .immediate = 0 } };
4656 return self.cmp(operand_bind, imm_bind, sentinel_ty, .eq);
4657 }
4646 break :blk if (payload_ty.hasRuntimeBitsIgnoreComptime()) Type.bool else operand_ty;
4647 } else operand_ty;
4648 const imm_bind: ReadArg.Bind = .{ .mcv = .{ .immediate = 0 } };
4649 return self.cmp(operand_bind, imm_bind, sentinel_ty, .eq);
46584650}
46594651
46604652fn isNonNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
......@@ -4692,10 +4684,10 @@ fn isNonErr(self: *Self, ty: Type, operand: MCValue) !MCValue {
46924684fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
46934685 const un_op = self.air.instructions.items(.data)[inst].un_op;
46944686 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4695 const operand_bind: ReadArg.Bind = .{ .inst = un_op };
4687 const operand = try self.resolveInst(un_op);
46964688 const operand_ty = self.air.typeOf(un_op);
46974689
4698 break :result try self.isNull(operand_bind, operand_ty);
4690 break :result try self.isNull(.{ .mcv = operand }, operand_ty);
46994691 };
47004692 return self.finishAir(inst, result, .{ un_op, .none, .none });
47014693}
......@@ -4718,10 +4710,10 @@ fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
47184710fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
47194711 const un_op = self.air.instructions.items(.data)[inst].un_op;
47204712 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
4721 const operand_bind: ReadArg.Bind = .{ .inst = un_op };
4713 const operand = try self.resolveInst(un_op);
47224714 const operand_ty = self.air.typeOf(un_op);
47234715
4724 break :result try self.isNonNull(operand_bind, operand_ty);
4716 break :result try self.isNonNull(.{ .mcv = operand }, operand_ty);
47254717 };
47264718 return self.finishAir(inst, result, .{ un_op, .none, .none });
47274719}