[Bug target/43892] PowerPC suboptimal "add with carry" optimization

segher at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jun 3 04:33:58 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43892

--- Comment #33 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #32)
> So it is more about the back-end of PowerPC at this point.

For the testcase

===
typedef unsigned int u32;
typedef unsigned long long u64;

u32 f(u32 a, u32 b)
{
        u32 s = a + b;
        if (a + b < b)
                s++;
        return s;
}

u32 g(u32 *p, u32 n)
{
        u32 s = 0;
        while (n--)
                s = f(s, *p++);
        return s;
}

u32 g4(u32 *p)
{
        u32 s = 0;
        s = f(s, *p++);
        s = f(s, *p++);
        s = f(s, *p++);
        s = f(s, *p++);
        return s;
}

u32 h4(u32 *p)
{
        u64 s = 0;
        s += *p++;imple
        s += *p++;
        s += *p++;
        s += *p++;
        s = (s >> 32) + (u32)s;
        s = (s >> 32) + (u32)s;
        return s;
}
===

... GCC does not do anything with ADD_OVERFLOW.  But all *do* compile
to reasonable code (albeit not optimal).  So no, you cannot say Gimple
is super here and it is all the backend's fault :-)


More information about the Gcc-bugs mailing list