diff options
author | Jakub Jelinek <jakub@redhat.com> | 2018-12-06 11:45:47 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2018-12-06 11:45:47 +0100 |
commit | 98610dc5b630a8ee7f39ed48d45e58fb044dbec1 (patch) | |
tree | 31424dd67a7c75abf968575cec641c895751abdd /gcc/gimple-match-head.c | |
parent | a126d36172d336ee92f18b5c0fcf60a16690c2f0 (diff) | |
download | gcc-98610dc5b630a8ee7f39ed48d45e58fb044dbec1.zip gcc-98610dc5b630a8ee7f39ed48d45e58fb044dbec1.tar.gz gcc-98610dc5b630a8ee7f39ed48d45e58fb044dbec1.tar.bz2 |
re PR tree-optimization/85726 (div C1 to div C2 match.pd suboptimization)
PR tree-optimization/85726
* generic-match-head.c (optimize_successive_divisions_p): New function.
* gimple-match-head.c (optimize_successive_divisions_p): Likewise.
* match.pd: Don't combine successive divisions if they aren't exact
and optimize_successive_divisions_p is false.
* gcc.dg/tree-ssa/pr85726-1.c: New test.
* gcc.dg/tree-ssa/pr85726-2.c: New test.
* gcc.dg/tree-ssa/pr85726-3.c: New test.
* gcc.dg/tree-ssa/pr85726-4.c: New test.
From-SVN: r266848
Diffstat (limited to 'gcc/gimple-match-head.c')
-rw-r--r-- | gcc/gimple-match-head.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/gimple-match-head.c b/gcc/gimple-match-head.c index d6c60ab..374232b 100644 --- a/gcc/gimple-match-head.c +++ b/gcc/gimple-match-head.c @@ -1163,3 +1163,27 @@ optimize_pow_to_exp (tree arg0, tree arg1) return false; return true; } + +/* Return true if a division INNER_DIV / DIVISOR where INNER_DIV + is another division can be optimized. Don't optimize if INNER_DIV + is used in a TRUNC_MOD_EXPR with DIVISOR as second operand. */ + +static bool +optimize_successive_divisions_p (tree divisor, tree inner_div) +{ + if (!gimple_in_ssa_p (cfun)) + return false; + + imm_use_iterator imm_iter; + use_operand_p use_p; + FOR_EACH_IMM_USE_FAST (use_p, imm_iter, inner_div) + { + gimple *use_stmt = USE_STMT (use_p); + if (!is_gimple_assign (use_stmt) + || gimple_assign_rhs_code (use_stmt) != TRUNC_MOD_EXPR + || !operand_equal_p (gimple_assign_rhs2 (use_stmt), divisor, 0)) + continue; + return false; + } + return true; +} |