diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-14 12:38:56 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-14 12:38:56 -0400 |
| commit | 5919b10048be6efa8c0ca6bcb259706098b2d5ec (patch) | |
| tree | 307c504b85c9aee16602e667db1a5db5c25e1fff /src/Sema.zig | |
| parent | cb3b1dd6ddee65d1811fb4058b5cc0f2c06d0139 (diff) | |
| parent | b2a1b4c085b93d508c51307f40444252b8cd4d52 (diff) | |
| download | zig-5919b10048be6efa8c0ca6bcb259706098b2d5ec.tar.gz zig-5919b10048be6efa8c0ca6bcb259706098b2d5ec.zip | |
Merge pull request #11155 from ziglang/stage2-float-fixes
stage2 float fixes
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 1a760be4ef..99519cd562 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -4195,7 +4195,15 @@ fn zirDbgVar( const str_op = sema.code.instructions.items(.data)[inst].str_op; const operand = sema.resolveInst(str_op.operand); const operand_ty = sema.typeOf(operand); - if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty))) return; + switch (air_tag) { + .dbg_var_ptr => { + if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty.childType()))) return; + }, + .dbg_var_val => { + if (!(try sema.typeHasRuntimeBits(block, sema.src, operand_ty))) return; + }, + else => unreachable, + } const name = str_op.getStr(sema.code); // Add the name to the AIR. @@ -13268,7 +13276,7 @@ fn checkFloatType( ty: Type, ) CompileError!void { switch (ty.zigTypeTag()) { - .ComptimeFloat, .Float => {}, + .ComptimeInt, .ComptimeFloat, .Float => {}, else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ty}), } } @@ -17169,10 +17177,25 @@ fn storePtr2( return; } + // TODO do the same thing for anon structs as for tuples above. + + // Detect if we are storing an array operand to a bitcasted vector pointer. + // If so, we instead reach through the bitcasted pointer to the vector pointer, + // bitcast the array operand to a vector, and then lower this as a store of + // a vector value to a vector pointer. This generally results in better code, + // as well as working around an LLVM bug: + // https://github.com/ziglang/zig/issues/11154 + if (sema.obtainBitCastedVectorPtr(ptr)) |vector_ptr| { + const vector_ty = sema.typeOf(vector_ptr).childType(); + const vector = try sema.coerce(block, vector_ty, uncasted_operand, operand_src); + try sema.storePtr2(block, src, vector_ptr, ptr_src, vector, operand_src, .store); + return; + } + const operand = try sema.coerce(block, elem_ty, uncasted_operand, operand_src); + const maybe_operand_val = try sema.resolveMaybeUndefVal(block, operand_src, operand); const runtime_src = if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| rs: { - const maybe_operand_val = try sema.resolveMaybeUndefVal(block, operand_src, operand); const operand_val = maybe_operand_val orelse { try sema.checkPtrIsNotComptimeMutable(block, ptr_val, ptr_src, operand_src); break :rs operand_src; @@ -17195,6 +17218,39 @@ fn storePtr2( _ = try block.addBinOp(air_tag, ptr, operand); } +/// Traverse an arbitrary number of bitcasted pointers and return the underyling vector +/// pointer. Only if the final element type matches the vector element type, and the +/// lengths match. +fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref { + const array_ty = sema.typeOf(ptr).childType(); + if (array_ty.zigTypeTag() != .Array) return null; + var ptr_inst = Air.refToIndex(ptr) orelse return null; + const air_datas = sema.air_instructions.items(.data); + const air_tags = sema.air_instructions.items(.tag); + const prev_ptr = while (air_tags[ptr_inst] == .bitcast) { + const prev_ptr = air_datas[ptr_inst].ty_op.operand; + const prev_ptr_ty = sema.typeOf(prev_ptr); + const prev_ptr_child_ty = switch (prev_ptr_ty.tag()) { + .single_mut_pointer => prev_ptr_ty.castTag(.single_mut_pointer).?.data, + .pointer => prev_ptr_ty.castTag(.pointer).?.data.pointee_type, + else => return null, + }; + if (prev_ptr_child_ty.zigTypeTag() == .Vector) break prev_ptr; + ptr_inst = Air.refToIndex(prev_ptr) orelse return null; + } else return null; + + // We have a pointer-to-array and a pointer-to-vector. If the elements and + // lengths match, return the result. + const vector_ty = sema.typeOf(prev_ptr).childType(); + if (array_ty.childType().eql(vector_ty.childType()) and + array_ty.arrayLen() == vector_ty.vectorLen()) + { + return prev_ptr; + } else { + return null; + } +} + /// Call when you have Value objects rather than Air instructions, and you want to /// assert the store must be done at comptime. fn storePtrVal( |
