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

--- Comment #5 from cbcode at gmail dot com ---
(In reply to H.J. Lu from comment #4)
> (In reply to cbcode from comment #2)
> > Created attachment 44621 [details]
> > test reproducing the problem
> 
> How to show the problem?

Save the attachment as test.cpp, compile, run and look at the output:
g++ -std=c++11 -O3 -o test test.cpp && ./test 10

function bigmul() multiplies two arbitrary-precision integers, and main()
generates a few random examples and format them as a python3-script, consisting
of lines of the form:
if a * b != expected: print a, b, expected, a * b

To run the tests, do:
g++ -std=c++11 -O3 -o test test.cpp && ./test 10 | python3

If the gcc version is not 6, or if the optimization level is below -O3, all
checks will pass and there is no output.

With the default g++ in amd64-debian-stable at the time of this writing (gcc
version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)) I get the following output:

$ g++ -std=c++11 -O3 -o test test.cpp && ./test 10 | python3
0xbeeb8da1658eec67910a2dec89025cc1 * 0x71c18690ee42c90bf893a2eefb32555e
= 0x54d64d7566d4996250f93066b9e161138d4d6f3a582b5c4f9f3bd72d705c23de
? 0x54d64d7566d4996250f93066b9e161128d4d6f3a582b5c4f9f3bd72d705c23de
0xc34d0bff9015028071bb54d8d101b5b9 * 0x85e7bb0f12278575e099ec6cd7363ca5
= 0x6627d0766096e0e087e772aabc35719b32092fcf64d348f16eb53cc1d0b77c3d
? 0x6627d0766096e0e087e772aabc35719a32092fcf64d348f16eb53cc1d0b77c3d
0xcb435c8e74616796491718de357e3da8 * 0x9afcd44d14cf8bfe6775dc7701564f61
= 0x7b0f448dcaac0546958108e31e6bff5afc779f31bc686ccf2bbb7e72984c34a8
? 0x7b0f448dcaac0546958108e31e6bff59fc779f31bc686ccf2bbb7e72984c34a8
0x87b341d690d7a28a7476cf8a4baa5dc0 * 0x2ac2ce17a5794a3b6f9b6dae6f4c57a8
= 0x16aaabe3e0298b6b287985777faad3121c5e6216bd208bf75d540032a2a9c600
? 0x16aaabe3e0298b6b287985777faad3111c5e6216bd208bf75d540032a2a9c600
0xd0bad0da572baaf1a534a6a6b7fd0b63 * 0xe263183773ef6508ae84379630af89ee
= 0xb895b85e3fa2b67d1b3b3243d7509b6b0ca8fe779ebdc9d4475c5094d105910a
? 0xb895b85e3fa2b67d1b3b3243d7509b6a0ca8fe779ebdc9d4475c5094d105910a
0x70616f2f48dce01c65ace2685a072c6d * 0x879e2e2256feff0c40d6824e2ef3fc17
= 0x3b88d20523b761dd4aec1ed139f28c4baa0e1564fccd5926707eb1ffe7d749cb
? 0x3b88d20523b761dd4aec1ed139f28c4aaa0e1564fccd5926707eb1ffe7d749cb
0xbf8c59bb003553c18b2e02445e4be0f5 * 0xab27a171be5b133cd16aa4b296eb9d18
= 0x8010671df4712da0478a910d2b8b019bd201c56c8ce38b81bf08880e6efa57f8
? 0x8010671df4712da0478a910d2b8b019ad201c56c8ce38b81bf08880e6efa57f8

7 out of 10 tests fail, there is bit flipped somewhere in the middle.

g++ -std=c++11 -O2 -o test test.cpp && ./test 10 | python3
passes all tests, as does g++ -O3 with a gcc version other than 6.x.

The problem seems to require the presence of loops (and presumably their
unrolling), and the add_overflow and add_carry need to appear next to each
other without anything in between. I was not able to narrow it down further.

Reply via email to