-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Miscompile on some targets #143399
Copy link
Copy link
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesIssue expected to be fixed by the next major LLVM upgrade, or backported fixes
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesIssue expected to be fixed by the next major LLVM upgrade, or backported fixes
Type
Fields
Give feedbackNo fields configured for issues without a type.
Not sure if this is an Internal Compiler Error or a Bug, apologies if I picked the wrong one. (To be honest I'm also not sure if this is Rust's fault or LLVM so I will post something to the LLVM folks as well).
Recently I have been running into some strange errors which seem to only occur on some architectures. See
Plonky3/Plonky3#729
Plonky3/Plonky3#905
For more info about the situation where these arose. I managed to make a minimal example in Godbolt so I thought it made sense to post this here.
Code
Probably easier to understand in the following Godbolt link: https://godbolt.org/z/rrrj3eobd
Basically we define a simple function which adds integers mod a prime
P. We then use this on vectors of length4. What you find is that if you check(x + y) + z = x + (y + z)manually, everything works as expected and they agree. If however we define a function which computes(x + y) + z,x + (y + z)and then checks that they are equal we get an error. I agree this seems totally bizarre, please check out the Godbolt.Meta
The error occurs when compiling with current rustc 1.880, beta and nightly. It seems to have been introduced in the move to
LLVM 20as these errors do not appear onnightly-2025-02-17but things begin failing onnightly-2025-02-18.The error occurs when using the compiler flags:
-O -C target-cpu=znver4 -C opt-level=3.It does not occur with
opt-level=0, 1, 2, it does however occur with some other target cpus in particularmic_avx512andznver5but not with others such asskylake, skylake_avx512, alderlake, raptorlake. (If you want a complete list I can go through and check them all)Error output
See the Godbolt link for more details. Essentially what seems to be happening is that something goes wrong in the vectorization code? It's hard to say exactly what though. The compiled code for
check_assocseems to be reasonable? We are pretty lost as to what is going on.