]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/105368 - avoid overflow in powi_cost
authorRichard Biener <rguenther@suse.de>
Mon, 25 Apr 2022 08:55:21 +0000 (10:55 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 25 Apr 2022 09:46:59 +0000 (11:46 +0200)
The following avoids undefined signed overflow when computing
the absolute of the exponent in powi_cost.

2022-04-25  Richard Biener  <rguenther@suse.de>

PR tree-optimization/105368
* tree-ssa-math-opts.cc (powi_cost): Use absu_hwi.

gcc/tree-ssa-math-opts.cc

index 102b7a2cc99f4057af349d1a3c96322ae42bab48..7555793948e1f5491866aa04e896db31db25fa78 100644 (file)
@@ -1462,7 +1462,7 @@ powi_cost (HOST_WIDE_INT n)
     return 0;
 
   /* Ignore the reciprocal when calculating the cost.  */
-  val = (n < 0) ? -n : n;
+  val = absu_hwi (n);
 
   /* Initialize the exponent cache.  */
   memset (cache, 0, POWI_TABLE_SIZE * sizeof (bool));