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]

expected_retval attribute proposal


Hi
One of the bits that may help somewhat to static branch prediction pass
in gcc is the knowedge that given function is returning some value
to signalize error and that error is unlikely to happen. This is
common for number of functions, so I think it may be profitable to add
attribute expected_retval (and probably also inexpected_retval)
so such functions can be marked in the glibc headers.

For example fputc can de marked as:
int fpuc (int c, FILE *stream) __attribute__ ((__inexpected_retval (EOF)));

What do you think? I basically see following drawbacks:
  1) gcc already contain some generic heruistics taking such error values
     into mind (such as comparing pointer against NULL).
  2) it is kludge and will make glibc headers less readable
  3) there are certainly places in the program where given call (feof)
     fails more often than in the average case
     and return value heruistics will not work well.

But still I think this is interesting bit that may improve program performance
somewhat with no extra effort from final user. Basically I am more firend of
idea of doing interprocedural analysis in gcc instead of adding such
attributes everywhere, but even with such analysis we will probably not
able to handle glibc...

Ideas?  If this turns out to be acceptable hack, I will implement the gcc
part. (well and glibc part to if neccesary...)

Honya

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