Skip to content

Vectorized code computes a different result from the unvectorized code (see later comments) #63185

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

Closed
wsmoses opened this issue Jun 8, 2023 · 10 comments
Labels
julialang question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! vectorizers

Comments

@wsmoses
Copy link
Member

wsmoses commented Jun 8, 2023

Edit: the bug is not related to address spaces, see later comments:

The following code examples are equivalent except for one having a non-zero address space for the first arg or not. The non-zero address space version is incorrectly marked as vectorizable whereas the second one is not.

Illegal case: https://godbolt.org/z/Wjodd6n5x
Correct case: https://godbolt.org/z/svPhcT84x

cc @vchuravy @jdoerfert

@llvmbot
Copy link
Member

llvmbot commented Jun 8, 2023

@llvm/issue-subscribers-julialang

@jdoerfert
Copy link
Member

The good version is not vectorized because:

LAA: Runtime check would require comparison between different address spaces
LAA: We can't vectorize because we can't find the array bounds.

@wsmoses
Copy link
Member Author

wsmoses commented Jun 8, 2023

Yeah I minimized this one slightly too far, a moment.

@wsmoses
Copy link
Member Author

wsmoses commented Jun 8, 2023

In essence this code (https://godbolt.org/z/11drEMfjx) when run through Julia's LLVM pass pipeline creates a bug. It should print 1.0, but optimizes to 2.0

@wsmoses
Copy link
Member Author

wsmoses commented Jun 8, 2023

out_a2.txt

@wsmoses
Copy link
Member Author

wsmoses commented Jun 8, 2023

Here is it post vectorization (see it prints 2): https://godbolt.org/z/4vqzxMbd8
Here is it pre vectorization (see it prints 1): https://godbolt.org/z/aGM6Td4T6

Here is the vectorization itself as an llvm pass on trunc: https://godbolt.org/z/431xo6Tfc

@wsmoses wsmoses changed the title Illegal vectorization on Non-zero address space Vectorized code computes a different result from the unvectorized code (see later comments) Jun 8, 2023
@wsmoses
Copy link
Member Author

wsmoses commented Jun 8, 2023

@fhahn if you might have any insights here.

@fhahn
Copy link
Contributor

fhahn commented Jun 9, 2023

Hmm interesting, let me take a look in a bit

@artagnon
Copy link
Contributor

The issue seems to be fixed now. I ran the optimization pipeline you showed minus the -opaque-pointers=0, since that option no longer exists, and got the same output of 1.

@fhahn
Copy link
Contributor

fhahn commented May 7, 2025

Closing as per @artagnon's comment. @wsmoses please re-open if this still reproduces on your end

@fhahn fhahn closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2025
@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label May 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
julialang question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! vectorizers
Projects
None yet
Development

No branches or pull requests

7 participants