Description of Problem: gcc -O2 produces incorrect biniaries. Version-Release number of selected component (if applicable): gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-87) How Reproducible: Each and every time. Steps to Reproduce: 1. Put the following program in a file, maybe called bug.c, as follows: #include <stdio.h> #define round(a) (int)(((a)<0.0)?(a)-.5:(a)+.5) int zoomxoff; short SHZOOMX(int x) { x = round(0.7*((x)-zoomxoff)); return (short) x; } int main() { zoomxoff = 0; printf ("SHZOOMX(%d) = %hd (should be 70)\n", 100, SHZOOMX(100)); printf ("SHZOOMX(%d) = %hd (should be -70)\n", -100, SHZOOMX(-100)); return 0; } 2. Compile the program with: gcc -O2 -o bug bug.c 3. Execute the program with: ./bug Actual Results: SHZOOMX(100) = 0 (should be 70) SHZOOMX(-100) = -70 (should be -70) Expected Results: SHZOOMX(100) = 70 (should be 70) SHZOOMX(-100) = -70 (should be -70) Additional Information: This problem goes away if you compile with 'gcc -O2 -fno-sched-interblock'. The bug also occurs thru gcc-3.0.4 released Feb 20, 2002, but goes away in gcc-3.1-prerelease dated April 01, 2002. Please let me know if I can be of further assitance. Best Regards, --George
Created attachment 77066 [details] sample program that shows this problem.
I have attached another variation of the same type of code that fails in different optimization passes. Best Regards, --George
After our chat in IRC... I believe you've resolved this now. Could you attach the patch here, so we can ensure it gets into future erratum also?
gcc-2.96 is too old now. Its release cycle was finished long ago. Also I've checked the current state of gcc-3_0-branch. The bug was gone. So I am closing the bug. If it is still important to fix the bug in gcc-2.96, the customer could reopen the case.