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



--- Comment #4 from rguenther at suse dot de <rguenther at suse dot de> 
2012-10-18 10:58:56 UTC ---

On Thu, 18 Oct 2012, siarhei.siamashka at gmail dot com wrote:



> 

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

> 

> --- Comment #3 from Siarhei Siamashka <siarhei.siamashka at gmail dot com> 
> 2012-10-18 10:47:51 UTC ---

> (In reply to comment #2)

> > void combine_conjoint_xor_ca_float ()

> > {

> >     combine_channel_t j = pd_combine_conjoint_xor, k = 
> > pd_combine_conjoint_xor;

> >     a[0] = k (0, b, 0, a[0]);

> >     a[0] = k (0, b, 0, a[0]);

> >     a[0] = k (0, b, 0, a[0]);

> >     a[0] = j (0, c[0], 0, a[0]);

> >     a[0] = k (0, c[0], 0, a[0]);

> >     a[0] = k (0, c[0], 0, a[0]);

> >     a[0] = k (0, c[0], 0, a[0]);

> > 

> > you are using indirect function calls here, GCC in 4.6 is not smart enough

> > to transform them to direct calls before inlining.  Inlining of

> > always-inline indirect function calls is not going to work reliably.

> 

> Does this only apply to GCC 4.6?



No, that applies in general.  If GCC isn't able to figure out which

function is called it cannot make sure always-inline functions are

always inlined.  always-inline is an attribute that should be used

if it is incorrect to not inline, not if that's just good for 

optimziation.



> > Don't use always-inline or don't use indirect function calls to 
> > always-inline

> > functions.

> 

> This looks like it might be really inconvenient. Pixman relies on this

> functionality in a number of places by doing something like this:

> 

> void always_inline per_pixel_operation_a(...)

> {

>     ...

> }

> 

> void always_inline per_pixel_operation_b(...)

> {

>     ...

> }

> 

> void always_inline big_function_template(..., per_pixel_operation_ptr foo)

> {

>     ...

>     /* do some calls to foo() in an inner loop */

>     ...

> }

> 

> void big_function_a(...)

> {

>     big_function_template(..., per_pixel_operation_a);

> }

> 

> void big_function_b(...)

> {

>     big_function_template(..., per_pixel_operation_b);

> }

> 

> Needless to say that we want to be absolutely sure that per-pixel operations

> are always inlined. Otherwise the performance gets really bad if the compiler

> ever makes a bad inlining decision.

> 

> The same functionality can be probably achieved by replacing always_inline

> functions with macros. But the code becomes less readable, more error prone 
> and

> somewhat more difficult to maintain.



In the above case you probably want big_function_a to have all

calls inlined.  You can then conveniently use the flatten attribute:



void __attribute__((flatten)) big_function_b (...)

{

  big_function_template(..., per_pixel_operation_b);

}



GCC will then inline all calls in that function but not ICE

when it fails to inline one case for some weird reason.



Richard.

Reply via email to