https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120966
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|-Waggressive-loop-optimizat |++/-- for short still uses |ions warns for int but not |unsigned types even if |for short overflow |sizeof(int) == | |sizeof(short) Status|UNCONFIRMED |NEW Keywords| |diagnostic, | |missed-optimization Ever confirmed|0 |1 Last reconfirmed| |2025-07-05 Target| |sizeof(int)==sizeof(short) --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- The issue is the C/C++ shared gimplifier does: ``` case PREINCREMENT_EXPR: case PREDECREMENT_EXPR: case POSTINCREMENT_EXPR: case POSTDECREMENT_EXPR: { tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 0)); if (INTEGRAL_TYPE_P (type) && c_promoting_integer_type_p (type)) { if (!TYPE_OVERFLOW_WRAPS (type)) type = unsigned_type_for (type); return gimplify_self_mod_expr (expr_p, pre_p, post_p, 1, type); } break; } ``` c_promoting_integer_type_p returns true even if sizeof(type) == sizeof(int). Most likely this should have `(TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))` added to it. This is a missed optimization in some cases since it is signed integer overflow is undefined and this just forces `short_var++` to being defined which is ok.