https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99082

            Bug ID: 99082
           Summary: manual bit-field creation followed by manual
                    extraction does not always produce good code
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
#include <stdint.h>

static inline uint16_t foo(uint32_t *r8b8g8x)
{
    const uint8_t r8 = *r8b8g8x;
    const uint8_t b8 = *r8b8g8x >> 8;
    const uint8_t g8 = *r8b8g8x >> 16;
    return
        (uint16_t)r8 >> 3 |
        ((uint16_t)(g8 >> 2) << 5) |
        ((uint16_t)(b8 >> 3) << 11);
}

uint16_t bar(
    uint8_t *r8,
    uint8_t *g8,
    uint8_t *b8)
{
   uint32_t t = (uint32_t)*r8 |
        ((uint32_t)*b8 << 8) |
        ((uint32_t)*g8 << 16);
    return foo(&t);
}
uint16_t bar1(
    uint8_t *r8,
    uint8_t *g8,
    uint8_t *b8)
{
    return
        (uint16_t)*r8 >> 3 |
        ((uint16_t)(*g8 >> 2) << 5) |
        ((uint16_t)(*b8 >> 3) << 11);
}

---- CUT ----
bar and bar1 should produce the same code but currently does not.

Reply via email to