On Wed, Mar 9, 2022 at 12:20 PM Xi Ruoyao via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Bootstrapped and tested on mips64el-linux-gnuabi64, and MIPS is the only > port with a non-zero targetm.const_anchor. Ok for trunk? > > -- >8 -- > > With a non-zero const_anchor, the behavior of this function relied on > signed overflow. > > gcc/ > > PR rtl-optimization/104843 > * cse.cc (compute_const_anchors): Cast to unsigned HOST_WIDE_INT > to perform overflow arithmetics safely. > --- > gcc/cse.cc | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/gcc/cse.cc b/gcc/cse.cc > index a18b599d324..7c39a009449 100644 > --- a/gcc/cse.cc > +++ b/gcc/cse.cc > @@ -1169,10 +1169,10 @@ 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 = INTVAL (cst);
UINTVAL (cst)? > > *lower_base = n & ~(targetm.const_anchor - 1); isn't it better to make targetm.const_anchor unsigned? The & and ~ are not subject to overflow rules. > - if (*lower_base == n) > + if (*lower_base == INTVAL (cst)) duplicating this here is definitely ugly. > return false; > > *upper_base = > -- > 2.35.1 > >