From patchwork Tue Sep 19 07:48:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 141720 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3201583vqi; Tue, 19 Sep 2023 00:49:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHw5p5ywtgT8JFgbcUzvEpmjYaKWE7eqy6alnfV9n1pyo7shBrb8QgAfCDZapz6IgsCuvjl X-Received: by 2002:a05:6402:229b:b0:530:1bab:f8a5 with SMTP id cw27-20020a056402229b00b005301babf8a5mr2355153edb.6.1695109780457; Tue, 19 Sep 2023 00:49:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695109780; cv=none; d=google.com; s=arc-20160816; b=rWNn0xeh/t5TbpkDD0FDc9JkpgNW0Kzz6eLG9plAYpTGw9PC8rINvWVJqdY5PqE841 1FDV+k+YsDtQ6+GuMXE9h+mHi6KpWrEt9SHI49sCKIDntG9/SYwjjCX2/OJOX86Tb5do XE+4NItLgPtez02hhFV9E+jjDpzrqB3g8s+BurkIv8I+0HFfRbnka5+3J11h3NQ/lknO XXsSrHcymqYI9oilOCzWsTD4rO1PsBlnlfN03dKO9ky4NOZZqwDLoei+H6MVb7bvSgg0 qUFKPW6+ShvKZUMbf/bd9FdDJtQiMa/gWtNSllqD6OgXmOo6OtDfxWwCCm8wB3EB6HOf BnBA== 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=SX8yQAoZZTFBS4BMxJMeh3PDx5aNkxBxuLD0iAKG2Qk=; fh=4BGZEqj80tnema6wO63RKu8g5BQo5zzXnRzaT6yPDWM=; b=ZyR3JK3jf3xq6087i/7sohYvHJWBQabvb2oEf2QvwAsirPNO6cYmItPueywYFt5Rpm QK6LQuUi3ABwD53oMTnz7BX2xlSegXXO+k+cT60Tucc0l/t3xMVgkHw69++JLR37aJUX XpABhWSylD/IY2WCdgc3+w75vrCacUt6jOnAEOh6c2Nxp+dIlEvSGN/bLuynC0BFiBB3 /Z1o3V53OAZTA8lNKA/+4Kc/GXSvXuX5SWx1CNz8nfXpCYJBw0MOmdX8SeVhFqYW+vyJ ZUNjvfm8LBaJ5JP1LEVrrPQK0NJCtAJAhK4jisSmcxPvGrCEpMQSiEZmPmdaCSNZEvcq 8Ydw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Iubs8sGl; 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 l10-20020a056402344a00b00530a3223a79si6970272edc.212.2023.09.19.00.49.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 00:49:40 -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=Iubs8sGl; 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 D2A083858D3C for ; Tue, 19 Sep 2023 07:49:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2A083858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695109778; bh=SX8yQAoZZTFBS4BMxJMeh3PDx5aNkxBxuLD0iAKG2Qk=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Iubs8sGlvn0Lx2zRdtlmjLAiHS0ZY7Ir1CzxGGznUxKpN2kjDb3+ZJTnSf+v+ESbE XSGfc84M6OAG8tovMNxLBP0rKM/4IS8tCq/NH3YcdD7AdoecJkZ9CMbgAJRbBvR6X3 68CJwLigRH23QfmXPlM5sGlTLlpBqTLp6wYx0iwo= 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 8785A3858D39 for ; Tue, 19 Sep 2023 07:48:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8785A3858D39 Received: from mimecast-mx02.redhat.com (mx-ext.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-225-zkbZvr1RNO-jqUJOuWjpqA-1; Tue, 19 Sep 2023 03:48:51 -0400 X-MC-Unique: zkbZvr1RNO-jqUJOuWjpqA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 925203C0BE28; Tue, 19 Sep 2023 07:48:51 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.82]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5524D40C6EA8; Tue, 19 Sep 2023 07:48:51 +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 38J7mnLv2523985 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 19 Sep 2023 09:48:49 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 38J7mmEn2523984; Tue, 19 Sep 2023 09:48:48 +0200 Date: Tue, 19 Sep 2023 09:48:48 +0200 To: Richard Biener Cc: gcc-patches@gcc.gnu.org, Andrew Pinski Subject: [PATCH] match.pd: Some build_nonstandard_integer_type tweaks Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-0.9 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, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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: 1777451432848761980 X-GMAIL-MSGID: 1777451432848761980 Hi! As discussed earlier, using build_nonstandard_integer_type blindly for all INTEGRAL_TYPE_Ps is problematic now that we have BITINT_TYPE, because it always creates an INTEGRAL_TYPE with some possibly very large precision. The following patch attempts to deal with 3 such spots in match.pd, others still need looking at. In the first case, I think it is quite expensive/undesirable to create a non-standard INTEGER_TYPE with possibly huge precision and then immediately just see type_has_mode_precision_p being false for it, or even worse introducing a cast to TImode or OImode or XImode INTEGER_TYPE which nothing will be able to actually handle. 128-bit or 64-bit (on 32-bit targets) types are the largest supported by the backend, so the following patch avoids creating and matching conversions to larger types, it is an optimization anyway and so should be used when it is cheap that way. In the second hunk, I believe the uses of build_nonstandard_integer_type aren't useful at all. It is when matching a ? -1 : 0 and trying to express it as say -(type) (bool) a etc., but this is all GIMPLE only, where most of integral types with same precision/signedness are compatible and we know -1 is representable in that type, so I really don't see any reason not to perform the negation of a [0, 1] valued expression in type, rather than doing it in build_nonstandard_integer_type (TYPE_PRECISION (type), TYPE_UNSIGNED (type)) (except that it breaks the BITINT_TYPEs). I don't think we need to do something like range_check_type. While in there, I've also noticed it was using a (with { tree booltrue = constant_boolean_node (true, boolean_type_node); } and removed that + replaced uses of booltrue with boolean_true_node which the above function always returns. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-09-19 Jakub Jelinek * match.pd ((x << c) >> c): Don't call build_nonstandard_integer_type nor check type_has_mode_precision_p for width larger than [TD]Imode precision. (a ? CST1 : CST2): Don't use build_nonstandard_type, just convert to type. Use boolean_true_node instead of constant_boolean_node (true, boolean_type_node). Formatting fixes. Jakub --- gcc/match.pd.jj 2023-09-18 10:37:56.002965361 +0200 +++ gcc/match.pd 2023-09-18 12:14:32.321631010 +0200 @@ -4114,9 +4114,13 @@ (define_operator_list SYNC_FETCH_AND_AND (if (INTEGRAL_TYPE_P (type)) (with { int width = element_precision (type) - tree_to_uhwi (@1); - tree stype = build_nonstandard_integer_type (width, 0); + tree stype = NULL_TREE; + scalar_int_mode mode = (targetm.scalar_mode_supported_p (TImode) + ? TImode : DImode); + if (width <= GET_MODE_PRECISION (mode)) + stype = build_nonstandard_integer_type (width, 0); } - (if (width == 1 || type_has_mode_precision_p (stype)) + (if (stype && (width == 1 || type_has_mode_precision_p (stype))) (convert (convert:stype @0)))))))) /* Optimize x >> x into 0 */ @@ -5092,49 +5096,24 @@ (define_operator_list SYNC_FETCH_AND_AND /* a ? -1 : 0 -> -a. No need to check the TYPE_PRECISION not being 1 here as the powerof2cst case above will handle that case correctly. */ (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1)) + (negate (convert:type (convert:boolean_type_node @0)))))) + (if (integer_zerop (@1)) + (switch + /* a ? 0 : 1 -> !a. */ + (if (integer_onep (@2)) + (convert (bit_xor (convert:boolean_type_node @0) { boolean_true_node; }))) + /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */ + (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2)) (with { - auto prec = TYPE_PRECISION (type); - auto unsign = TYPE_UNSIGNED (type); - tree inttype = build_nonstandard_integer_type (prec, unsign); + tree shift = build_int_cst (integer_type_node, tree_log2 (@2)); } - (convert (negate (convert:inttype (convert:boolean_type_node @0)))))))) - (if (integer_zerop (@1)) - (with { - tree booltrue = constant_boolean_node (true, boolean_type_node); - } - (switch - /* a ? 0 : 1 -> !a. */ - (if (integer_onep (@2)) - (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))) - /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */ - (if (INTEGRAL_TYPE_P (type) && integer_pow2p (@2)) - (with { - tree shift = build_int_cst (integer_type_node, tree_log2 (@2)); - } - (lshift (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )) - { shift; }))) - /* a ? -1 : 0 -> -(!a). No need to check the TYPE_PRECISION not being 1 + (lshift (convert (bit_xor (convert:boolean_type_node @0) + { boolean_true_node; })) { shift; }))) + /* a ? -1 : 0 -> -(!a). No need to check the TYPE_PRECISION not being 1 here as the powerof2cst case above will handle that case correctly. */ - (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2)) - (with { - auto prec = TYPE_PRECISION (type); - auto unsign = TYPE_UNSIGNED (type); - tree inttype = build_nonstandard_integer_type (prec, unsign); - } - (convert - (negate - (convert:inttype - (bit_xor (convert:boolean_type_node @0) { booltrue; } ) - ) - ) - ) - ) - ) - ) - ) - ) - ) -) + (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2)) + (negate (convert:type (bit_xor (convert:boolean_type_node @0) + { boolean_true_node; })))))))) /* (a > 1) ? 0 : (cast)a is the same as (cast)(a == 1) for unsigned types. */