From 0cb5d7cdbab8e5f8359764ef5f62d93c2bc88552 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 22 Dec 2022 12:44:13 +0100 Subject: cse: Fix up CSE const_anchor handling [PR108193] The following testcase ICEs on aarch64, because insert_const_anchor inserts invalid CONST_INT into the CSE tables - 0x80000000 for SImode. The second hunk of the patch fixes that, the first one is to avoid triggering undefined behavior at compile time during compute_const_anchors computations - performing those additions and subtractions in HOST_WIDE_INT means it can overflow for certain constants. 2022-12-22 Jakub Jelinek PR rtl-optimization/108193 * cse.cc (compute_const_anchors): Change n type to unsigned HOST_WIDE_INT, adjust comparison against it to avoid warnings. Formatting fix. (insert_const_anchor): Use gen_int_mode instead of GEN_INT. * gfortran.dg/pr108193.f90: New test. --- gcc/cse.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'gcc/cse.cc') diff --git a/gcc/cse.cc b/gcc/cse.cc index b13afd4..b030f06 100644 --- a/gcc/cse.cc +++ b/gcc/cse.cc @@ -1169,14 +1169,14 @@ compute_const_anchors (rtx cst, HOST_WIDE_INT *lower_base, HOST_WIDE_INT *lower_offs, HOST_WIDE_INT *upper_base, HOST_WIDE_INT *upper_offs) { - HOST_WIDE_INT n = INTVAL (cst); + unsigned HOST_WIDE_INT n = UINTVAL (cst); *lower_base = n & ~(targetm.const_anchor - 1); - if (*lower_base == n) + if ((unsigned HOST_WIDE_INT) *lower_base == n) return false; - *upper_base = - (n + (targetm.const_anchor - 1)) & ~(targetm.const_anchor - 1); + *upper_base = ((n + (targetm.const_anchor - 1)) + & ~(targetm.const_anchor - 1)); *upper_offs = n - *upper_base; *lower_offs = n - *lower_base; return true; @@ -1193,7 +1193,7 @@ insert_const_anchor (HOST_WIDE_INT anchor, rtx reg, HOST_WIDE_INT offs, rtx anchor_exp; rtx exp; - anchor_exp = GEN_INT (anchor); + anchor_exp = gen_int_mode (anchor, mode); hash = HASH (anchor_exp, mode); elt = lookup (anchor_exp, hash, mode); if (!elt) -- cgit v1.1