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

Chaining uadd.with.overflow should optimize to or disjoint #118162

Closed
scottmcm opened this issue Nov 30, 2024 · 3 comments
Closed

Chaining uadd.with.overflow should optimize to or disjoint #118162

scottmcm opened this issue Nov 30, 2024 · 3 comments
Labels
llvm:instcombine missed-optimization wontfix Issue is real, but we can't or won't fix it. Not invalid

Comments

@scottmcm
Copy link

The following code is useful for doing bigint addition, where you need to add the the digits from both numbers but also add a carry https://cpp.godbolt.org/z/c7PcWqbz7

bool uadd_with_carry(unsigned a, unsigned b, bool c, unsigned* out) {
    unsigned sum1;
    bool c1 = __builtin_uadd_overflow(a, b, &sum1);
    unsigned sum2;
    bool c2 = __builtin_uadd_overflow(sum1, (unsigned)c, &sum2);
    
    *out = sum2;
    return c1 | c2;
}

That c1 | c2 stays an or i1, but it would be legal for it to be or disjoint i1: https://alive2.llvm.org/ce/z/BMwvqN

(This is a C++ translation of Rust's https://doc.rust-lang.org/std/primitive.u32.html#method.carrying_add, cc rust-lang/rust#85532)

@AmrDeveloper
Copy link
Member

@dtcxzyw If it's confirmed and has priority I can start working on it

@dtcxzyw
Copy link
Member

dtcxzyw commented Dec 20, 2024

Similar with #118164, I am just wondering if we can get better codegen with or disjoint i1.

@scottmcm
Copy link
Author

I ended up just updating rust's implementation of this method to disjoint manually, so you can close this if you want.

@dtcxzyw dtcxzyw closed this as not planned Won't fix, can't repro, duplicate, stale Mar 24, 2025
@EugeneZelenko EugeneZelenko added the wontfix Issue is real, but we can't or won't fix it. Not invalid label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:instcombine missed-optimization wontfix Issue is real, but we can't or won't fix it. Not invalid
Projects
None yet
Development

No branches or pull requests

5 participants