@@ -15919,26 +15919,27 @@ fn zirOverflowArithmetic(
1591915919 },
1592015920 .mul_with_overflow => {
1592115921 // If either of the arguments is zero, the result is zero and no overflow occured.
15922+ if (maybe_lhs_val) |lhs_val| {
15923+ if (!lhs_val.isUndef(zcu) and try lhs_val.compareAllWithZeroSema(.eq, pt)) {
15924+ break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = lhs };
15925+ }
15926+ }
15927+ if (maybe_rhs_val) |rhs_val| {
15928+ if (!rhs_val.isUndef(zcu) and try rhs_val.compareAllWithZeroSema(.eq, pt)) {
15929+ break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = rhs };
15930+ }
15931+ }
1592215932 // If either of the arguments is one, the result is the other and no overflow occured.
15923- // Otherwise, if either of the arguments is undefined, both results are undefined.
1592415933 const scalar_one = try pt.intValue(dest_ty.scalarType(zcu), 1);
15934+ const vec_one = try sema.splat(dest_ty, scalar_one);
1592515935 if (maybe_lhs_val) |lhs_val| {
15926- if (!lhs_val.isUndef(zcu)) {
15927- if (try lhs_val.compareAllWithZeroSema(.eq, pt)) {
15928- break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = lhs };
15929- } else if (try sema.compareAll(lhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {
15930- break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = rhs };
15931- }
15936+ if (!lhs_val.isUndef(zcu) and try sema.compareAll(lhs_val, .eq, vec_one, dest_ty)) {
15937+ break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = rhs };
1593215938 }
1593315939 }
15934-
1593515940 if (maybe_rhs_val) |rhs_val| {
15936- if (!rhs_val.isUndef(zcu)) {
15937- if (try rhs_val.compareAllWithZeroSema(.eq, pt)) {
15938- break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = rhs };
15939- } else if (try sema.compareAll(rhs_val, .eq, try sema.splat(dest_ty, scalar_one), dest_ty)) {
15940- break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = lhs };
15941- }
15941+ if (!rhs_val.isUndef(zcu) and try sema.compareAll(rhs_val, .eq, vec_one, dest_ty)) {
15942+ break :result .{ .overflow_bit = try sema.splat(overflow_ty, .zero_u1), .inst = lhs };
1594215943 }
1594315944 }
1594415945
@@ -15947,7 +15948,6 @@ fn zirOverflowArithmetic(
1594715948 if (lhs_val.isUndef(zcu) or rhs_val.isUndef(zcu)) {
1594815949 break :result .{ .overflow_bit = .undef, .wrapped = .undef };
1594915950 }
15950-
1595115951 const result = try arith.mulWithOverflow(sema, dest_ty, lhs_val, rhs_val);
1595215952 break :result .{ .overflow_bit = result.overflow_bit, .wrapped = result.wrapped_result };
1595315953 }
@@ -17751,10 +17751,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1775117751 try ty.resolveStructFieldInits(pt);
1775217752
1775317753 for (struct_field_vals, 0..) |*field_val, field_index| {
17754- const field_name = if (struct_type.fieldName(ip, field_index).unwrap()) |field_name|
17755- field_name
17756- else
17757- try ip.getOrPutStringFmt(gpa, pt.tid, "{d}", .{field_index}, .no_embedded_nulls);
17754+ const field_name = struct_type.fieldName(ip, field_index);
1775817755 const field_name_len = field_name.length(ip);
1775917756 const field_ty: Type = .fromInterned(struct_type.field_types.get(ip)[field_index]);
1776017757 const field_init = struct_type.fieldInit(ip, field_index);
@@ -28347,6 +28344,10 @@ fn elemPtrArray(
2834728344 break :o index;
2834828345 } else null;
2834928346
28347+ if (offset == null and array_ty.zigTypeTag(zcu) == .vector) {
28348+ return sema.fail(block, elem_index_src, "vector index not comptime known", .{});
28349+ }
28350+
2835028351 const elem_ptr_ty = try array_ptr_ty.elemPtrType(offset, pt);
2835128352
2835228353 if (maybe_undef_array_ptr_val) |array_ptr_val| {
@@ -28364,10 +28365,6 @@ fn elemPtrArray(
2836428365 try sema.validateRuntimeValue(block, array_ptr_src, array_ptr);
2836528366 }
2836628367
28367- if (offset == null and array_ty.zigTypeTag(zcu) == .vector) {
28368- return sema.fail(block, elem_index_src, "vector index not comptime known", .{});
28369- }
28370-
2837128368 // Runtime check is only needed if unable to comptime check.
2837228369 if (oob_safety and block.wantSafety() and offset == null) {
2837328370 const len_inst = try pt.intRef(.usize, array_len);
@@ -30399,22 +30396,6 @@ fn storePtr2(
3039930396
3040030397 const is_ret = air_tag == .ret_ptr;
3040130398
30402- // Detect if we are storing an array operand to a bitcasted vector pointer.
30403- // If so, we instead reach through the bitcasted pointer to the vector pointer,
30404- // bitcast the array operand to a vector, and then lower this as a store of
30405- // a vector value to a vector pointer. This generally results in better code,
30406- // as well as working around an LLVM bug:
30407- // https://github.com/ziglang/zig/issues/11154
30408- if (sema.obtainBitCastedVectorPtr(ptr)) |vector_ptr| {
30409- const vector_ty = sema.typeOf(vector_ptr).childType(zcu);
30410- const vector = sema.coerceExtra(block, vector_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) {
30411- error.NotCoercible => unreachable,
30412- else => |e| return e,
30413- };
30414- try sema.storePtr2(block, src, vector_ptr, ptr_src, vector, operand_src, .store);
30415- return;
30416- }
30417-
3041830399 const operand = sema.coerceExtra(block, elem_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) {
3041930400 error.NotCoercible => unreachable,
3042030401 else => |e| return e,
@@ -30447,29 +30428,6 @@ fn storePtr2(
3044730428
3044830429 try sema.requireRuntimeBlock(block, src, runtime_src);
3044930430
30450- if (ptr_ty.ptrInfo(zcu).flags.vector_index == .runtime) {
30451- const ptr_inst = ptr.toIndex().?;
30452- const air_tags = sema.air_instructions.items(.tag);
30453- if (air_tags[@intFromEnum(ptr_inst)] == .ptr_elem_ptr) {
30454- const ty_pl = sema.air_instructions.items(.data)[@intFromEnum(ptr_inst)].ty_pl;
30455- const bin_op = sema.getTmpAir().extraData(Air.Bin, ty_pl.payload).data;
30456- _ = try block.addInst(.{
30457- .tag = .vector_store_elem,
30458- .data = .{ .vector_store_elem = .{
30459- .vector_ptr = bin_op.lhs,
30460- .payload = try block.sema.addExtra(Air.Bin{
30461- .lhs = bin_op.rhs,
30462- .rhs = operand,
30463- }),
30464- } },
30465- });
30466- return;
30467- }
30468- return sema.fail(block, ptr_src, "unable to determine vector element index of type '{f}'", .{
30469- ptr_ty.fmt(pt),
30470- });
30471- }
30472-
3047330431 const store_inst = if (is_ret)
3047430432 try block.addBinOp(.store, ptr, operand)
3047530433 else
@@ -30569,37 +30527,6 @@ fn markMaybeComptimeAllocRuntime(sema: *Sema, block: *Block, alloc_inst: Air.Ins
3056930527 }
3057030528}
3057130529
30572- /// Traverse an arbitrary number of bitcasted pointers and return the underyling vector
30573- /// pointer. Only if the final element type matches the vector element type, and the
30574- /// lengths match.
30575- fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
30576- const pt = sema.pt;
30577- const zcu = pt.zcu;
30578- const array_ty = sema.typeOf(ptr).childType(zcu);
30579- if (array_ty.zigTypeTag(zcu) != .array) return null;
30580- var ptr_ref = ptr;
30581- var ptr_inst = ptr_ref.toIndex() orelse return null;
30582- const air_datas = sema.air_instructions.items(.data);
30583- const air_tags = sema.air_instructions.items(.tag);
30584- const vector_ty = while (air_tags[@intFromEnum(ptr_inst)] == .bitcast) {
30585- ptr_ref = air_datas[@intFromEnum(ptr_inst)].ty_op.operand;
30586- if (!sema.isKnownZigType(ptr_ref, .pointer)) return null;
30587- const child_ty = sema.typeOf(ptr_ref).childType(zcu);
30588- if (child_ty.zigTypeTag(zcu) == .vector) break child_ty;
30589- ptr_inst = ptr_ref.toIndex() orelse return null;
30590- } else return null;
30591-
30592- // We have a pointer-to-array and a pointer-to-vector. If the elements and
30593- // lengths match, return the result.
30594- if (array_ty.childType(zcu).eql(vector_ty.childType(zcu), zcu) and
30595- array_ty.arrayLen(zcu) == vector_ty.vectorLen(zcu))
30596- {
30597- return ptr_ref;
30598- } else {
30599- return null;
30600- }
30601- }
30602-
3060330530/// Call when you have Value objects rather than Air instructions, and you want to
3060430531/// assert the store must be done at comptime.
3060530532fn storePtrVal(
@@ -35579,8 +35506,13 @@ fn structFieldInits(
3557935506 const default_val = try sema.resolveConstValue(&block_scope, init_src, coerced, null);
3558035507
3558135508 if (default_val.canMutateComptimeVarState(zcu)) {
35582- const field_name = struct_type.fieldName(ip, field_i).unwrap().?;
35583- return sema.failWithContainsReferenceToComptimeVar(&block_scope, init_src, field_name, "field default value", default_val);
35509+ return sema.failWithContainsReferenceToComptimeVar(
35510+ &block_scope,
35511+ init_src,
35512+ struct_type.fieldName(ip, field_i),
35513+ "field default value",
35514+ default_val,
35515+ );
3558435516 }
3558535517 struct_type.field_inits.get(ip)[field_i] = default_val.toIntern();
3558635518 }
0 commit comments