This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Some __builtin_round and cast subtleties
- From: Kyrill Tkachov <kyrylo dot tkachov at arm dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Fri, 04 Jul 2014 09:41:05 +0100
- Subject: Some __builtin_round and cast subtleties
- Authentication-results: sourceware.org; auth=none
Hi all,
Consider code:
long int
foo (double a)
{
return __builtin_round (a);
}
Compiling for aarch64-none-elf (bare-metal aarch64 with newlib as
C-library) with -O2 gives the 003t.original dump:
;; Function foo (null)
;; enabled by -tree-original
{
return (long int) __builtin_round (a);
}
whereas compiling for aarch64-none-linux-gnu (linux target with glibc)
gets translated into:
;; Function foo (null)
;; enabled by -tree-original
{
return __builtin_lround (a);
}
These end up taking different codepaths through the compiler () because
__builtin_lround has to take -fmath-errno into account and does not end
up getting inlined (generating a call to the library lround).
__builtin_round, however, is defined everywhere and ends up getting
expanded to a
rounddf optab + (set r:DI (fix:DI (r:DF)))
which then later gets combined into the expansion we've got for the
lrounddfdi2 optab
Is that correct/expected behaviour?
I tried grepping around the gcc sources but I'm not familiar with code
that would do the frontend transformation mentioned above.
Thanks,
Kyrill