Hi, I've code from verse (http://verse.blender.org/) which returns different results when run with optimizations. Steps to reproduce: run gcc test_simple.c then run compiled program and see what it prints. compile it with gcc -O2 (or higher). Resulting executable returns different result. Tested gcc versions: 3.4.6 - everything works there 4.3.0 - bug is reproducible 4.1.2 - the same as 4.3.0 I've tried to turn on optimization flags which are enabled by -O2 by parts (At first first half and then second half of flags) but in this case the problem is not present.
Created attachment 15516 [details] test code from verse
thanks to Ketling (one guy who helps me with identifying the bug) there is more progress: high = (uv & 0x80000000) != 0; is always zero.
What is correct, what is incorrect output? I get the same output 0x91F915BFDFAA69101B4D0720E517E6EAFAF7B231ADFFBBCDA5D630F51644A3466EC239357DA5989680018670CAAA4CA9CF5383B2E71A933A5608E3155DFF5071 for 3.3, 4.1, 4.2 and 4.3 for x86_64 and i686.
ok, there are subtle differences (too large number to look at), but which is correct, which is incorrect?
Looking at it.
-fno-tree-vrp "fixes" it, but D.2830_35: [0, 65535] D.2839_49: [0, 65535] D.2840_56: [0, +INF(OVF)] D.2829_34 = *D.2828_33; D.2830_35 = (int) D.2829_34; ... D.2838_48 = *D.2837_47; D.2839_49 = (int) D.2838_48; D.2840_56 = D.2830_35 * D.2839_49; high_59 = D.2840_56 < 0; looks suspiciously like a case of signed integer overflow undefinedness. uv = x[1 + j] * x[1 + i]; high = (uv & 0x80000000) != 0; the multiplication will be carried out in signed int because VBigDig, the type of *x, unsigned short, promotes to int. Thus the above is equivalent to uv = (unsigned int)((int)x[1 + j] * (int)x[1 + i]); high = (uv & 0x80000000) != 0; at which the compiler can conclude that the result of the multiplication is never negative. Fix this by doing uv = (VBigDigs)x[1 + j] * (VBigDigs)x[1 + i]; high = (uv & 0x80000000) != 0; instead.
Btw: gcc-4.3 -o t test_simple.c -O2 -Wstrict-overflow test_simple.c: In function 'v_bignum_square_half': test_simple.c:96: warning: assuming signed overflow does not occur when simplifying conditional to constant
Thanks a lot. Actually I'm a very beginner in C++ and I don't understand this code a lot.