"Rohit Arul Raj" <[EMAIL PROTECTED]> writes:

> > > This small bit of code worked fine with all optimization except Os.
> > >
> > > unsigned int n = 30;
> > > void x ()
> > > {
> > >  unsigned int h;
> > >  h = n <= 30;           // Line 1
> > >  if (h)
> > >    p = 1;
> > >  else
> > >    p = 0;
> > > }
> > >
> > > when we tried to debug the emitted RTL instruction for Os, it was
> > > found that RTL instruction for Line #1 (Compare and gtu) were not at
> > > all emitted. i.e. there is no reference with respect to "h or n". For
> > > the same optimization Os, if we declare the identifier "h" as global,
> > > it generates the instructions properly.
> >
> > That small bit of code won't compile, since 'p' is undeclared.  If 'p'
> > is a global variable, then this certainly seems to be a bug.  But you
> > should be aware that -Os changes inlining behaviour, and different
> > inlining may cause different behaviour here depending on how 'p' is
> > used.
> 
> p is a global variable. But the problem is not with p, but with
> codegeneration for h, n.

Sure.  But the most likely reason that the test of 'h' is being
removed is that the compiler thinks that there is no need to store to
'p'.  And once the test of 'h' is removed, there is no need to test
'n'.

> In the RTL dump after cse2 pass, i do have the code for h, n. But in
> the RTL dump after life analysis, that part of code is missing.
> Is this output of cse2 pass used for life analysis?

If I understand the question correctly, then the answer is yes.  The
compiler works by creating an intermediate representation (IR) and
then manipulating it.  The cse2 pass runs on the IR, then the life1
pass runs on the IR.  The .cse2 file contains a dump of the IR after
the cse2 pass is complete.


> > > 3. What are the probable causes for the elimination of RTL code's
> > > (Compare & gtu) between the above mentioned passes?
> >
> > The probable cause is that 'p' appears to be unused, and the
> > assignment to 'p' is dead.
> >
> since p is a global variable, it can be used in other functions. Any
> other causes?

I can't think of any.


> 4. If i disable gcse optimization pass, (i.e. -Os -fno-gcse), the code
> is generated properly for h , n and the program works fine (it failed
> for -Os). How does gcse affect code generation at .life1 pass.

The gcse pass can change the IR significantly, and thus affects the
life1 pass in many different ways which are difficult to characterize.

You really have to look at what exactly is going on.

ian

Reply via email to