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: 35667 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp244441wrn; Thu, 22 Dec 2022 02:24:05 -0800 (PST) X-Google-Smtp-Source: AMrXdXu3SY9r0iWE4uhpk1/vRZ2CGogHw/tiOMCye7Y9OACdQ9Pb9uCAKkGzl/lmPWtSKZ/273/4 X-Received: by 2002:a05:6402:241b:b0:461:2288:6808 with SMTP id t27-20020a056402241b00b0046122886808mr4774394eda.21.1671704645327; Thu, 22 Dec 2022 02:24:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671704645; cv=none; d=google.com; s=arc-20160816; b=GZ17HlcA9Ck7o6L9JriD0TQVGJkdRBdtb1+u0HJJy4LGowWRxCsGu5e5wk7kyth/Ii EGXJACskS5eCgta8NDoR8NMvadkYPF3ysBMjWSmn1FpbXevAUlRvKiWJc/21bfBlzH4c nI5/JgwHzkRqVG3XdWBJuOYERt+ARtiW9N8ohVVXQKVBj8Be4Eh8/IxDK5dCRw4c5tbV mGyhVkNPZWClMBNJY6JML4ijo1wTHsOmJ3SsmyEHzPatfilv+62i0qhOeY4GzlMQ+EZf 2MIBD3kyApwECPDAoh2SRAk9FdALUHDm/O/Md+F0+7X12cApctAu4JdPmmrv2wu2cmZk PudA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oIh8Na3Wbuw/6S1TobL1kynouO3UXTmShK1IXQU3OqA=; b=D2gfOdS+42EQgTC7IXPwKItsTVCvrbDrSRaWDiNh4d5QBtxfVttxDekrRdtfvG6xWN T5IObv0m9oksRJ+sBkC2qYoUWfCfrLJs4C4/ldWAtRE0a1ZFySg39Iax1FUuoTySYj8A Hf4eMKPclaGaf80NxAgCHdqjwSeiFVDLbbxmDQJCazDVaUauArbiehO9fWP5yfYpmyqG 9ehAdrRXX0B4CFvuu4ysHP0wEO39Wp6pWF/RpLbjht3jUFmjeRYvS/yM3A2PRcdZi0cs VD3nhjAnIBTw5U+tv3kv3PSaG8o5A8nS+X6aT+8G+Cs24NZwPSZpf7ajghiCkT0fagLC 6+EQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=a88wJJyW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id cb4-20020a0564020b6400b004674c93ecb8si374429edb.326.2022.12.22.02.24.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 02:24:05 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=a88wJJyW; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1724638555A0 for ; Thu, 22 Dec 2022 10:23:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1724638555A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671704638; 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=a88wJJyWQbVbrbxZHP5pGPx0ZHoP9hQEJ91v/HkA4L1iBs4QBoilqcR1gVaxDJFxo JeDSPeJronM1mSgnDAw7t+l5p6mv4rpchiOkaGUYRzmlq3FnKo9IP9SCZ8RFfF+Cf5 fAa/ve5wBJlpOg6o1XBf3uFLDZ4NAPmzKaYdTXhE= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752909370086537198?= X-GMAIL-MSGID: =?utf-8?q?1752909370086537198?= 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