[Swan-dev] pluto: ikev2_ts.c: convert large const by-value parameters to by-ref

D. Hugh Redelmeier hugh at mimosa.com
Wed Jun 16 19:50:12 UTC 2021

| From: Andrew Cagney <andrew.cagney at gmail.com>

| I saw that but decided to ignore it.
| On Wed, 16 Jun 2021 at 12:14, D. Hugh Redelmeier <hugh at vault.libreswan.fi>
| wrote:

| >     Wishful thinking: a compiler ought to be able to do this
| > transformation.

| What makes you think the compiler can't eliminate this?  It is 2021 after
| all.
| The function's static so it doesn't even need LTO.

I assumed this.

After you questioned this assumption, I had to investigate.

Summary: no, it isn't 2021.

[build at redtiny libreswan]$ size ./OBJ.linux.x86_64/programs/pluto/ikev2_ts.o
   text	   data	    bss	    dec	    hex	filename
  21936	    664	      0	  22600	   5848	./OBJ.linux.x86_64/programs/pluto/ikev2_ts.o

[hugh at redeye libreswan]$ size ./OBJ.linux.x86_64/programs/pluto/ikev2_ts.o
   text	   data	    bss	    dec	    hex	filename
  21460	    664	      0	  22124	   566c	./OBJ.linux.x86_64/programs/pluto/ikev2_ts.o

The x86-64 assembly code isn't familiar to me, but there are tell-tale

The stack frame allocation goes from
	subq	$2440, %rsp
	subq  	$376, %rsp

The old assembly code has two "rep movsq" instructions that the new does not.

Here are the key parts of the prologs, with similar heads and tails stripped:

================ old
	leaq	1064(%rsp), %r14
	leaq	32(%rsp), %r12
	movq	%rsi, 8(%rsp)
	movl	%ecx, 16(%rsp)
	movq	%r14, %rdi
	movl	$129, %ecx
        .loc 1 1036 1 view .LVU636
	leaq	2496(%rsp), %rsi
	rep movsq
        .loc 1 1036 1 view .LVU637
	leaq	3528(%rsp), %rsi
	movl	$129, %ecx
	movq	%r12, %rdi
	rep movsq
        .loc 1 1037 2 view .LVU638
	movl	1068(%rsp), %ecx
        .loc 1 1036 1 view .LVU639

================ new
        movq 	%rsi, 8(%rsp)
        .loc 1 1037 2 view .LVU1162
      	movl	4(%rdx), %esi
        .loc 1 1037 2 view .LVU1163
        .loc 1 1036 1 view .LVU1164
	movl	%r9d, 16(%rsp)

More information about the Swan-dev mailing list