Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting location of vector component for non-power-of-two type is broken on stage2 #12812

Closed
silversquirl opened this issue Sep 11, 2022 · 1 comment · Fixed by #13959
Closed
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. miscompilation The compiler reports success but produces semantically incorrect code. regression It worked in a previous version of Zig, but stopped working.
Milestone

Comments

@silversquirl
Copy link
Contributor

Zig Version

0.10.0-dev.3978+4fd4c733d

Steps to Reproduce

const std = @import("std");
pub fn main() !void {
    var x: std.meta.Vector(2, u15) = .{ 1, 4 };
    std.debug.print("{} {}\n", .{ (&x[0]).*, (&x[1]).* });
}

Expected Behavior

Output of 1 4

Actual Behavior

Output of 1 2, as the second integer is shifted down by 1 bit.

@silversquirl silversquirl added the bug Observed behavior contradicts documented or intended behavior label Sep 11, 2022
@Vexu Vexu added frontend Tokenization, parsing, AstGen, Sema, and Liveness. miscompilation The compiler reports success but produces semantically incorrect code. labels Sep 11, 2022
@Vexu Vexu added this to the 0.10.0 milestone Sep 11, 2022
@kkHAIKE
Copy link
Contributor

kkHAIKE commented Sep 23, 2022

I spent two days trying to fix this bug and found that the problem is not easy..

solution from stage1 is that if 'airLoad' get a ptr to elem of vector, then add llvm-ir load(vec_ptr) + ExtractElement(vec_ptr, idx), but I don't think it works in all cases.

another solution is to modify the following places:

  1. 'fn Sema.elemPtrType' when if 'ptr_ty == vector' and 'bits mod 8 != 0'(eg: u15):
    1. if 'offset != null', then calc 'host_size' and 'bit_offset' corrently.
    2. if 'offset == null', means the index is runtime-known, then return a ?:
      1. new pointer type vector_elem_ptr
      2. or current pointer type add new field maybe 'vector_index' (statge1)
      3. must ensure that this pointer type cannot be convert/cast to other type !!!!.
  2. 'fn Sema.analyzeLoad' when if get the new pointer type, try to find vector_ptr, and add air 'load(vec_ptr) + array_elem_val(vec_ptr, index)

@andrewrk andrewrk modified the milestones: 0.10.0, 0.10.1 Oct 31, 2022
@Vexu Vexu added the regression It worked in a previous version of Zig, but stopped working. label Dec 15, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 15, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 15, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 15, 2022
andrewrk pushed a commit that referenced this issue Dec 16, 2022
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. miscompilation The compiler reports success but produces semantically incorrect code. regression It worked in a previous version of Zig, but stopped working.
Projects
None yet
4 participants