From patchwork Wed Mar 30 07:53:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1610970 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=y0ldHLy7; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KSzGd1sCYz9sFk for ; Wed, 30 Mar 2022 18:54:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1256C3865479 for ; Wed, 30 Mar 2022 07:54:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1256C3865479 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648626853; bh=e2Dd8rzDqD1gwVr2U2Pvs3LTTT8M6lyOPd05fbImxu0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=y0ldHLy7Ux3DZnHyQayYGQZAvbKpktRAEB4RNbMwma7ispQVsKb6UX+8hr4hWJewr XEn7yYcbGljRSWVk0V0DJgJlAUiZwA2FpGyB/Kii3S+953agyQnNOzzRhyFpRM2enr sXHhZgY7k7OfKdO7xehSU7BSpwM/tZtnrr34gLCM= 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 EDEFB3858403 for ; Wed, 30 Mar 2022 07:53:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EDEFB3858403 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-264-FFXFVPugP2qbtn4XIoyXNg-1; Wed, 30 Mar 2022 03:53:49 -0400 X-MC-Unique: FFXFVPugP2qbtn4XIoyXNg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E669C3801EC3; Wed, 30 Mar 2022 07:53:48 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99954C15E74; Wed, 30 Mar 2022 07:53:48 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 22U7rkN5152833 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 09:53:46 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 22U7reOP152831; Wed, 30 Mar 2022 09:53:40 +0200 Date: Wed, 30 Mar 2022 09:53:40 +0200 To: Richard Biener Subject: [PATCH] store-merging: Avoid ICEs on roughly ~0ULL/8 sized stores [PR105094] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! On the following testcase on 64-bit targets, store-merging sees a MEM_REF store from {} ctor with "negative" bitsize where bitoff + bitsize wraps around to very small end offset. This later confuses the code so that it allocates just a few bytes of memory but fills in huge amounts of it. Later on there is a param_store_merging_max_size size check but due to the wrap-around we pass that. The following patch punts on such large bitsizes. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-03-30 Jakub Jelinek PR tree-optimization/105094 * gimple-ssa-store-merging.cc (mem_valid_for_store_merging): Punt if bitsize <= 0 rather than just == 0. * gcc.dg/pr105094.c: New test. Jakub --- gcc/gimple-ssa-store-merging.cc.jj 2022-02-04 14:36:55.000000000 +0100 +++ gcc/gimple-ssa-store-merging.cc 2022-03-29 12:06:44.918286242 +0200 @@ -4940,7 +4940,7 @@ mem_valid_for_store_merging (tree mem, p tree base_addr = get_inner_reference (mem, &bitsize, &bitpos, &offset, &mode, &unsignedp, &reversep, &volatilep); *pbitsize = bitsize; - if (known_eq (bitsize, 0)) + if (known_le (bitsize, 0)) return NULL_TREE; if (TREE_CODE (mem) == COMPONENT_REF --- gcc/testsuite/gcc.dg/pr105094.c.jj 2022-03-29 12:32:16.871391545 +0200 +++ gcc/testsuite/gcc.dg/pr105094.c 2022-03-29 12:30:51.667609971 +0200 @@ -0,0 +1,13 @@ +/* PR tree-optimization/105094 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct S { short a; char b[~(__SIZE_TYPE__)0 / __CHAR_BIT__ - 1]; }; +void bar (struct S *); + +void +foo (void) +{ + struct S s = { 5 }; + bar (&s); +}