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

            Bug ID: 98960
           Summary: Failure to optimize accumulate loop to mul
           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: ---

int f(uint8_t max_value) {
    int sum = 0;
    for (int i = 0; i < max_value; i++) {
        sum += i;
    }
    return sum;
}

This can be optimized to `return (uint64_t)max_value * (max_value - 1) >> 1;`.
This transformation is done by LLVM, but not by GCC.

Reply via email to