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 A58DA385E005 for ; Fri, 30 Jun 2023 10:59:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A58DA385E005 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 imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D17032185F for ; Fri, 30 Jun 2023 10:59:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1688122760; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=9PooOUkNhK1jOFpqD7R2tbU9A7yQyoylacWxFn6qjR8=; b=HZant8f+6T4/PxM0FQXU/u3zaGczeFml5IXPfRAM4HYSzoxSQ87XeQp2bQz1xuOhySeBdf PNwN6ag8fpUb0uukhBVvsbpz2eMkON3q+teD7+/wLxCYjgxDcOuW5OcMEZYL2lrPMlP2qC 7oxaOjACDByCumPQIOlDzE5nN23atFM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1688122760; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=9PooOUkNhK1jOFpqD7R2tbU9A7yQyoylacWxFn6qjR8=; b=nI6dnaIiVS9Ys+7n3ksJYP4Osm3tiLzqc/vOAw0F+t7fHGeQY/NNqQcF6Y1KoBDGkWtwOk HfCqyLUsKYBCNsBw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id BA70D138F8 for ; Fri, 30 Jun 2023 10:59:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ez9sLIi1nmTsGgAAMHmgww (envelope-from ) for ; Fri, 30 Jun 2023 10:59:20 +0000 Date: Fri, 30 Jun 2023 12:59:20 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/110496 - TYPE_PRECISION issue with store-merging MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20230630105920.BA70D138F8@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: When store-merging looks for bswap opportunities we also handle BIT_FIELD_REFs where we verify the refed object is of scalar type but we don't check for the result type we eventually use. That's done later but after we eventually query TYPE_PRECISION. The following re-orders this. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/110496 * gimple-ssa-store-merging.cc (find_bswap_or_nop_1): Re-order verifying and TYPE_PRECISION query for the BIT_FIELD_REF case. * gcc.dg/pr110496.c: New testcase. --- gcc/gimple-ssa-store-merging.cc | 5 ++++- gcc/testsuite/gcc.dg/pr110496.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr110496.c diff --git a/gcc/gimple-ssa-store-merging.cc b/gcc/gimple-ssa-store-merging.cc index 401496a9231..0d19b98ed73 100644 --- a/gcc/gimple-ssa-store-merging.cc +++ b/gcc/gimple-ssa-store-merging.cc @@ -650,10 +650,13 @@ find_bswap_or_nop_1 (gimple *stmt, struct symbolic_number *n, int limit) /* Convert. */ n->type = TREE_TYPE (rhs1); + if (!verify_symbolic_number_p (n, stmt)) + return NULL; + if (!n->base_addr) n->range = TYPE_PRECISION (n->type) / BITS_PER_UNIT; - return verify_symbolic_number_p (n, stmt) ? stmt : NULL; + return stmt; } return NULL; diff --git a/gcc/testsuite/gcc.dg/pr110496.c b/gcc/testsuite/gcc.dg/pr110496.c new file mode 100644 index 00000000000..3c3d12fb532 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr110496.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +long contents, f_num; +int decide(); +int f_MV0__x; +void f() { + unsigned char *rptr; + unsigned char valbuf[6]; + rptr = (unsigned char *)contents; + if (decide()) + do { + __builtin_memcpy(valbuf, &f_MV0__x, sizeof(int)); + (&valbuf[0])[4] = (&valbuf[0])[5] = 0; + } while (0); + else { + int MV0__x = f_num; + __builtin_memcpy(valbuf, &MV0__x, sizeof(int)); + (&valbuf[0])[4] = (&valbuf[0])[5] = 0; + } + rptr[1] = valbuf[4]; + rptr[2] = valbuf[5]; + rptr[4] = valbuf[1]; + rptr[5] = valbuf[2]; + __builtin_memset(valbuf, 0, 8); +} -- 2.35.3