Skip to content

mips64 crashes or hangs on 128 bit division #116440

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
AaronKutch opened this issue Oct 5, 2023 · 6 comments
Closed

mips64 crashes or hangs on 128 bit division #116440

AaronKutch opened this issue Oct 5, 2023 · 6 comments
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@AaronKutch
Copy link
Contributor

This target either crashes or hangs with different arguments to a 128 bit division

#[inline(never)]
fn test(x: u128, y: u128) -> u128 {
    x.wrapping_div(y)
}

fn main() {
    dbg!(test(123 << 64, (32 << 64) | 65));
    //dbg!(test(1 << 96,  1 << 64));
}

this happens with cross run --target mips64-unknown-linux-gnuabi64 -Z build-std=core,alloc,proc_macro,std, but I don't know how to get the version that cross is using, also #115218 .

@AaronKutch AaronKutch added the C-bug Category: This is a bug. label Oct 5, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 5, 2023
@saethlin
Copy link
Member

saethlin commented Oct 5, 2023

Is this a duplicate of #116177? (Are we using shifts to do the division)

@saethlin saethlin added the O-MIPS Target: MIPS processors label Oct 5, 2023
@AaronKutch
Copy link
Contributor Author

yes shifts are used internally, but when I saw that issue I assumed it only applied to the 32 bit version, if 64 bit MIPS is also affected it should be noted

@saethlin saethlin added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 5, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 5, 2023
@saethlin saethlin added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 5, 2023
@saethlin
Copy link
Member

saethlin commented Oct 5, 2023

I ran the reproducer for #116177 and as far as I can tell it succeeds on mips64-unknown-linux-gnuabi64. So I think this is a separate codegen bug?

@AaronKutch
Copy link
Contributor Author

maybe the reproducer needs to have its widths doubled to a 128 bit shift, a 64 bit shift would need a single instruction on mips64

@saethlin
Copy link
Member

saethlin commented Oct 6, 2023

I adjusted the reproducer for the other issue a bit into this, which does not pass the assert with your cross invocation:

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
    );
}

So I now think this is a duplicate of #116177. Do you agree?

@AaronKutch
Copy link
Contributor Author

yes, this should be closed then and the 64 bit version mentioned in the other thread?

@saethlin saethlin closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2023
@saethlin saethlin removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants