How to control GCC builtin functions optimization

2019-01-10 Thread Cao jin
Hi,
(pls CC me when replying because I am not subscriber)

I met an interesting phenomenon when looking into linux kernel
compilation, it can be simply summarized as following: in
arch/x86/boot/compressed, memcpy is defined as __builtin_memcpy, while
also implemented as a function. But when using memcpy, in some case GCC
optimize it to inline code, in other case GCC just emit a call to
self-defined memcpy function. This can be confirmed according to the
symbol table via `nm bluh.o`.

The compiling flags is, for example:
cmd_arch/x86/boot/compressed/pgtable_64.o := gcc
-Wp,-MD,arch/x86/boot/compressed/.pgtable_64.o.d  -nostdinc -isystem
/usr/lib/gcc/x86_64-redhat-linux/8/include -I./arch/x86/include
-I./arch/x86/include/generated  -I./include
-I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi
-I./include/uapi -I./include/generated/uapi -include
./include/linux/kconfig.h -include ./include/linux/compiler_types.h
-D__KERNEL__ -DCONFIG_CC_STACKPROTECTOR -m64 -O2 -fno-strict-aliasing
-fPIE -DDISABLE_BRANCH_PROFILING -mcmodel=small -mno-mmx -mno-sse
-ffreestanding -fno-stack-protector-DKBUILD_BASENAME='"pgtable_64"'
-DKBUILD_MODNAME='"pgtable_64"' -c -o
arch/x86/boot/compressed/pgtable_64.o arch/x86/boot/compressed/pgtable_64.c

Now the questions is: from code-reading, it is kind of non-intuitive, is
there any explicit way to control the optimization behavior accurately?
-- 
Sincerely,
Cao jin




Re: How to control GCC builtin functions optimization

2019-01-11 Thread Cao jin
Hi Martin,

On 1/11/19 5:22 PM, Martin Liška wrote:
> On 1/11/19 4:03 AM, Cao jin wrote:
>> Now the questions is: from code-reading, it is kind of non-intuitive, is
>> there any explicit way to control the optimization behavior accurately?
> 
> Hi.
> 
> Please take a look here:
> https://gcc.gnu.org/onlinedocs/gcc.pdf

Yes, I already have it and spent some time on it. It just a little bit
difficult for GCC newbie to find the answer accurately(I searched some
of the used flags).

> 
> you are searching for:
> -mmemcpy
> -mno-memcpy
> Force (do not force) the use of memcpy for non-trivial block moves. The 
> default
> is ‘-mno-memcpy’, which allows GCC to inline most constant-sized copies

I tried -mmemcpy, it seems these two are not for x86.

> 
> and possibly for:
> -mmemcpy-strategy
> 
> and
> -mstringop-strategy=alg
> 

And yes, -mmemcpy-strategy worked as I expected.
Thanks very much!

-- 
Sincerely,
Cao jin




Re: How to control GCC builtin functions optimization

2019-01-11 Thread Cao jin
On 1/11/19 7:09 PM, Cao jin wrote:
> Hi Martin,

>>
>> and possibly for:
>> -mmemcpy-strategy
>>
>> and
>> -mstringop-strategy=alg
>>
> 
> And yes, -mmemcpy-strategy worked as I expected.

typo. It is -mstringop-strategy=byte_loop

-- 
Sincerely,
Cao jin