This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/16157] gcc fails to optimize redundant expression


------- Additional Comments From bangerth at dealii dot org  2004-06-23 13:58 -------
Well, the testcase may be a little deceiving: since you write back into 
the same variables, the additions can only be merged by CSE if you have 
a place to store intermediate results. At least on x86, there aren't 
enough registers to do that, so one would have to move them to the stack 
and back before writing all intermediate results to their destinations. That 
may well be more expensive than using more additions. 
 
However, with this testcase, that problem doesn't exist: 
------------------ 
extern int a0, a1, a2, a3, a4; 
extern int b0, b1, b2, b3, b4; 
void f () 
{ 
        /* this can be optimized to four additions... */ 
        b4 = a4 + a3 + a2 + a1 + a0; 
        b3 = a3 + a2 + a1 + a0; 
        b2 = a2 + a1 + a0; 
        b1 = a1 + a0; 
} 
----------------------- 
The compiler should recognize that it can revert the order in which 
b4...b1 are computed, and then do so to avoid additional additions. 
It doesn't do so, however. 
 
W. 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-06-23 13:58:59
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16157


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]