tree-optimization/105368 - avoid overflow in powi_cost

Message ID 20220425094653.12F1613AE1@imap2.suse-dmz.suse.de
State Committed
Commit f0e170f72f8bfaa2a64e1d09ebdfd48f917420f1
Headers
Series tree-optimization/105368 - avoid overflow in powi_cost |

Commit Message

Richard Biener April 25, 2022, 9:46 a.m. UTC
  The following avoids undefined signed overflow when computing
the absolute of the exponent in powi_cost.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Patch

diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
index 102b7a2cc99..7555793948e 100644
--- a/gcc/tree-ssa-math-opts.cc
+++ b/gcc/tree-ssa-math-opts.cc
@@ -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));