From patchwork Thu Dec 22 10:23:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 62254 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E25F3850F07 for ; Thu, 22 Dec 2022 10:23:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E25F3850F07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671704623; bh=oIh8Na3Wbuw/6S1TobL1kynouO3UXTmShK1IXQU3OqA=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=O1MvWE0cStwFt6EmR7TQYmxhuwt9JzTxxAiTN517NLmsRFEw40xn2YpstveJIc6Rw lurBOooTm4ZodB3B77mkMUhh8t3gAtWGTkFtPW3zb6Zt+j8qC05/SRH8i8mD4f94/J EjvAQNKmBcJuMld9MrWQoge6x2Hf+ssnbXdPX8PQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 3F2A63857C45 for ; Thu, 22 Dec 2022 10:23:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F2A63857C45 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-41-0sWzSJOiNC-wh5wbHulNrg-1; Thu, 22 Dec 2022 05:23:10 -0500 X-MC-Unique: 0sWzSJOiNC-wh5wbHulNrg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5E2F2101A521; Thu, 22 Dec 2022 10:23:10 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 12093112132C; Thu, 22 Dec 2022 10:23:09 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2BMAN6Kb1189255 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 22 Dec 2022 11:23:07 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2BMAN5Em1189254; Thu, 22 Dec 2022 11:23:05 +0100 Date: Thu, 22 Dec 2022 11:23:05 +0100 To: Richard Biener , Jeff Law , Richard Sandiford Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] cse: Fix up CSE const_anchor handling [PR108193] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. Jakub --- 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); *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