authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-19 12:18:55+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-19 12:19:52+02:00
log2926d95e6a7c4d83eb197f78de40718e97bc1f1b
treeb3ad8e54eb60e5b4f8eb0e63308a987102369786
parent0eddf0cbc0a88121a67239d5899dca8a39c39cd8

llvm: handle vectors in packed structs

Closes #13201

2 files changed, 3 insertions(+), 6 deletions(-)

src/codegen/llvm.zig+3-3
...@@ -5966,7 +5966,7 @@ pub const FuncGen = struct {...@@ -5966,7 +5966,7 @@ pub const FuncGen = struct {
5966 const shift_amt = containing_int.typeOf().constInt(bit_offset, .False);5966 const shift_amt = containing_int.typeOf().constInt(bit_offset, .False);
5967 const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");5967 const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");
5968 const elem_llvm_ty = try self.dg.lowerType(field_ty);5968 const elem_llvm_ty = try self.dg.lowerType(field_ty);
5969 if (field_ty.zigTypeTag() == .Float) {5969 if (field_ty.zigTypeTag() == .Float or field_ty.zigTypeTag() == .Vector) {
5970 const elem_bits = @intCast(c_uint, field_ty.bitSize(target));5970 const elem_bits = @intCast(c_uint, field_ty.bitSize(target));
5971 const same_size_int = self.context.intType(elem_bits);5971 const same_size_int = self.context.intType(elem_bits);
5972 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");5972 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
...@@ -5989,7 +5989,7 @@ pub const FuncGen = struct {...@@ -5989,7 +5989,7 @@ pub const FuncGen = struct {
5989 assert(struct_ty.containerLayout() == .Packed);5989 assert(struct_ty.containerLayout() == .Packed);
5990 const containing_int = struct_llvm_val;5990 const containing_int = struct_llvm_val;
5991 const elem_llvm_ty = try self.dg.lowerType(field_ty);5991 const elem_llvm_ty = try self.dg.lowerType(field_ty);
5992 if (field_ty.zigTypeTag() == .Float) {5992 if (field_ty.zigTypeTag() == .Float or field_ty.zigTypeTag() == .Vector) {
5993 const elem_bits = @intCast(c_uint, field_ty.bitSize(target));5993 const elem_bits = @intCast(c_uint, field_ty.bitSize(target));
5994 const same_size_int = self.context.intType(elem_bits);5994 const same_size_int = self.context.intType(elem_bits);
5995 const truncated_int = self.builder.buildTrunc(containing_int, same_size_int, "");5995 const truncated_int = self.builder.buildTrunc(containing_int, same_size_int, "");
...@@ -9889,7 +9889,7 @@ pub const FuncGen = struct {...@@ -9889,7 +9889,7 @@ pub const FuncGen = struct {
9889 return result_ptr;9889 return result_ptr;
9890 }9890 }
98919891
9892 if (info.pointee_type.zigTypeTag() == .Float) {9892 if (info.pointee_type.zigTypeTag() == .Float or info.pointee_type.zigTypeTag() == .Vector) {
9893 const same_size_int = self.context.intType(elem_bits);9893 const same_size_int = self.context.intType(elem_bits);
9894 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");9894 const truncated_int = self.builder.buildTrunc(shifted_value, same_size_int, "");
9895 return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");9895 return self.builder.buildBitCast(truncated_int, elem_llvm_ty, "");
test/behavior/bitcast.zig-3
...@@ -358,9 +358,6 @@ test "comptime @bitCast packed struct to int and back" {...@@ -358,9 +358,6 @@ test "comptime @bitCast packed struct to int and back" {
358 const rt_cast = @bitCast(S, i);358 const rt_cast = @bitCast(S, i);
359 const ct_cast = comptime @bitCast(S, @as(Int, 0));359 const ct_cast = comptime @bitCast(S, @as(Int, 0));
360 inline for (@typeInfo(S).Struct.fields) |field| {360 inline for (@typeInfo(S).Struct.fields) |field| {
361 if (@typeInfo(field.type) == .Vector)
362 continue; //TODO: https://github.com/ziglang/zig/issues/13201
363
364 try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name));361 try expectEqual(@field(rt_cast, field.name), @field(ct_cast, field.name));
365 }362 }
366}363}