This is the mail archive of the gcc@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]

Re: Fields, unions, and code quality


Andrew Pinski writes:
 > 
 > On Jun 20, 2006, at 7:20 AM, Andrew Haley wrote:
 > 
 > > Does using fields of auto variables of union type generate code that
 > > is less efficient than it would be using scalars?
 > 
 > If it is only one used field at a time (and the address is not taken),
 > then FRE will resolve them.
 > 
 > Take:
 > int f(int t, int t1)
 > {
 > 
 > union f
 > {
 >    int n;
 >    float n1;
 > } f1, f2;
 > f1.n = t;
 > f2.n1 = t1;
 > int t2 = f1.n;
 > f1.n1 = t2;
 > return f1.n1 + f2.n1 * f1.n1;
 > }
 > 
 > in final_cleanup, we get:
 >    D.1522 = (float) t;
 >    return (int) (D.1522 + (float) t1 * D.1522);

OK, thanks.

Andrew.


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