Skip to content
New issue

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

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

Already on GitHub? # to your account

64 bit shift is broken in nightly build for MIPS #116177

Closed
mcroomp opened this issue Sep 26, 2023 · 8 comments · Fixed by #117907
Closed

64 bit shift is broken in nightly build for MIPS #116177

mcroomp opened this issue Sep 26, 2023 · 8 comments · Fixed by #117907
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness O-MIPS Target: MIPS processors P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mcroomp
Copy link

mcroomp commented Sep 26, 2023

I tried this code:

const SHIFTVALUE : i64 = 10000000000i64;

fn main() {

    fn shiftleft(a : i64, b : i64) -> i64 {
        a << b
    }

    assert_eq!(shiftleft(black_box(SHIFTVALUE), black_box(2)), SHIFTVALUE << 2);
}

Nightly fails running on MIPS emulator

assertion left == right failed
left: 35705032704
right: 40000000000

Stable succeeds

Looks like the top and bottom dwords are mixed up

target is mips-unknown-linux-musl
emulator is qemu-mips-static

@mcroomp mcroomp added the C-bug Category: This is a bug. label Sep 26, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 26, 2023
@saethlin saethlin added O-MIPS Target: MIPS processors A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 26, 2023
@nikic
Copy link
Contributor

nikic commented Sep 26, 2023

This is probably related to llvm/llvm-project#64794.

@Noratrieb Noratrieb added the I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness label Sep 27, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 27, 2023
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Sep 28, 2023
@saethlin
Copy link
Member

saethlin commented Oct 7, 2023

This can be provoked on mips64 as well:

use std::hint::black_box;

const SHIFTVALUE: i128 = u64::MAX as i128;

fn main() {
    fn shiftleft(a: i128, b: i128) -> i128 {
        a << b
    }

    assert_eq!(
        shiftleft(black_box(SHIFTVALUE), black_box(2)),
        SHIFTVALUE << 2
    );
}

@matoro
Copy link

matoro commented Oct 9, 2023

Is this what's causing these build failures when upgrading from 1.72.0 to 1.73.0? Just checking before I open a new bug.

thread 'rustc' panicked at compiler/rustc_mir_build/src/build/mod.rs:1004:13:
apfloat::ieee::Double gave different result for `3.321928094887362`: 3.3219319068173765(0x400a9351091a8e71) vs Rust's 3.3219280948873622(0x400a934f0979a371)

I get a bunch of these on slightly different floating-point values on mips64.

@saethlin
Copy link
Member

saethlin commented Oct 9, 2023

Floats are hell, and also this landed with 1.73: #113843

A new issue is a good idea.

@CryZe
Copy link
Contributor

CryZe commented Oct 9, 2023

Yeah I've also been getting lots of different floating point related issues on 1.73 on MIPS. I too would've thought they are related to the shifts, but the new apfloat code could also be the reason.

@matoro
Copy link

matoro commented Oct 10, 2023

I applied the patch from llvm/llvm-project#64794 (comment) and confirmed that it fixes the 1.73.0 bootstrap problem for me. I also tried the snippet from @saethlin 's comment above and it did not assert after applying that patch.

@Cyanoxygen
Copy link
Contributor

It happened with {u,i}128, too. We stripped down the PoC to a few lines of LLVM IR code, and we reported to the upstream.
Turned out that it is exactly the same problem here.

bors added a commit to rust-lang-ci/rust that referenced this issue Nov 14, 2023
@bors bors closed this as completed in dd430bc Nov 14, 2023
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness O-MIPS Target: MIPS processors P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants