why is this not optimized? added by Bunny351 on Thu Nov 30 11:17:17 2017


typedef unsigned char ___u8;

struct HO_port {
        ___u8 * data;
};

void foo(struct HO_port *___out) {
   ___u8 *ptr = ___out->data;
   ptr[ 11 ] = 1;
   ptr[ 12 ] = 1;
   ptr[ 13 ] = 2;
}

void bar(struct HO_port *___out) {
   ___out->data[ 11 ] = 1;
   ___out->data[ 12 ] = 1;
   ___out->data[ 13 ] = 2;
}


gcc -Os x.c -c -o x.o -fstrict-aliasing
objdump -D x.o



0000000000000000 <foo>:
   0:	48 8b 07             	mov    (%rdi),%rax
   3:	c6 40 0b 01          	movb   $0x1,0xb(%rax)
   7:	c6 40 0c 01          	movb   $0x1,0xc(%rax)
   b:	c6 40 0d 02          	movb   $0x2,0xd(%rax)
   f:	c3                   	retq   

0000000000000010 <bar>:
  10:	48 8b 07             	mov    (%rdi),%rax
  13:	c6 40 0b 01          	movb   $0x1,0xb(%rax)
  17:	48 8b 07             	mov    (%rdi),%rax
  1a:	c6 40 0c 01          	movb   $0x1,0xc(%rax)
  1e:	48 8b 07             	mov    (%rdi),%rax
  21:	c6 40 0d 02          	movb   $0x2,0xd(%rax)
  25:	c3                   	retq