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

            Bug ID: 68804
           Summary: Code generated by _addcarry_u64 is wrong in O3 mode
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: furyusss at yahoo dot fr
  Target Milestone: ---

When compiled with -O3, the following code generates incorrect assembly code on
my machine:

int main()
{
        unsigned long long r;

        _addcarry_u64(0, 0, 9872702152712425062ull, &r);

        unsigned long long test_h = 8574040432038206621ull + r;

        unsigned long long h = (test_h << 8) | (218ull);

        unsigned long long p;

        _addcarry_u64(1, h, 258554859004771ull, &p);

        if (p == 18446621455085053758ull)
        {
                std::cout << "OK!";
        }
        else
        {
                std::cout << "KO!";
        }
        return 0;
}

In the second _addcarry_u64, the 1 input is ignored and the result is
18446621455085053757ull. 


Replacing the first _addcarry_u64 by r = 9872702152712425062ull gives the
correct result.

Reply via email to