[cfe-dev] missing optimization opportunity for const std::vector compared to std::array

dennis luehring dl.soluz at gmx.net
Wed May 28 04:35:34 PDT 2014


i've rechecked against 

gcc.http://gcc.godbolt.org/
*clang version 3.4.1
*gcc 4.9 20130909 
with -O3 -std=c++11

gcc does not optimize down to result 160 and does not remove the new/deletes

main:
	pushq	%rbx
	movl	$12, %edi
	call	operator new(unsigned long)
	movq	._41(%rip), %rdx
	movq	%rax, %rdi
	movq	%rdx, %rsi
	movq	%rdx, (%rax)
	movl	._41+8(%rip), %eax
	shrq	$32, %rsi
	leal	100(%rsi,%rdx), %ebx
	movl	%eax, 8(%rdi)
	addl	%eax, %ebx
	testq	%rdi, %rdi
	je	.L2
	call	operator delete(void*)
.L2:
	movl	%ebx, %eax
	popq	%rbx
	ret
._41:
	.long	10
	.long	20
	.long	30

clang does optimize down to result 160 but still not remove the new/deletes

main:                                   # @main
	pushq	%rax
	movl	$12, %edi
	callq	operator new(unsigned long)
	testq	%rax, %rax
	movabsq	$85899345930, %rcx      # imm = 0x140000000A
	movq	%rcx, (%rax)
	movl	$30, 8(%rax)
	je	.LBB0_2
	movq	%rax, %rdi
	callq	operator delete(void*)
.LBB0_2:                                # %_ZNSt6vectorIiSaIiEED2Ev.exit
	movl	$160, %eax
	popq	%rdx
	ret

so Bens "Sadly, removing the allocation is harder." seems to be still hard





--
View this message in context: http://clang-developers.42468.n3.nabble.com/missing-optimization-opportunity-for-const-std-vector-compared-to-std-array-tp4034587p4039704.html
Sent from the Clang Developers mailing list archive at Nabble.com.



More information about the cfe-dev mailing list