From patchwork Wed Mar 27 10:37:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 87692 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 5FE563858012 for ; Wed, 27 Mar 2024 10:38:44 +0000 (GMT) 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 D5BE6385DC3F for ; Wed, 27 Mar 2024 10:38:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D5BE6385DC3F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D5BE6385DC3F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711535898; cv=none; b=uCOTRjpTjHsH6J5mPNqJYhijKJD1/RGalfHDSihFf1n2wScNALWxelJsKAToP6mpmXDWWTv8n+U5wiWQSt2yYIOHXyYZvun0VT4nyzWDjYrrFM7pB3JTR6T/+BqHzSJPJotizrcyj5P+5EI/bIqA+shE7XQ6ioj08Lv8S/5fmes= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711535898; c=relaxed/simple; bh=0xAvrl/nx2aBGdzIycxzwlJI2jAwELQLUtfsnO/qXu4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=sgUf9onDzmP2LFgoEOzB7L3L2/ngx5SrJF5DvkR5USp7VwrGlhPf3XiwfH3+L+tjw8DuCsKyle1XnXwlsAimcJnZ92c6cgFDANHY9kuoGOPQviz6Bn85SGcv57C0QlJ5XbVkQF2Qceyoat+Lvz1ISWh15pQ5wA3IMP/rJoAxG6A= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711535896; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=T1JB/fOREGGnfr97HX1l76Wi8ntT5KKuerEETr3Hc/4=; b=clu9oPO8xTwLRt3AoN2GfoLDQbCNck8QS9GjEbK0RzR5EEmAGH5MAJR9yHBjxnpFB+Knpf sNIViI4FrDcnr4iHevtzE+AB7QTfDUZnTCncXKEJ4iTkjcjX8uZfynRKc1DOAuF8tUEFCU 86KnPXxOxEBByZmdR3ltPikOBu2BADM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-608-iF7g-VmMPmWz1dTkEif3zg-1; Wed, 27 Mar 2024 06:38:14 -0400 X-MC-Unique: iF7g-VmMPmWz1dTkEif3zg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB522101CC6D; Wed, 27 Mar 2024 10:38:13 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8064840C6DB5; Wed, 27 Mar 2024 10:38:13 +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 42RAboK71688492 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 27 Mar 2024 11:37:51 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42RAboKr1688491; Wed, 27 Mar 2024 11:37:50 +0100 Date: Wed, 27 Mar 2024 11:37:49 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] match.pd: Avoid (view_convert (convert@0 @1)) optimization for extended _BitInts with padding bits [PR114469] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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_H4, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi! The following patch attempts to fix the (view_convert (convert@0 @1)) optimization. If TREE_TYPE (@0) is a _BitInt type with padding bits and @0 has the same precision as @1 and it has a different sign and _BitInt with padding bits are extended on the target (x86 doesn't, aarch64 doesn't, but arm plans to do that), then optimizing it to just (view_convert @1) is wrong, the padding bits wouldn't be what it should be. E.g. bitint-64.c test with -O2 has _5 = (unsigned _BitInt(5)) _4; _7 = (unsigned _BitInt(5)) e.0_1; _8 = _5 + _7; _9 = (_BitInt(5)) _8; _10 = VIEW_CONVERT_EXPR(_9); and forwprop1 changes that to just _5 = (unsigned _BitInt(5)) _4; _7 = (unsigned _BitInt(5)) e.0_1; _8 = _5 + _7; _10 = VIEW_CONVERT_EXPR(_8); The former makes the padding bits well defined (at least on arm in the future), while the latter has those bits zero extended. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-26 Jakub Jelinek PR tree-optimization/114469 * match.pd ((view_convert (convert@0 @1))): Don't optimize if TREE_TYPE (@0) is a BITINT_TYPE with padding bits which are supposed to be extended by the ABI. Jakub --- gcc/match.pd.jj 2024-03-15 11:04:24.672914747 +0100 +++ gcc/match.pd 2024-03-26 15:49:44.177864509 +0100 @@ -4699,13 +4699,38 @@ (define_operator_list SYNC_FETCH_AND_AND zero-extend while keeping the same size (for bool-to-char). */ (simplify (view_convert (convert@0 @1)) - (if ((INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0))) - && (INTEGRAL_TYPE_P (TREE_TYPE (@1)) || POINTER_TYPE_P (TREE_TYPE (@1))) - && TYPE_SIZE (TREE_TYPE (@0)) == TYPE_SIZE (TREE_TYPE (@1)) - && (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)) - || (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (TREE_TYPE (@1)) - && TYPE_UNSIGNED (TREE_TYPE (@1))))) - (view_convert @1))) + (with { tree type0 = TREE_TYPE (@0); + tree type1 = TREE_TYPE (@1); + bool ok = false; + if ((INTEGRAL_TYPE_P (type0) || POINTER_TYPE_P (type0)) + && (INTEGRAL_TYPE_P (type1) || POINTER_TYPE_P (type1)) + && TYPE_SIZE (type0) == TYPE_SIZE (type1)) + { + if (TYPE_PRECISION (type0) == TYPE_PRECISION (type1)) + { + if (TREE_CODE (type0) != BITINT_TYPE) + ok = true; + else + { + /* Avoid optimizing this if type0 is a _BitInt + type with padding bits which are supposed to be + extended. */ + struct bitint_info info; + targetm.c.bitint_type_info (TYPE_PRECISION (type0), + &info); + if (!info.extended) + ok = true; + else + ok = (TYPE_PRECISION (type0) + == tree_to_uhwi (TYPE_SIZE (type0))); + } + } + else if (TYPE_PRECISION (type0) > TYPE_PRECISION (type1) + && TYPE_UNSIGNED (type1)) + ok = true; + } } + (if (ok) + (view_convert @1)))) /* Simplify a view-converted empty or single-element constructor. */ (simplify