From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 3F7CC395B416; Fri, 27 May 2022 13:15:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F7CC395B416 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10764] tree-optimization/105368 - avoid overflow in powi_cost X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 6007449a1c3bd116e431fe53d4dfe2d1c67c1076 X-Git-Newrev: ebe6ffee1aa2d819e4fbdf4130e054a33c274b38 Message-Id: <20220527131517.3F7CC395B416@sourceware.org> Date: Fri, 27 May 2022 13:15:17 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 May 2022 13:15:17 -0000 https://gcc.gnu.org/g:ebe6ffee1aa2d819e4fbdf4130e054a33c274b38 commit r10-10764-gebe6ffee1aa2d819e4fbdf4130e054a33c274b38 Author: Richard Biener 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 PR tree-optimization/105368 * tree-ssa-math-opts.c (powi_cost): Use absu_hwi. (cherry picked from commit f0e170f72f8bfaa2a64e1d09ebdfd48f917420f1) Diff: --- gcc/tree-ssa-math-opts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c index 4c89fddcfc5..fbaa3deffe3 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));