+2016-06-30 Jakub Jelinek <jakub@redhat.com>
+
+ PR middle-end/71693
+ * fold-const.c (fold_binary_loc) <case RROTATE_EXPR>: Cast
+ TREE_OPERAND (arg0, 0) and TREE_OPERAND (arg0, 1) to type
+ first when permuting bitwise operation with rotate. Cast
+ TREE_OPERAND (arg0, 0) to type when cancelling two rotations.
+
2016-06-21 Georg-Johann Lay <avr@gjlay.de>
Backport from 2016-06-21 trunk r237639.
|| TREE_CODE (arg0) == BIT_IOR_EXPR
|| TREE_CODE (arg0) == BIT_XOR_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
- return fold_build2_loc (loc, TREE_CODE (arg0), type,
- fold_build2_loc (loc, code, type,
- TREE_OPERAND (arg0, 0), arg1),
- fold_build2_loc (loc, code, type,
- TREE_OPERAND (arg0, 1), arg1));
+ {
+ tree arg00 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
+ tree arg01 = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 1));
+ return fold_build2_loc (loc, TREE_CODE (arg0), type,
+ fold_build2_loc (loc, code, type,
+ arg00, arg1),
+ fold_build2_loc (loc, code, type,
+ arg01, arg1));
+ }
/* Two consecutive rotates adding up to the precision of the
type can be ignored. */
&& ((TREE_INT_CST_LOW (arg1)
+ TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)))
== prec))
- return TREE_OPERAND (arg0, 0);
+ return fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
/* Fold (X & C2) << C1 into (X << C1) & (C2 << C1)
(X & C2) >> C1 into (X >> C1) & (C2 >> C1)