diff options
author | Richard Biener <rguenther@suse.de> | 2022-04-29 08:45:48 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2022-04-29 11:10:24 +0200 |
commit | 44b09adb9bad99dd7e3017c5ecefed7f7c9a1590 (patch) | |
tree | 9f49abe44279c9265b38ccabaa433bb93fe96702 /gcc | |
parent | 9eb38e88ce8003c0b852144da3c265b6785ede3c (diff) | |
download | gcc-44b09adb9bad99dd7e3017c5ecefed7f7c9a1590.zip gcc-44b09adb9bad99dd7e3017c5ecefed7f7c9a1590.tar.gz gcc-44b09adb9bad99dd7e3017c5ecefed7f7c9a1590.tar.bz2 |
tree-optimization/105431 - another overflow in powi handling
This avoids undefined signed overflow when calling powi_as_mults_1.
2022-04-29 Richard Biener <rguenther@suse.de>
PR tree-optimization/105431
* tree-ssa-math-opts.cc (powi_as_mults_1): Make n unsigned.
(powi_as_mults): Use absu_hwi.
(gimple_expand_builtin_powi): Remove now pointless n != -n
check.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/tree-ssa-math-opts.cc | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc index b528b05..2085597 100644 --- a/gcc/tree-ssa-math-opts.cc +++ b/gcc/tree-ssa-math-opts.cc @@ -1495,7 +1495,7 @@ powi_cost (HOST_WIDE_INT n) static tree powi_as_mults_1 (gimple_stmt_iterator *gsi, location_t loc, tree type, - HOST_WIDE_INT n, tree *cache) + unsigned HOST_WIDE_INT n, tree *cache) { tree op0, op1, ssa_target; unsigned HOST_WIDE_INT digit; @@ -1548,7 +1548,7 @@ powi_as_mults (gimple_stmt_iterator *gsi, location_t loc, memset (cache, 0, sizeof (cache)); cache[1] = arg0; - result = powi_as_mults_1 (gsi, loc, type, (n < 0) ? -n : n, cache); + result = powi_as_mults_1 (gsi, loc, type, absu_hwi (n), cache); if (n >= 0) return result; @@ -1572,11 +1572,9 @@ static tree gimple_expand_builtin_powi (gimple_stmt_iterator *gsi, location_t loc, tree arg0, HOST_WIDE_INT n) { - /* Avoid largest negative number. */ - if (n != -n - && ((n >= -1 && n <= 2) - || (optimize_function_for_speed_p (cfun) - && powi_cost (n) <= POWI_MAX_MULTS))) + if ((n >= -1 && n <= 2) + || (optimize_function_for_speed_p (cfun) + && powi_cost (n) <= POWI_MAX_MULTS)) return powi_as_mults (gsi, loc, arg0, n); return NULL_TREE; |