stage2: update vector alignment logic

This follows LLVM14's lead on vector alignment, which computes byte
count based on the length premultiplied by bits.

This commit also disables behavior tests regressed by LLVM 14, only for
stage1. stage2 fortunately does not trip the regression.
This commit is contained in:
Andrew Kelley 2022-07-03 13:33:09 -07:00
parent 15f111a085
commit b698168664
2 changed files with 15 additions and 3 deletions

View File

@ -2909,8 +2909,8 @@ pub const Type = extern union {
.vector => {
const len = ty.arrayLen();
const bits = try bitSizeAdvanced(ty.elemType(), target, sema_kit);
const bytes = (bits + 7) / 8;
const alignment = std.math.ceilPowerOfTwoAssert(u64, bytes * len);
const bytes = ((bits * len) + 7) / 8;
const alignment = std.math.ceilPowerOfTwoAssert(u64, bytes);
return AbiAlignmentAdvanced{ .scalar = @intCast(u32, alignment) };
},

View File

@ -5,6 +5,12 @@ const math = std.math;
const expect = std.testing.expect;
test "implicit cast vector to array - bool" {
if (builtin.zig_backend == .stage1) {
// Regressed in LLVM 14:
// https://github.com/llvm/llvm-project/issues/55522
return error.SkipZigTest;
}
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
@ -391,6 +397,12 @@ test "initialize vector which is a struct field" {
}
test "vector comparison operators" {
if (builtin.zig_backend == .stage1) {
// Regressed in LLVM 14:
// https://github.com/llvm/llvm-project/issues/55522
return error.SkipZigTest;
}
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
@ -1051,7 +1063,7 @@ test "@shlWithOverflow" {
test "alignment of vectors" {
try expect(@alignOf(@Vector(2, u8)) == 2);
try expect(@alignOf(@Vector(2, u1)) == 2);
try expect(@alignOf(@Vector(2, u1)) == 1);
try expect(@alignOf(@Vector(1, u1)) == 1);
try expect(@alignOf(@Vector(2, u16)) == 4);
}