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

Open
scottmcm opened this issue Nov 30, 2024 · 2 comments
Open

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

scottmcm opened this issue Nov 30, 2024 · 2 comments

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants