https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101858
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |12.0 Component|c |middle-end Status|NEW |ASSIGNED --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- #0 build2 (code=RSHIFT_EXPR, tt=<pointer_type 0x7ffff65649d8>, arg0=<convert_expr 0x7ffff6686260>, arg1=<parm_decl 0x7ffff669d000 a>) at /home/rguenther/src/gcc2/gcc/tree.c:4970 #1 0x0000000000eb1bab in fold_binary_loc (loc=2147483651, code=LT_EXPR, type=<integer_type 0x7ffff655c5e8 int>, op0=<convert_expr 0x7ffff6686260>, op1=<convert_expr 0x7ffff6686220>) at /home/rguenther/src/gcc2/gcc/fold-const.c:12510 /* Similarly for X < (cast) (1 << Y). But cast can't be narrowing, otherwise Y might be >= # of bits in X's type and thus e.g. (unsigned char) (1 << Y) for Y 15 might be 0. If the cast is widening, then 1 << Y should have unsigned type, otherwise if Y is number of bits in the signed shift type minus 1, we can't optimize this. E.g. (unsigned long long) (1 << Y) for Y 31 might be 0xffffffff80000000. */ if ((code == LT_EXPR || code == GE_EXPR) && TYPE_UNSIGNED (TREE_TYPE (arg0)) && CONVERT_EXPR_P (arg1) && TREE_CODE (TREE_OPERAND (arg1, 0)) == LSHIFT_EXPR && (element_precision (TREE_TYPE (arg1)) >= element_precision (TREE_TYPE (TREE_OPERAND (arg1, 0)))) && (TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (arg1, 0))) || (element_precision (TREE_TYPE (arg1)) == element_precision (TREE_TYPE (TREE_OPERAND (arg1, 0))))) && integer_onep (TREE_OPERAND (TREE_OPERAND (arg1, 0), 0))) { tem = build2 (RSHIFT_EXPR, TREE_TYPE (arg0), arg0, TREE_OPERAND (TREE_OPERAND (arg1, 0), 1)); return build2_loc (loc, code == LT_EXPR ? EQ_EXPR : NE_EXPR, type, fold_convert_loc (loc, TREE_TYPE (arg0), tem), build_zero_cst (TREE_TYPE (arg0))); } Mine.