diff options
author | burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-09-20 21:49:12 +0000 |
---|---|---|
committer | burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-09-20 21:49:12 +0000 |
commit | c9c81ef3c667aaa14c498a5449ec6d134b4b66ff (patch) | |
tree | 0ac440db6513ee01deb5e5dc6142769d1e5b7b2d /gcc/tree-chrec.c | |
parent | 12cdcb9d74f55c165366ca1b1eeec013a0ce72ef (diff) | |
parent | 891196d7325e4c55d92d5ac5cfe7161c4f36c0ce (diff) | |
download | gcc-fortran-dev.tar.gz |
Merge from trunk (r239915 to r240230)fortran-dev
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/fortran-dev@240290 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-chrec.c')
-rw-r--r-- | gcc/tree-chrec.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/gcc/tree-chrec.c b/gcc/tree-chrec.c index 79f07b029d1..e7e47b1bc52 100644 --- a/gcc/tree-chrec.c +++ b/gcc/tree-chrec.c @@ -490,7 +490,6 @@ tree_fold_binomial (tree type, tree n, unsigned int k) { bool overflow; unsigned int i; - tree res; /* Handle the most frequent cases. */ if (k == 0) @@ -498,18 +497,20 @@ tree_fold_binomial (tree type, tree n, unsigned int k) if (k == 1) return fold_convert (type, n); + widest_int num = wi::to_widest (n); + /* Check that k <= n. */ - if (wi::ltu_p (n, k)) + if (wi::ltu_p (num, k)) return NULL_TREE; /* Denominator = 2. */ - wide_int denom = wi::two (TYPE_PRECISION (TREE_TYPE (n))); + widest_int denom = 2; /* Index = Numerator-1. */ - wide_int idx = wi::sub (n, 1); + widest_int idx = num - 1; /* Numerator = Numerator*Index = n*(n-1). */ - wide_int num = wi::smul (n, idx, &overflow); + num = wi::smul (num, idx, &overflow); if (overflow) return NULL_TREE; @@ -528,9 +529,10 @@ tree_fold_binomial (tree type, tree n, unsigned int k) } /* Result = Numerator / Denominator. */ - wide_int di_res = wi::udiv_trunc (num, denom); - res = wide_int_to_tree (type, di_res); - return int_fits_type_p (res, type) ? res : NULL_TREE; + num = wi::udiv_trunc (num, denom); + if (! wi::fits_to_tree_p (num, type)) + return NULL_TREE; + return wide_int_to_tree (type, num); } /* Helper function. Use the Newton's interpolating formula for |