+2015-07-03 Richard Biener <rguenther@suse.de>
+
+ * fold-const.c (fold_binary_loc): Move (T)ptr & CST folding...
+ * match.pd: ... here.
+
2015-07-03 Gerald Pfeifer <gerald@pfeifer.com>
PR target/37072
fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
}
- /* If arg0 is derived from the address of an object or function, we may
- be able to fold this expression using the object or function's
- alignment. */
- if (POINTER_TYPE_P (TREE_TYPE (arg0)) && TREE_CODE (arg1) == INTEGER_CST)
- {
- unsigned int align;
- unsigned HOST_WIDE_INT bitpos;
-
- get_pointer_alignment_1 (arg0, &align, &bitpos);
-
- /* This works because modulus is a power of 2. If this weren't the
- case, we'd have to replace it by its greatest power-of-2
- divisor: modulus & -modulus. */
- if (wi::ltu_p (arg1, align / BITS_PER_UNIT))
- return wide_int_to_tree (type,
- wi::bit_and (arg1,
- bitpos / BITS_PER_UNIT));
- }
-
goto associate;
case RDIV_EXPR:
(if (ptr_difference_const (@0, @1, &diff))
{ build_int_cst_type (type, diff); }))))
+/* If arg0 is derived from the address of an object or function, we may
+ be able to fold this expression using the object or function's
+ alignment. */
+(simplify
+ (bit_and (convert? @0) INTEGER_CST@1)
+ (if (POINTER_TYPE_P (TREE_TYPE (@0))
+ && tree_nop_conversion_p (type, TREE_TYPE (@0)))
+ (with
+ {
+ unsigned int align;
+ unsigned HOST_WIDE_INT bitpos;
+ get_pointer_alignment_1 (@0, &align, &bitpos);
+ }
+ (if (wi::ltu_p (@1, align / BITS_PER_UNIT))
+ { wide_int_to_tree (type, wi::bit_and (@1, bitpos / BITS_PER_UNIT)); }))))
/* We can't reassociate at all for saturating types. */