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

            Bug ID: 112884
           Summary: Missing optimization: fold a%2==0 ? a/2*2 : 0 to
                    a%2==0 ? a : 0
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xxs_chy at outlook dot com
  Target Milestone: ---

Godbolt example: https://godbolt.org/z/Ec1ax79r8

For the select arm "a / 2 * 2" in:

unsigned src(unsigned a) {
    return a % 2 == 0 ? (a / 2 * 2) : 0;
}

it's equivalent to "a", so the program could be folded to:

unsigned tgt(unsigned a) {
    return a % 2 == 0 ? a : 0;
}

Both GCC and LLVM missed such optimization in select arms.

Reply via email to