+2015-10-29 Marc Glisse <marc.glisse@inria.fr>
+
+ * match.pd (X-(X/Y)*Y): Properly handle conversions and commutativity.
+
2015-10-29 Richard Sandiford <richard.sandiford@arm.com>
* tree-call-cdce.c (shrink_wrap_one_built_in_call): Remove
/* X - (X / Y) * Y is the same as X % Y. */
(simplify
- (minus (convert1? @0) (convert2? (mult (trunc_div @0 @1) @1)))
- (if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
- && TYPE_UNSIGNED (TREE_TYPE (@0)) == TYPE_UNSIGNED (type))
- (trunc_mod (convert @0) (convert @1))))
+ (minus (convert1? @2) (convert2? (mult:c (trunc_div @0 @1) @1)))
+ /* We cannot use matching captures here, since in the case of
+ constants we really want the type of @0, not @2. */
+ (if (operand_equal_p (@0, @2, 0)
+ && (INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type)))
+ (convert (trunc_mod @0 @1))))
/* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR,
i.e. "X % C" into "X & (C - 1)", if X and C are positive.