public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-8242] tree-optimization/105368 - avoid overflow in powi_cost
@ 2022-04-25  9:47 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-04-25  9:47 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f0e170f72f8bfaa2a64e1d09ebdfd48f917420f1

commit r12-8242-gf0e170f72f8bfaa2a64e1d09ebdfd48f917420f1
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Apr 25 10:55:21 2022 +0200

    tree-optimization/105368 - avoid overflow in powi_cost
    
    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.

Diff:
---
 gcc/tree-ssa-math-opts.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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));


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-25  9:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-25  9:47 [gcc r12-8242] tree-optimization/105368 - avoid overflow in powi_cost Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).