summaryrefslogtreecommitdiff
path: root/gcc/match.pd
diff options
context:
space:
mode:
authorglisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-29 15:39:09 +0000
committerglisse <glisse@138bc75d-0d04-0410-961f-82ee72b054a4>2015-10-29 15:39:09 +0000
commitf801d40f14e7795140bacad07ee40462d5973c65 (patch)
tree32b708b45bfab7f43eefe48927f0bf1bd5176759 /gcc/match.pd
parent4cba6f608e709786797b5f24b44c0a42291f91a4 (diff)
downloadgcc-f801d40f14e7795140bacad07ee40462d5973c65.tar.gz
Fix X - (X / Y) * Y in match.pd.
2015-10-29 Marc Glisse <marc.glisse@inria.fr> * match.pd (X-(X/Y)*Y): Properly handle conversions and commutativity. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229534 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/match.pd')
-rw-r--r--gcc/match.pd10
1 files changed, 6 insertions, 4 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index 1d6dde19f47..f6c5c07b681 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -318,10 +318,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* 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.