From patchwork Mon Sep 11 17:33:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 137912 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp2221307vqo; Mon, 11 Sep 2023 10:34:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHAuf8hsXxgOAjQ93X1sYuOQNmnpZAH52PSKUKEBDsnTZLDxzbH5US8ZqBcSHMrHKBOwQ3V X-Received: by 2002:a05:6402:2794:b0:52e:33ad:1c45 with SMTP id b20-20020a056402279400b0052e33ad1c45mr433173ede.11.1694453671882; Mon, 11 Sep 2023 10:34:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694453671; cv=none; d=google.com; s=arc-20160816; b=1AyJ+Ed882H6tSvnugOr1MRc5LbWYdLURGLss1w4VJzyb6fzLOD6e93eXuqXPO6gMd echgS84DmZ8DDjci6Nr18RoLI2EtL416Zo7lhhSCZCErb+ZSGZNnt5evWi6+iF9HJZrQ ZAdQ3qzlNz1U67Q2gd0YbP4P6UXwUJ8ia1dXi7ZNU3C11J/KcZLDQlxaLibQIwdu6HcL U7Lzr8SReDvp6Yni8Au7eVoPeGfuh3LXafoi4av0uuZKyNE4hsit0BrbqP7O87rRxgJS rCZxd87cT7pHFQZdQml9S4H9mMEIL0gxWln4r9v1x+dXFDdElDN3o1PRZYs/EmQo4/Gv fYIQ== 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=mEJ0GgBrkAVezdGGUSLqmBCKKp7o5VrOCthRDBcxbLw=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=TV3C3bCHlTHcw5H3POrBFUOWyRKFnhmp2ApVxrHSwumGc/2IxosSyhWiPEcduN6g0O fuNVuqeULSL0ad0R/i7svXP3WrdSdlJQk9ht9qgguFavFvIvS+Ds4+4v4ccAV7yPdX9f 877LJhv4qCylRtDsJXZ/UbAXVGT5tpSgdq8XVnt2BiVOc/R+O2QJntCUpCOh/EvofWMj afFATNWNe0u7GoVHCXw0Me5j5bzSKuhFUIJAY7nq0eUZ8H9sf8ZtGXcUDdqmJXUH7tOd gWOzyZwVn7H34rRwfF/WJyAEwpLhHQ6Nt4Cl89d4zw2hHqcAvTDsASmDnT4Aufz09eVX yWAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=acnZ+Huy; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y23-20020a056402135700b005231db540d4si7503417edw.230.2023.09.11.10.34.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 10:34:31 -0700 (PDT) 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=acnZ+Huy; 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 907623858404 for ; Mon, 11 Sep 2023 17:34:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 907623858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694453669; bh=mEJ0GgBrkAVezdGGUSLqmBCKKp7o5VrOCthRDBcxbLw=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=acnZ+Huy3QxuA0pVlRS5AkskbCPkZITgp+Fv8udCE4CPxtwWWTNuZlRniNmL7csHl DKs8QB06WOfGW76sA/9YnVK0NnGF016XsqkMzPa3f7qgYKX685OrLjDKO74BOPb4Or 8V97eGyBjQXIZbSZrRhGLP5ZDxONQLyp5az7BPv4= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id DABA53858D38 for ; Mon, 11 Sep 2023 17:33:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DABA53858D38 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-490-qS-5gKeyNeOykPDgCZLmcA-1; Mon, 11 Sep 2023 13:33:44 -0400 X-MC-Unique: qS-5gKeyNeOykPDgCZLmcA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 06E8A1026447; Mon, 11 Sep 2023 17:33:44 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.225.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDC672156701; Mon, 11 Sep 2023 17:33:43 +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 38BHXf1X3694262 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 11 Sep 2023 19:33:42 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 38BHXfAu3694261; Mon, 11 Sep 2023 19:33:41 +0200 Date: Mon, 11 Sep 2023 19:33:41 +0200 To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] sccvn: Avoid ICEs on _BitInt load BIT_AND_EXPR mask [PR111338] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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_H3, RCVD_IN_MSPIKE_WL, 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.30 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: INBOX X-GMAIL-THRID: 1776763452981543961 X-GMAIL-MSGID: 1776763452981543961 Hi! The following testcase ICEs, because vn_walk_cb_data::push_partial_def uses a fixed size buffer (64 target bytes) for its construction/deconstruction of partial stores and fails if larger precision than that is needed, and the PR93582 changes assert push_partial_def succeeds (and check the various other conditions much earlier when seeing the BIT_AND_EXPR statement, like CHAR_BIT == 8, BITS_PER_UNIT == 8, BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN, etc.). So, just removing the assert and allowing it fail there doesn't really work and ICEs later on. The following patch moves the bufsize out of the method and tests it together with the other checks. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? BTW, perhaps we could increase the bufsize as well or in addition to increasing it make the buffer allocated using XALLOCAVEC, but still I think it is useful to have some upper bound and so I think this patch is useful even in that case. 2023-09-11 Jakub Jelinek PR middle-end/111338 * tree-ssa-sccvn.cc (struct vn_walk_cb_data): Add bufsize non-static data member. (vn_walk_cb_data::push_partial_def): Remove bufsize variable. (visit_nary_op): Avoid the BIT_AND_EXPR with constant rhs2 optimization if type's precision is too large for vn_walk_cb_data::bufsize. * gcc.dg/bitint-37.c: New test. Jakub --- gcc/tree-ssa-sccvn.cc.jj 2023-09-06 17:28:24.232977433 +0200 +++ gcc/tree-ssa-sccvn.cc 2023-09-08 13:22:27.928158846 +0200 @@ -1903,6 +1903,7 @@ struct vn_walk_cb_data alias_set_type first_base_set; splay_tree known_ranges; obstack ranges_obstack; + static constexpr HOST_WIDE_INT bufsize = 64; }; vn_walk_cb_data::~vn_walk_cb_data () @@ -1973,7 +1974,6 @@ vn_walk_cb_data::push_partial_def (pd_da HOST_WIDE_INT offseti, HOST_WIDE_INT maxsizei) { - const HOST_WIDE_INT bufsize = 64; /* We're using a fixed buffer for encoding so fail early if the object we want to interpret is bigger. */ if (maxsizei > bufsize * BITS_PER_UNIT @@ -5414,6 +5414,7 @@ visit_nary_op (tree lhs, gassign *stmt) && CHAR_BIT == 8 && BITS_PER_UNIT == 8 && BYTES_BIG_ENDIAN == WORDS_BIG_ENDIAN + && TYPE_PRECISION (type) <= vn_walk_cb_data::bufsize * BITS_PER_UNIT && !integer_all_onesp (gimple_assign_rhs2 (stmt)) && !integer_zerop (gimple_assign_rhs2 (stmt))) { --- gcc/testsuite/gcc.dg/bitint-37.c.jj 2023-09-08 13:27:51.676882523 +0200 +++ gcc/testsuite/gcc.dg/bitint-37.c 2023-09-08 13:27:22.460268614 +0200 @@ -0,0 +1,11 @@ +/* PR middle-end/111338 */ +/* { dg-do compile { target bitint575 } } */ +/* { dg-options "-O1" } */ + +_BitInt(575) e; + +_BitInt(575) +foo (void) +{ + return e & 1; +}