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

            Bug ID: 115555
           Summary: [Ranger] deduce 'a >= 0' from  'b << a'
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: aldyh at gcc dot gnu.org
  Target Milestone: ---

Stumbled over this when looking at PR 115551.

C has for the bitwise shift operators:

"If the value of the right operand is negative or is greater than or equal to
the
width of the promoted left operand, the behavior is undefined."

Thus, it seems as if the ranger should be able to deduce 'a >= 0' in the
following, such that both conditions can be optimized away:

int f (int a, float *b) {
   *b = a >= 0 ? 1.0 : 2.0;
   int mask1 = 1U << a;  // 'a' must be >= 0 → '*b=1.0' above and 'return -1'
below
   if (a >= 0)
     return -1;
   return mask1;
}

Reply via email to