[PATCH] Expand SimplifyCFG to convert certain simple switches to selects

Marcello Maggioni hayarms at gmail.com
Fri Jun 20 08:39:57 PDT 2014


Whoops, I didn't notice that on X86 I had frame-pointers enabled by default (default without -fomit-frame-pointer) and that is the cause of those pushing and  popping.

After omitting frame pointers I get this output:

_foo3_without_def:
	shrl	%edi
	andl	$1, %edi
	leal	1(%rdi), %eax
	retq

with the one without optimization being:

_foo3_without_def:
	andl	$6, %edi
	leaq	l_switch.table1(%rip), %rax
	movl	(%rax,%rdi,4), %eax
	retq

Which is short in instruction count, thanks to X86 assembly being quite expressive, but accesses memory. 

In my micro benchmark this is the result of the optimized version:

marcellos-mbp:test_files Kariddi$ time ./test2

real	0m3.880s
user	0m3.878s
sys	0m0.002s

vs unoptimized:

marcellos-mbp:test_files Kariddi$ time ./test2_norm

real	0m4.675s
user	0m4.670s
sys	0m0.003s

for this switch:

http://reviews.llvm.org/D4219






More information about the llvm-commits mailing list