unsigned short int
f5 (unsigned short int x, unsigned int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
}
unsigned short int
f6 (unsigned short int x, unsigned long int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
}
unsigned char
f7 (unsigned char x, unsigned int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ - 1)));
}
unsigned char
f8 (unsigned char x, unsigned long int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ - 1)));
}
unsigned short int
f13 (unsigned short int x, unsigned int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
}
unsigned short int
f14 (unsigned short int x, unsigned long int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
}
unsigned char
f15 (unsigned char x, unsigned int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
}
unsigned char
f16 (unsigned char x, unsigned long int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
}
unsigned short int
f37 (unsigned short int x, unsigned int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
}
unsigned short int
f38 (unsigned short int x, unsigned long int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
}
unsigned char
f39 (unsigned char x, unsigned int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ - 1)));
}
unsigned char
f40 (unsigned char x, unsigned long int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ - 1)));
}
unsigned short int
f45 (unsigned short int x, unsigned int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
}
unsigned short int
f46 (unsigned short int x, unsigned long int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
}
unsigned char
f47 (unsigned char x, unsigned int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
}
unsigned char
f48 (unsigned char x, unsigned long int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
}
--- /dev/null
+/* Check rotate pattern detection. */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-ipa-icf -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-not "r\[<>]\[<>]" "optimized" } } */
+
+unsigned short int
+f5 (unsigned short int x, unsigned int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
+}
+
+unsigned short int
+f6 (unsigned short int x, unsigned long int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
+}
+
+unsigned char
+f7 (unsigned char x, unsigned int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ - 1)));
+}
+
+unsigned char
+f8 (unsigned char x, unsigned long int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ - 1)));
+}
+
+unsigned short int
+f13 (unsigned short int x, unsigned int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
+}
+
+unsigned short int
+f14 (unsigned short int x, unsigned long int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
+}
+
+unsigned char
+f15 (unsigned char x, unsigned int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
+}
+
+unsigned char
+f16 (unsigned char x, unsigned long int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
+}
+
+unsigned short int
+f37 (unsigned short int x, unsigned int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
+}
+
+unsigned short int
+f38 (unsigned short int x, unsigned long int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
+}
+
+unsigned char
+f39 (unsigned char x, unsigned int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ - 1)));
+}
+
+unsigned char
+f40 (unsigned char x, unsigned long int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ - 1)));
+}
+
+unsigned short int
+f45 (unsigned short int x, unsigned int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
+}
+
+unsigned short int
+f46 (unsigned short int x, unsigned long int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
+}
+
+unsigned char
+f47 (unsigned char x, unsigned int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
+}
+
+unsigned char
+f48 (unsigned char x, unsigned long int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
+}
unsigned short int
f5 (unsigned short int x, int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
}
unsigned short int
f6 (unsigned short int x, long int y)
{
+ if (y >= 0UL + __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
}
unsigned char
f7 (unsigned char x, int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ - 1)));
}
unsigned char
f8 (unsigned char x, long int y)
{
+ if (y >= 0UL + __CHAR_BIT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ - 1)));
}
unsigned short int
f13 (unsigned short int x, int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
}
unsigned short int
f14 (unsigned short int x, long int y)
{
+ if (y >= 0UL + __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
}
unsigned char
f15 (unsigned char x, int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
}
unsigned char
f16 (unsigned char x, long int y)
{
+ if (y >= 0UL + __CHAR_BIT__)
+ __builtin_unreachable ();
return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
}
unsigned short int
f37 (unsigned short int x, int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
}
unsigned short int
f38 (unsigned short int x, long int y)
{
+ if (y >= 0UL + __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
}
unsigned char
f39 (unsigned char x, int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ - 1)));
}
unsigned char
f40 (unsigned char x, long int y)
{
+ if (y >= 0UL + __CHAR_BIT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ - 1)));
}
unsigned short int
f45 (unsigned short int x, int y)
{
+ if (y >= __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
}
unsigned short int
f46 (unsigned short int x, long int y)
{
+ if (y >= 0UL + __CHAR_BIT__ * __SIZEOF_SHORT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
}
unsigned char
f47 (unsigned char x, int y)
{
+ if (y >= __CHAR_BIT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
}
unsigned char
f48 (unsigned char x, long int y)
{
+ if (y >= 0UL + __CHAR_BIT__)
+ __builtin_unreachable ();
return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
}
--- /dev/null
+/* Check rotate pattern detection. */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-ipa-icf -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-not "r\[<>]\[<>]" "optimized" } } */
+
+unsigned short int
+f5 (unsigned short int x, int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
+}
+
+unsigned short int
+f6 (unsigned short int x, long int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
+}
+
+unsigned char
+f7 (unsigned char x, int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ - 1)));
+}
+
+unsigned char
+f8 (unsigned char x, long int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ - 1)));
+}
+
+unsigned short int
+f13 (unsigned short int x, int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
+}
+
+unsigned short int
+f14 (unsigned short int x, long int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
+}
+
+unsigned char
+f15 (unsigned char x, int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
+}
+
+unsigned char
+f16 (unsigned char x, long int y)
+{
+ return (x << y) | (x >> ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
+}
+
+unsigned short int
+f37 (unsigned short int x, int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
+}
+
+unsigned short int
+f38 (unsigned short int x, long int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * __SIZEOF_SHORT__ - 1)));
+}
+
+unsigned char
+f39 (unsigned char x, int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ - 1)));
+}
+
+unsigned char
+f40 (unsigned char x, long int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ - 1)));
+}
+
+unsigned short int
+f45 (unsigned short int x, int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
+}
+
+unsigned short int
+f46 (unsigned short int x, long int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned short) - 1)));
+}
+
+unsigned char
+f47 (unsigned char x, int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
+}
+
+unsigned char
+f48 (unsigned char x, long int y)
+{
+ return (x >> y) | (x << ((-y) & (__CHAR_BIT__ * sizeof (unsigned char) - 1)));
+}
--- /dev/null
+/* PR tree-optimization/106523 */
+
+__attribute__((noipa)) unsigned char
+f7 (unsigned char x, unsigned int y)
+{
+ unsigned int t = x;
+ return (t << y) | (t >> ((-y) & 7));
+}
+
+int
+main ()
+{
+ if (__CHAR_BIT__ != 8 || __SIZEOF_INT__ != 4)
+ return 0;
+
+ volatile unsigned char x = 152;
+ volatile unsigned int y = 19;
+ if (f7 (x, y) != 4)
+ __builtin_abort ();
+
+ return 0;
+}
((T) ((T2) X << Y)) | ((T) ((T2) X >> ((-Y) & (B - 1))))
((T) ((T2) X << (int) Y)) | ((T) ((T2) X >> (int) ((-Y) & (B - 1))))
- transform these into:
+ transform these into (last 2 only if ranger can prove Y < B):
X r<< Y
Or for:
int i;
bool swapped_p = false;
gimple *g;
+ gimple *def_arg_stmt[2] = { NULL, NULL };
+ int wider_prec = 0;
arg[0] = gimple_assign_rhs1 (stmt);
arg[1] = gimple_assign_rhs2 (stmt);
return false;
for (i = 0; i < 2; i++)
- defcodefor_name (arg[i], &def_code[i], &def_arg1[i], &def_arg2[i]);
+ {
+ defcodefor_name (arg[i], &def_code[i], &def_arg1[i], &def_arg2[i]);
+ if (TREE_CODE (arg[i]) == SSA_NAME)
+ def_arg_stmt[i] = SSA_NAME_DEF_STMT (arg[i]);
+ }
/* Look through narrowing (or same precision) conversions. */
if (CONVERT_EXPR_CODE_P (def_code[0])
&& has_single_use (arg[0])
&& has_single_use (arg[1]))
{
+ wider_prec = TYPE_PRECISION (TREE_TYPE (def_arg1[0]));
for (i = 0; i < 2; i++)
{
arg[i] = def_arg1[i];
defcodefor_name (arg[i], &def_code[i], &def_arg1[i], &def_arg2[i]);
+ if (TREE_CODE (arg[i]) == SSA_NAME)
+ def_arg_stmt[i] = SSA_NAME_DEF_STMT (arg[i]);
}
}
else
{
arg[i] = def_arg1[i];
defcodefor_name (arg[i], &def_code[i], &def_arg1[i], &def_arg2[i]);
+ if (TREE_CODE (arg[i]) == SSA_NAME)
+ def_arg_stmt[i] = SSA_NAME_DEF_STMT (arg[i]);
}
}
{
tree cdef_arg1[2], cdef_arg2[2], def_arg2_alt[2];
enum tree_code cdef_code[2];
+ gimple *def_arg_alt_stmt[2] = { NULL, NULL };
+ bool check_range = false;
+ gimple *check_range_stmt = NULL;
/* Look through conversion of the shift count argument.
The C/C++ FE cast any shift count argument to integer_type_node.
The only problem might be if the shift count type maximum value
&& type_has_mode_precision_p (TREE_TYPE (cdef_arg1[i])))
{
def_arg2_alt[i] = cdef_arg1[i];
+ if (TREE_CODE (def_arg2[i]) == SSA_NAME)
+ def_arg_alt_stmt[i] = SSA_NAME_DEF_STMT (def_arg2[i]);
defcodefor_name (def_arg2_alt[i], &cdef_code[i],
&cdef_arg1[i], &cdef_arg2[i]);
}
+ else
+ def_arg_alt_stmt[i] = def_arg_stmt[i];
}
for (i = 0; i < 2; i++)
/* Check for one shift count being Y and the other B - Y,
if (CONVERT_EXPR_CODE_P (code)
&& INTEGRAL_TYPE_P (TREE_TYPE (tem))
&& TYPE_PRECISION (TREE_TYPE (tem))
- > floor_log2 (TYPE_PRECISION (rtype))
+ > floor_log2 (TYPE_PRECISION (rtype))
&& type_has_mode_precision_p (TREE_TYPE (tem))
&& (tem == def_arg2[1 - i]
|| tem == def_arg2_alt[1 - i]))
if (CONVERT_EXPR_CODE_P (code)
&& INTEGRAL_TYPE_P (TREE_TYPE (tem))
&& TYPE_PRECISION (TREE_TYPE (tem))
- > floor_log2 (TYPE_PRECISION (rtype))
+ > floor_log2 (TYPE_PRECISION (rtype))
&& type_has_mode_precision_p (TREE_TYPE (tem)))
defcodefor_name (tem, &code, &tem, NULL);
if (tem == def_arg2[1 - i] || tem == def_arg2_alt[1 - i])
{
rotcnt = tem;
+ check_range = true;
+ if (tem == def_arg2[1 - i])
+ check_range_stmt = def_arg_stmt[1 - i];
+ else
+ check_range_stmt = def_arg_alt_stmt[1 - i];
break;
}
tree tem2;
|| tem2 == def_arg2_alt[1 - i])
{
rotcnt = tem2;
+ check_range = true;
+ if (tem2 == def_arg2[1 - i])
+ check_range_stmt = def_arg_stmt[1 - i];
+ else
+ check_range_stmt = def_arg_alt_stmt[1 - i];
break;
}
}
}
}
}
+ if (check_range && wider_prec > TYPE_PRECISION (rtype))
+ {
+ if (TREE_CODE (rotcnt) != SSA_NAME)
+ return false;
+ int_range_max r;
+ if (!get_global_range_query ()->range_of_expr (r, rotcnt,
+ check_range_stmt))
+ return false;
+ int prec = TYPE_PRECISION (TREE_TYPE (rotcnt));
+ signop sign = TYPE_SIGN (TREE_TYPE (rotcnt));
+ wide_int min = wide_int::from (TYPE_PRECISION (rtype), prec, sign);
+ wide_int max = wide_int::from (wider_prec - 1, prec, sign);
+ int_range<2> r2 (TREE_TYPE (rotcnt), min, max);
+ r.intersect (r2);
+ if (!r.undefined_p ())
+ return false;
+ }
if (rotcnt == NULL_TREE)
return false;
swapped_p = i != 1;