Home > Enterprise >  Is this a missed optimization in GCC, loading an 16-bit integer value from .rodata instead of an imm
Is this a missed optimization in GCC, loading an 16-bit integer value from .rodata instead of an imm

Time:01-18

Looking for this code:

#include <stdint.h>

extern struct __attribute__((packed))
{
    uint8_t size;
    uint8_t pad;
    uint16_t sec_num;
    uint16_t offset;
    uint16_t segment;
    uint64_t sec_id;
} ldap;

//uint16_t x __attribute__((aligned(4096)));

void kkk()
{
    ldap.size = 16;
    ldap.pad = 0;
    //x = 16;
}

After compiling it with -O2, -O3 or -Ofast, it will be :

    .globl  kkk
    .type   kkk, @function
kkk:
    movzwl  .LC0(%rip),            
  • Related