From: Richard Biener Date: Mon, 25 Apr 2022 08:55:21 +0000 (+0200) Subject: tree-optimization/105368 - avoid overflow in powi_cost X-Git-Tag: releases/gcc-10.4.0~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ebe6ffee1aa2d819e4fbdf4130e054a33c274b38;p=thirdparty%2Fgcc.git 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 PR tree-optimization/105368 * tree-ssa-math-opts.c (powi_cost): Use absu_hwi. (cherry picked from commit f0e170f72f8bfaa2a64e1d09ebdfd48f917420f1) --- diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 4c89fddcfc57..fbaa3deffe39 100644 --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -1328,7 +1328,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));