summaryrefslogtreecommitdiff
path: root/gcc/cfgexpand.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-09-12 20:28:20 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2018-09-12 20:28:20 +0200
commitc0cbe5260fab673f7cd755df2226422b88b28837 (patch)
tree80f2a40dc45418305b5aabf0aed406735df224de /gcc/cfgexpand.c
parent8e36332cf65b4ec5a1ea6b4b3a6ae8cb6ed9f455 (diff)
re PR middle-end/82853 (Optimize x % 3 == 0 without modulo)
PR middle-end/82853 * expr.h (maybe_optimize_mod_cmp): Declare. * expr.c (mod_inv): New function. (maybe_optimize_mod_cmp): New function. (do_store_flag): Use it. * cfgexpand.c (expand_gimple_cond): Likewise. * gcc.target/i386/pr82853-1.c: New test. * gcc.target/i386/pr82853-2.c: New test. From-SVN: r264248
Diffstat (limited to 'gcc/cfgexpand.c')
-rw-r--r--gcc/cfgexpand.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 2d3111da25d..697b238669f 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -2477,6 +2477,13 @@ expand_gimple_cond (basic_block bb, gcond *stmt)
}
}
+ /* Optimize (x % C1) == C2 or (x % C1) != C2 if it is beneficial
+ into (x - C2) * C3 < C4. */
+ if ((code == EQ_EXPR || code == NE_EXPR)
+ && TREE_CODE (op0) == SSA_NAME
+ && TREE_CODE (op1) == INTEGER_CST)
+ code = maybe_optimize_mod_cmp (code, &op0, &op1);
+
last2 = last = get_last_insn ();
extract_true_false_edges_from_block (bb, &true_edge, &false_edge);