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

            Bug ID: 96542
           Summary: Failure to optimize simple code to a constant when
                    storing part of the operation in a variable
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

uint8_t f(uint32_t x)
{
    bool tmp = x;
    return (0xFF >> tmp) * 2;
}

This can be optimized to `return -2;`. This transformation is done by LLVM, but
not by GCC. Strangely, this only seems to happen if `(bool)x` is stored in an
intermediate variable, otherwise the transformation is done by GCC.

Reply via email to