aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Rubin <daviru007@icloud.com>2024-07-26 04:00:25 -0700
committerDavid Rubin <daviru007@icloud.com>2024-07-26 04:19:58 -0700
commit8da212c11bc54bb78950988f5980c78161af8573 (patch)
treeb2ea3f0019291f90a73da739a389ce30dd25eb5b /src
parent046001a34a070dffa6230ccbd8f1571e0b1c1240 (diff)
downloadzig-8da212c11bc54bb78950988f5980c78161af8573.tar.gz
zig-8da212c11bc54bb78950988f5980c78161af8573.zip
riscv: update tests and fix reuse bug
Diffstat (limited to 'src')
-rw-r--r--src/arch/riscv64/CodeGen.zig24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig
index 7f70be6231..0ffdb655ef 100644
--- a/src/arch/riscv64/CodeGen.zig
+++ b/src/arch/riscv64/CodeGen.zig
@@ -1982,6 +1982,8 @@ fn truncateRegister(func: *Func, ty: Type, reg: Register) !void {
.signedness = .unsigned,
.bits = @intCast(ty.bitSize(pt)),
};
+ assert(reg.class() == .int);
+
const shift = math.cast(u6, 64 - int_info.bits % 64) orelse return;
switch (int_info.signedness) {
.signed => {
@@ -2844,8 +2846,11 @@ fn genBinOp(
.cmp_gt,
.cmp_gte,
=> {
- try func.truncateRegister(lhs_ty, lhs_reg);
- try func.truncateRegister(rhs_ty, rhs_reg);
+ assert(lhs_reg.class() == rhs_reg.class());
+ if (lhs_reg.class() == .int) {
+ try func.truncateRegister(lhs_ty, lhs_reg);
+ try func.truncateRegister(rhs_ty, rhs_reg);
+ }
_ = try func.addInst(.{
.tag = .pseudo_compare,
@@ -3923,7 +3928,7 @@ fn airPtrElemPtr(func: *Func, inst: Air.Inst.Index) !void {
const ty_pl = func.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
const extra = func.air.extraData(Air.Bin, ty_pl.payload).data;
- const result = result: {
+ const result: MCValue = if (func.liveness.isUnused(inst)) .unreach else result: {
const elem_ptr_ty = func.typeOfIndex(inst);
const base_ptr_ty = func.typeOf(extra.lhs);
@@ -3959,6 +3964,7 @@ fn airPtrElemPtr(func: *Func, inst: Air.Inst.Index) !void {
break :result MCValue{ .register = result_reg };
};
+
return func.finishAir(inst, result, .{ extra.lhs, extra.rhs, .none });
}
@@ -4409,9 +4415,15 @@ fn airLoad(func: *Func, inst: Air.Inst.Index) !void {
const elem_size = elem_ty.abiSize(pt);
const dst_mcv: MCValue = blk: {
- // "ptr" is 8 bytes, and if the element is more than that, we cannot reuse it.
- if (elem_size <= 8 and func.reuseOperand(inst, ty_op.operand, 0, ptr)) {
- // The MCValue that holds the pointer can be re-used as the value.
+ // The MCValue that holds the pointer can be re-used as the value.
+ // - "ptr" is 8 bytes, and if the element is more than that, we cannot reuse it.
+ //
+ // - "ptr" will be stored in an integer register, so the type that we're gonna
+ // load into it must also be a type that can be inside of an integer register
+ if (elem_size <= 8 and
+ (if (ptr == .register) func.typeRegClass(elem_ty) == ptr.register.class() else true) and
+ func.reuseOperand(inst, ty_op.operand, 0, ptr))
+ {
break :blk ptr;
} else {
break :blk try func.allocRegOrMem(elem_ty, inst, true);