zig
zig copied to clipboard
stage2: Runtime result of `@bitCast(u16, @Vector(16, bool))` is incorrect
Zig Version
0.10.0-dev.4430+78778899
Steps to Reproduce
const std = @import("std");
const expect = std.testing.expect;
test "bitcast vector to integer and back" {
var x = @splat(16, true);
x[1] = false;
try expect(@bitCast(u16, x) == 0xfffd);
}
Expected Behavior
Test should pass, like it does on stage1.
Actual Behavior
Test fails
Related #12812, stage1 handles both cases correctly by using insertelement/extractelement instead of getelementptr like stage2 does:
; stage2
define dso_local i32 @main() {
Entry:
%0 = alloca <16 x i1>, align 2
store <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, ptr %0, align 2
%1 = getelementptr inbounds <16 x i1>, ptr %0, i32 0, i64 1
store i1 false, ptr %1, align 1
%2 = load <16 x i1>, ptr %0, align 2
%3 = bitcast <16 x i1> %2 to i16
%4 = icmp ne i16 %3, -3
br i1 %4, label %Then, label %Else
Then:
call fastcc void @abort()
unreachable
Else:
ret i32 0
}
; stage1
define i32 @main() {
Entry:
%x = alloca <16 x i1>, align 2
store <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, ptr %x, align 2
%0 = load <16 x i1>, ptr %x, align 2
%1 = insertelement <16 x i1> %0, i1 false, i32 1
store <16 x i1> %1, ptr %x, align 2
%2 = load <16 x i1>, ptr %x, align 2
%3 = bitcast <16 x i1> %2 to i16
%4 = icmp ne i16 %3, -3
br i1 %4, label %Then, label %Else
Then:
call fastcc void @abort()
unreachable
Else:
ret i32 0
}
Fixed by #13959, test re-enabled in #14272