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

Wrong result when turn on optimization on Vector compare. #1954

Open
xnhp0320 opened this issue Feb 11, 2025 · 2 comments
Open

Wrong result when turn on optimization on Vector compare. #1954

xnhp0320 opened this issue Feb 11, 2025 · 2 comments

Comments

@xnhp0320
Copy link

xnhp0320 commented Feb 11, 2025

import std::io;

macro splat($Type, x) {
    return $Type {x,x,x,x};
}

fn void main() {
    int[<4>] v1 = splat(int[<4>], 2);
    int[<4>] v2 = splat(int[<4>], 1);
    bool[<4>] vb = (v1 == v2);
    io::printf("hello world %s\n", vb);
}

c3c compile-run a.c3

Program linked to executable 'a'.
Launching ./a
hello world [<false, false, false, false>]

which is correct.

c3c compile-run -O2 a.c3

Program linked to executable 'a'.
Launching ./a
hello world [<false, true, false, false>]
Program completed with exit code 0.

which is not.

❯ c3c --version
C3 Compiler Version: 0.6.7 (Pre-release, Feb 10 2025 19:29:00)
Installed directory: /Users/penghe/src/c3c/build/
Git Hash: b46d394
Backends: LLVM
LLVM version: 18.1.8
LLVM default target: x86_64-apple-darwin23.4.0

@Book-reader
Copy link
Contributor

scalars will widen to vectors, so you can just do int[<4>] v1 = 2 and it will become {2, 2, 2, 2}

I can reproduce it with both with and without the splat macro on
C3 Compiler Version: 0.6.7 (Pre-release, Feb 10 2025 21:03:54)
Installed directory: /var/home/user/git/c3c/bin/
Git Hash: 8668027
Backends: LLVM
LLVM version: 18.1.8
LLVM default target: x86_64-pc-linux-gnu

@xnhp0320
Copy link
Author

scalars will widen to vectors, so you can just do int[<4>] v1 = 2 and it will become {2, 2, 2, 2}

cool, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants