diff options
author | naveenh <naveenh@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-11-12 05:34:54 +0000 |
---|---|---|
committer | naveenh <naveenh@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-11-12 05:34:54 +0000 |
commit | ee5e3723536a94612f9f2298d327fa587728db51 (patch) | |
tree | 6d95b42299d95761df6ad4dfed0acf92443db35e /gcc/match.pd | |
parent | dc77f97fa2cc52292b4a0d750702f72995ce37c8 (diff) | |
download | gcc-ee5e3723536a94612f9f2298d327fa587728db51.tar.gz |
2015-11-12 Naveen H.S <Naveen.Hurugalawadi@caviumnetworks.com>
* fold-const.c (fold_binary_loc) : Move Convert A/B/C to A/(B*C)
to match.pd.
Move Convert A/(B/C) to (A/B)*C to match.pd.
Move Convert C1/(X*C2) into (C1/C2)/X to match.pd.
Move Optimize (X & (-A)) / A where A is a power of 2, to
X >> log2(A) to match.pd.
* match.pd (rdiv (rdiv:s @0 @1) @2): New simplifier.
(rdiv @0 (rdiv:s @1 @2)): New simplifier.
(div (convert? (bit_and @0 INTEGER_CST@1)) INTEGER_CST@2):
New simplifier.
(rdiv REAL_CST@0 (mult @1 REAL_CST@2)): New simplifier.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@230204 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/match.pd')
-rw-r--r-- | gcc/match.pd | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index f6c5c07b681..d552bebdafe 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -247,6 +247,28 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (!HONOR_SNANS (type)) (negate @0))) +(if (flag_reciprocal_math) + /* Convert (A/B)/C to A/(B*C) */ + (simplify + (rdiv (rdiv:s @0 @1) @2) + (rdiv @0 (mult @1 @2))) + + /* Convert A/(B/C) to (A/B)*C */ + (simplify + (rdiv @0 (rdiv:s @1 @2)) + (mult (rdiv @0 @1) @2))) + +/* Optimize (X & (-A)) / A where A is a power of 2, to X >> log2(A) */ +(for div (trunc_div ceil_div floor_div round_div exact_div) + (simplify + (div (convert? (bit_and @0 INTEGER_CST@1)) INTEGER_CST@2) + (if (integer_pow2p (@2) + && tree_int_cst_sgn (@2) > 0 + && wi::add (@2, @1) == 0 + && tree_nop_conversion_p (type, TREE_TYPE (@0))) + (rshift (convert @0) { build_int_cst (integer_type_node, + wi::exact_log2 (@2)); })))) + /* If ARG1 is a constant, we can convert this to a multiply by the reciprocal. This does not have the same rounding properties, so only do this if -freciprocal-math. We can actually @@ -464,6 +486,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (tem) (rdiv { tem; } @1))))) +/* Convert C1/(X*C2) into (C1/C2)/X */ +(simplify + (rdiv REAL_CST@0 (mult @1 REAL_CST@2)) + (if (flag_reciprocal_math) + (with + { tree tem = const_binop (RDIV_EXPR, type, @0, @2); } + (if (tem) + (rdiv { tem; } @1))))) + /* Simplify ~X & X as zero. */ (simplify (bit_and:c (convert? @0) (convert? (bit_not @0))) |