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]
Other format: [Raw text]

Re: small test case for memset problem


> 
> Jan wanted a small test case for the memset issue I reported earlier.
> 
> Compile this with the 9.0 compiler on x86-64 with -O2:
> 
> static inline  __attribute__((always_inline)) void bitmap_clear(unsigned long *bitmap, int bits)
> {
>         __builtin_memset((unsigned long *)bitmap, 0, (((bits)+64 -1)/64)*sizeof(unsigned long));
> }
> 
> static void bla(unsigned long *nodes)
> {
>         bitmap_clear(nodes, (1 << 3));
> }
> 
> and you get
> 
> 	.text
> 	.p2align 4,,15
> 	.type	bla, @function
> bla:
> .LFB4:
> 	cld
> 	movl	$1, %ecx
> 	xorl	%eax, %eax
> 	rep
> 	stosq
> 	ret
> 
> Clearly it should be just
> 
> bla:
> 	movq $0,(%rdi)
> 	ret

The actual problem is that inliner don't constant propagate "bits"
argument into builtin call.  This can be fixed by adding "const"
modifier to the declaration, but it unforutnately won't solve the
problem (it does if bits is directly passed to builtin).

In this case we don't re-fold the operand so we end up with complex
constant expression.  Is there any easy way to deal with this?
I would say that for 3.4 we would get such we having to use macro for
this parituclar case...

Honza
> 	
> -Andi


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