diff --git a/src/Air.zig b/src/Air.zig index 4938cb8135..5120e0fd67 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -554,7 +554,7 @@ pub const Inst = struct { /// Uses the `ty_pl` field with payload `Shuffle`. shuffle, /// Constructs a vector element-wise from `a` or `b` based on `pred`. - /// Uses the `ty_pl` field with payload `Select`. + /// Uses the `pl_op` field with `pred` as operand, and payload `Bin`. select, /// Given dest ptr, value, and len, set all elements at dest to value. @@ -788,12 +788,6 @@ pub const Shuffle = struct { mask_len: u32, }; -pub const Select = struct { - pred: Inst.Ref, - a: Inst.Ref, - b: Inst.Ref, -}; - pub const VectorCmp = struct { lhs: Inst.Ref, rhs: Inst.Ref, @@ -965,7 +959,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type { .cmpxchg_weak, .cmpxchg_strong, .slice, - .select, .shuffle, .aggregate_init, .union_init, @@ -1077,6 +1070,10 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type { .reduce => return air.typeOf(datas[inst].reduce.operand).childType(), .mul_add => return air.typeOf(datas[inst].pl_op.operand), + .select => { + const extra = air.extraData(Air.Bin, datas[inst].pl_op.payload).data; + return air.typeOf(extra.lhs); + }, .add_with_overflow, .sub_with_overflow, diff --git a/src/Liveness.zig b/src/Liveness.zig index 9e15567d73..b9f4e6b33a 100644 --- a/src/Liveness.zig +++ b/src/Liveness.zig @@ -434,8 +434,9 @@ fn analyzeInst( return extra_tombs.finish(); }, .select => { - const extra = a.air.extraData(Air.Select, inst_datas[inst].ty_pl.payload).data; - return trackOperands(a, new_set, inst, main_tomb, .{ extra.pred, extra.a, extra.b }); + const pl_op = inst_datas[inst].pl_op; + const extra = a.air.extraData(Air.Bin, pl_op.payload).data; + return trackOperands(a, new_set, inst, main_tomb, .{ pl_op.operand, extra.lhs, extra.rhs }); }, .shuffle => { const extra = a.air.extraData(Air.Shuffle, inst_datas[inst].ty_pl.payload).data; diff --git a/src/Sema.zig b/src/Sema.zig index e4d719f346..6971be64bf 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -14894,12 +14894,11 @@ fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. try sema.requireRuntimeBlock(block, runtime_src); return block.addInst(.{ .tag = .select, - .data = .{ .ty_pl = .{ - .ty = try block.sema.addType(vec_ty), - .payload = try block.sema.addExtra(Air.Select{ - .pred = pred, - .a = a, - .b = b, + .data = .{ .pl_op = .{ + .operand = pred, + .payload = try block.sema.addExtra(Air.Bin{ + .lhs = a, + .rhs = b, }), } }, }); diff --git a/src/arch/aarch64/CodeGen.zig b/src/arch/aarch64/CodeGen.zig index 178dfe2c29..4d931da0b2 100644 --- a/src/arch/aarch64/CodeGen.zig +++ b/src/arch/aarch64/CodeGen.zig @@ -3748,10 +3748,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void { } fn airSelect(self: *Self, inst: Air.Inst.Index) !void { - const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; - const extra = self.air.extraData(Air.Select, ty_pl.payload).data; + const pl_op = self.air.instructions.items(.data)[inst].pl_op; + const extra = self.air.extraData(Air.Bin, pl_op.payload).data; const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for {}", .{self.target.cpu.arch}); - return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b }); + return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs }); } fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { diff --git a/src/arch/arm/CodeGen.zig b/src/arch/arm/CodeGen.zig index 7fa116edd1..15d0e47d4a 100644 --- a/src/arch/arm/CodeGen.zig +++ b/src/arch/arm/CodeGen.zig @@ -4325,10 +4325,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void { } fn airSelect(self: *Self, inst: Air.Inst.Index) !void { - const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; - const extra = self.air.extraData(Air.Select, ty_pl.payload).data; + const pl_op = self.air.instructions.items(.data)[inst].pl_op; + const extra = self.air.extraData(Air.Bin, pl_op.payload).data; const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for arm", .{}); - return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b }); + return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs }); } fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { diff --git a/src/arch/riscv64/CodeGen.zig b/src/arch/riscv64/CodeGen.zig index 65b3b4904d..8b697677c1 100644 --- a/src/arch/riscv64/CodeGen.zig +++ b/src/arch/riscv64/CodeGen.zig @@ -2398,10 +2398,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void { } fn airSelect(self: *Self, inst: Air.Inst.Index) !void { - const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; - const extra = self.air.extraData(Air.Select, ty_pl.payload).data; + const pl_op = self.air.instructions.items(.data)[inst].pl_op; + const extra = self.air.extraData(Air.Bin, pl_op.payload).data; const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for riscv64", .{}); - return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b }); + return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs }); } fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index de5e698eca..7ab4a33be9 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -3269,10 +3269,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) InnerError!WValue { fn airSelect(self: *Self, inst: Air.Inst.Index) InnerError!WValue { if (self.liveness.isUnused(inst)) return WValue{ .none = {} }; - const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; - const ty = try self.resolveInst(ty_pl.ty); + const pl_op = self.air.instructions.items(.data)[inst].pl_op; + const operand = try self.resolveInst(pl_op.operand); - _ = ty; + _ = operand; return self.fail("TODO: Implement wasm airSelect", .{}); } diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index 8a9aaebb22..4efb836c3a 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -5680,10 +5680,10 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void { } fn airSelect(self: *Self, inst: Air.Inst.Index) !void { - const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; - const extra = self.air.extraData(Air.Select, ty_pl.payload).data; + const pl_op = self.air.instructions.items(.data)[inst].pl_op; + const extra = self.air.extraData(Air.Bin, pl_op.payload).data; const result: MCValue = if (self.liveness.isUnused(inst)) .dead else return self.fail("TODO implement airSelect for x86_64", .{}); - return self.finishAir(inst, result, .{ extra.pred, extra.a, extra.b }); + return self.finishAir(inst, result, .{ pl_op.operand, extra.lhs, extra.rhs }); } fn airShuffle(self: *Self, inst: Air.Inst.Index) !void { diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 0f481e0a6d..00074d69d1 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -6359,11 +6359,11 @@ pub const FuncGen = struct { fn airSelect(self: *FuncGen, inst: Air.Inst.Index) !?*const llvm.Value { if (self.liveness.isUnused(inst)) return null; - const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; - const extra = self.air.extraData(Air.Select, ty_pl.payload).data; - const pred = try self.resolveInst(extra.pred); - const a = try self.resolveInst(extra.a); - const b = try self.resolveInst(extra.b); + const pl_op = self.air.instructions.items(.data)[inst].pl_op; + const extra = self.air.extraData(Air.Bin, pl_op.payload).data; + const pred = try self.resolveInst(pl_op.operand); + const a = try self.resolveInst(extra.lhs); + const b = try self.resolveInst(extra.rhs); return self.builder.buildSelect(pred, a, b, ""); } diff --git a/src/print_air.zig b/src/print_air.zig index a2fe461887..f1e51150a6 100644 --- a/src/print_air.zig +++ b/src/print_air.zig @@ -398,15 +398,16 @@ const Writer = struct { } fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void { - const ty_pl = w.air.instructions.items(.data)[inst].ty_pl; - const extra = w.air.extraData(Air.Select, ty_pl.payload).data; + const pl_op = w.air.instructions.items(.data)[inst].pl_op; + const extra = w.air.extraData(Air.Bin, pl_op.payload).data; - try s.print("{}, ", .{w.air.getRefType(ty_pl.ty).fmtDebug()}); - try w.writeOperand(s, inst, 0, extra.pred); + const elem_ty = w.air.typeOfIndex(inst).childType(); + try s.print("{}, ", .{elem_ty.fmtDebug()}); + try w.writeOperand(s, inst, 0, pl_op.operand); try s.writeAll(", "); - try w.writeOperand(s, inst, 1, extra.a); + try w.writeOperand(s, inst, 1, extra.lhs); try s.writeAll(", "); - try w.writeOperand(s, inst, 2, extra.b); + try w.writeOperand(s, inst, 2, extra.rhs); } fn writeReduce(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {