]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/tree-chrec.c
Merge in trunk.
[thirdparty/gcc.git] / gcc / tree-chrec.c
index afc1a6a5f645d631f6ab0f268c3df82b3e85a8e2..91a14e41f53a8d2ca8cd1a7891cf78c3fffaf963 100644 (file)
@@ -479,7 +479,6 @@ chrec_fold_multiply (tree type,
 static tree
 tree_fold_binomial (tree type, tree n, unsigned int k)
 {
-  double_int num, denom, idx, di_res;
   bool overflow;
   unsigned int i;
   tree res;
@@ -491,20 +490,20 @@ tree_fold_binomial (tree type, tree n, unsigned int k)
     return fold_convert (type, n);
 
   /* Numerator = n.  */
-  num = TREE_INT_CST (n);
+  wide_int num = n;
 
   /* Check that k <= n.  */
-  if (num.ult (double_int::from_uhwi (k)))
+  if (wi::ltu_p (num, k))
     return NULL_TREE;
 
   /* Denominator = 2.  */
-  denom = double_int::from_uhwi (2);
+  wide_int denom = wi::two (TYPE_PRECISION (TREE_TYPE (n)));
 
   /* Index = Numerator-1.  */
-  idx = num - double_int_one;
+  wide_int idx = num - 1;
 
   /* Numerator = Numerator*Index = n*(n-1).  */
-  num = num.mul_with_sign (idx, false, &overflow);
+  num = wi::smul (num, idx, &overflow);
   if (overflow)
     return NULL_TREE;
 
@@ -514,17 +513,17 @@ tree_fold_binomial (tree type, tree n, unsigned int k)
       --idx;
 
       /* Numerator *= Index.  */
-      num = num.mul_with_sign (idx, false, &overflow);
+      num = wi::smul (num, idx, &overflow);
       if (overflow)
        return NULL_TREE;
 
       /* Denominator *= i.  */
-      denom *= double_int::from_uhwi (i);
+      denom *= i;
     }
 
   /* Result = Numerator / Denominator.  */
-  di_res = num.div (denom, true, EXACT_DIV_EXPR);
-  res = build_int_cst_wide (type, di_res.low, di_res.high);
+  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;
 }