From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id D8BEB3857B8E for ; Thu, 22 Dec 2022 11:29:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D8BEB3857B8E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id B9B7E4D69F; Thu, 22 Dec 2022 11:29:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1671708547; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BX8E7jVdEwjNEOzvJOWmzAQLjTR9Sa/hoM7KFRh0YL0=; b=B842WB2eO8gAmEOxn15PPcTtyLuFSttTsaMJtnzc0awTWIe3x6KNyBoDf3+3/R0qx5T/aK ipf/mk7i7GpN30uQV+jspjedDzsNeJ6MUqnfHiMXLvj5MTVEAnkPGda1OqG1ARwqCeQbes Uy9sILOqXZh6VuJMzCMH83HIbYvN3B8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1671708547; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BX8E7jVdEwjNEOzvJOWmzAQLjTR9Sa/hoM7KFRh0YL0=; b=6wyLvtZNr80CE1JE0kZintjul0NXH3jZsJ2ldPaCTRrgzYsrrS9RSzgUQp6ryqIoCsj1se WXnPfO95V4fTcvCA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id ACDC82C141; Thu, 22 Dec 2022 11:29:07 +0000 (UTC) Date: Thu, 22 Dec 2022 11:29:07 +0000 (UTC) From: Richard Biener To: Jakub Jelinek cc: Jeff Law , Richard Sandiford , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] cse: Fix up CSE const_anchor handling [PR108193] In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 22 Dec 2022, Jakub Jelinek wrote: > Hi! > > 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. > > Bootstrapped/regtested on aarch64-linux (which does have nonzero > target.const_anchor) and x86_64-linux and i686-linux (which have it > zero). Ok for trunk? > > 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.jj 2022-06-28 13:03:30.699692752 +0200 > +++ gcc/cse.cc 2022-12-21 12:58:24.277945065 +0100 > @@ -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 = INTVAL (cst); UINTVAL? Otherwise OK. Thanks, Richard. > > *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 ancho > 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) > --- gcc/testsuite/gfortran.dg/pr108193.f90.jj 2022-12-21 13:02:21.925513332 +0100 > +++ gcc/testsuite/gfortran.dg/pr108193.f90 2022-12-21 13:01:38.595139040 +0100 > @@ -0,0 +1,24 @@ > +! PR rtl-optimization/108193 > +! { dg-do compile { target pthread } } > +! { dg-options "-O2 -fsplit-loops -ftree-parallelize-loops=2 -fno-tree-dominator-opts" } > + > +subroutine foo (n, r) > + implicit none > + integer :: i, j, n > + real :: s, r(*) > + > + s = 0.0 > + > + do j = 1, 2 > + do i = j, n > + s = r(i) > + end do > + end do > + > + do i = 1, n > + do j = i, n > + s = s + 1 > + end do > + r(i) = s > + end do > +end subroutine foo > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)