https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118222

Muqi <zou116 at purdue dot edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |FIXED
             Status|RESOLVED                    |CLOSED

--- Comment #3 from Muqi <zou116 at purdue dot edu> ---
(In reply to Andrew Pinski from comment #2)
> (In reply to Andrew Pinski from comment #1)
> > GCC has an IPA RA.
> > So if is_ENOTSUP is local to that file, GCC will see if edx is not clobbered
> > by that function, GCC can assume it can be used across the call.
> > 
> > I am suspecting you are seeing that effect.
> 
> Yes that is exactly it.
> 
> is_ENOTSUP is defined in sys/system.h as:
> ```
> static inline bool
> is_ENOTSUP (int err)
> {
>   return err == EOPNOTSUPP || (ENOTSUP != EOPNOTSUPP && err == ENOTSUP);
> }
> ```
> 
> So when not inlined, GCC's IPA RA comes into play and knows that is_ENOTSUP
> does not clobber edx at all so it knows that specific call is not going to
> clobber edx so it can use it as such.
> 
> This is 100% valid optimization since the function binds local to the TU and
> the call does NOT need to use the full x86_64 ABI here since GCC knows it
> can't be changed out.
> 
> Aka this is by design, GCC 5 added this IPA optimization.

Yes, I tried "-fno-ipa-ra" and the register used is replaced with rbx. From the
binary analysis side, this is interesting to see the compiler does not fully
follow the clobber abi. I have closed this issue. Thanks a lot!

Btw, the command line I used is "gcc -c -O2 -fno-inline -I../lib copy.c", sorry
for the late updates.

Reply via email to