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

            Bug ID: 127087
           Summary: [Missed optimization] failed to optimize (x * y) % x
                    => 0 for int8_t
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: apowenq at gmail dot com
  Target Milestone: ---

cat cprog.c
#include <stdint.h>
int8_t src(int8_t v0_i8, int8_t v2_i8) {
  if (!((-3 <= v0_i8) && (v0_i8 <= 3))) __builtin_unreachable();
  if (!((1 <= v2_i8) && (v2_i8 <= 42))) __builtin_unreachable();
  int8_t i0_i8 = v0_i8 * v2_i8;
  int8_t i1_i8 = i0_i8 % v2_i8;
  return i1_i8;
}

Failed to optimize (x * y) % x => 0 for int8_t. Works for int.
Reproducer: https://godbolt.org/z/Gn8TWK66q

Reply via email to