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

--- Comment #3 from Jin Haobo <a1343922569 at outlook dot com> ---
Thank you for your confirmation. I understand that the char/short cases are
treated differently due to integer promotion.
While I acknowledge that 8/16-bit unsigned integers undergo integer promotion
which changes the exact semantics of the operation (as shown in your example
with the char case), the mathematical result should still be equivalent for all
valid inputs. The expression `a > 0xFF / b` should yield the same boolean
result as checking if `a * b > 0xFF`, so a similar optimization strategy could
theoretically be applied.
However, even if there are concerns about optimizing the 8/16-bit cases due to
promotion semantics, the 32/64-bit cases should clearly be optimized. In these
cases:
1. The explicit zero check (`if (b == 0) return false;`) already guarantees
that division-by-zero cannot occur.
2. There is no integer promotion affecting the semantics.
3. The compiler already recognizes the pattern as a multiplication overflow
check for these sizes (as evidenced by the `mul` instruction followed by
`seto`).
The redundant zero check in the assembly output for 32/64-bit cases is
unnecessary and impacts performance, especially in performance-critical code
paths. I hope this specific optimization for int and long long types can be
implemented even if the smaller types require further analysis.

Thank you for your understanding!

Reply via email to