From patchwork Wed Aug 9 19:19:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 133443 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp3021582vqr; Wed, 9 Aug 2023 12:20:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFywbbVmvGDMfytVCUsAf1yPDruxDFqgIuGSMsMDa7ZqSbxp6L+/UKbwqPV20n5gzmxys2I X-Received: by 2002:a17:907:760a:b0:988:6491:98e1 with SMTP id jx10-20020a170907760a00b00988649198e1mr28562ejc.42.1691608853032; Wed, 09 Aug 2023 12:20:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691608853; cv=none; d=google.com; s=arc-20160816; b=W1Ama8ehjGnAaDXe9od+7HazaVPJi2JqHSHtP3Kk2ei/pP2c1sd1cv4LWBbe1OwybI jlSJFoqddOEuSoDDNtUXsAOJi+Ump8UR9mpmM2hBC4JE3i74UEzY/ZwdVDAM5NA8PT6L K2R2hNxgdW0N9RDlS3s/JLz0toV10MIi5NANRmtR3q6BiZL+1TCkGCMN7DKsaOo5Tl+I pW7sxI9Nq8sIHGzePndSMClYZgsF6bk+m2UoeEKSe+ITLJCH+oonBLpUtCfDmDe/Eo0P Sc0tHfwir1VF8Jbjz8siN/3s9Vp3YE4en4h4iAyyDsPIr8mW7wwH6CKyUVk0KL9/WK1g WDDg== 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-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=7iw/Em0vG7ex7+mE4nDoLJwLfMFuUIQFJ6r0IaKkBDo=; fh=09okz+w4tVyhQmqNBttR063P0zKcIsLE1JRBioNPGC4=; b=N6eiyX369gCk9vU8tl+fGLDxi3obwIXSZR5HySdv+GnWeR0EeSgnrC1QALqPc7GYnm xdz7/lT3kox+F6owcAj4nH7WYQ3kJ7aI3NfhN6QclymPZV8K3/zdgs6v5FEtBSbWjjfg ngFaeX0Z8HY0Y46spwRLwvq5d2AST25bqiTf++UKoytD6fei5voxB9057Wl315AGYS1E /6cw9VAEPqFSxhD/XMmfL5r/GPD904ksPx7WN6ouMU6rCAUKbpmPxSzYFul1rm/Cbbvh H8RGwTqsRbhRn9iZhTD9ABNpXn5t2kBkO0/JU45lFXCF4slODoLISI4YW568bBZeHPg4 A5qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vkLZCK5S; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u18-20020a17090617d200b0098e42bef73asi8982166eje.98.2023.08.09.12.20.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 12:20:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vkLZCK5S; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 EC4CE3856DF1 for ; Wed, 9 Aug 2023 19:20:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC4CE3856DF1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691608852; bh=7iw/Em0vG7ex7+mE4nDoLJwLfMFuUIQFJ6r0IaKkBDo=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=vkLZCK5SzM0BjNwjhXInrDO66j+7VJL519xW4yOoDmIg9MTPtHSF3jcYySkYRXSuf YrcddbCoVph/hX9s0X2dcek57XbiYGXgYo01Ms4Fke9kn82TmD1ZqtNL7/eSOsL1Bx x0xEYsmaPy10HYcW5acit/gnFRRghj7fuSkdmflI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id 920933858D33 for ; Wed, 9 Aug 2023 19:20:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 920933858D33 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 379Irncw027769 for ; Wed, 9 Aug 2023 12:20:09 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3sbkntp3v2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 09 Aug 2023 12:20:08 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 9 Aug 2023 12:20:07 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 9 Aug 2023 12:20:07 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 9F4B35B692F; Wed, 9 Aug 2023 12:20:06 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: [PR110937/PR100798] (a ? ~b : b) should be optimized to b ^ -(a) Date: Wed, 9 Aug 2023 12:19:54 -0700 Message-ID: <20230809191954.2668047-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: dxQbVrQ8zGW1sackN7tUk5oOfSgFNVAX X-Proofpoint-ORIG-GUID: dxQbVrQ8zGW1sackN7tUk5oOfSgFNVAX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-09_17,2023-08-09_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773780444908115013 X-GMAIL-MSGID: 1773780444908115013 This adds a simple match pattern for this case. I noticed it a couple of different places. One while I was looking at code generation of a parser and also while I was looking at locations where bitwise_inverted_equal_p should be used more. Committed as approved after bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/110937 PR tree-optimization/100798 gcc/ChangeLog: * match.pd (`a ? ~b : b`): Handle this case. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/bool-14.c: New test. * gcc.dg/tree-ssa/bool-15.c: New test. * gcc.dg/tree-ssa/phi-opt-33.c: New test. * gcc.dg/tree-ssa/20030709-2.c: Update testcase so `a ? -1 : 0` is not used to hit the match pattern. --- gcc/match.pd | 14 ++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c | 5 +++-- gcc/testsuite/gcc.dg/tree-ssa/bool-14.c | 15 +++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/bool-15.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/phi-opt-33.c | 13 +++++++++++++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-14.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bool-15.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-33.c diff --git a/gcc/match.pd b/gcc/match.pd index 9b4819e5be7..fc630b63563 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -6460,6 +6460,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (cmp == NE_EXPR) { constant_boolean_node (true, type); }))))))) +#if GIMPLE +/* a?~t:t -> (-(a))^t */ +(simplify + (cond @0 @1 @2) + (if (INTEGRAL_TYPE_P (type) + && bitwise_inverted_equal_p (@1, @2)) + (with { + auto prec = TYPE_PRECISION (type); + auto unsign = TYPE_UNSIGNED (type); + tree inttype = build_nonstandard_integer_type (prec, unsign); + } + (convert (bit_xor (negate (convert:inttype @0)) (convert:inttype @2)))))) +#endif + /* Simplify pointer equality compares using PTA. */ (for neeq (ne eq) (simplify diff --git a/gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c b/gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c index 5009cd69cfe..78938f919d4 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c @@ -29,15 +29,16 @@ union tree_node }; int make_decl_rtl (tree, int); void * -get_alias_set (t) +get_alias_set (t, t1) tree t; + void *t1; { long set; if (t->decl.rtl) return (t->decl.rtl->fld[1].rtmem ? 0 : (((t->decl.rtl ? t->decl.rtl: (make_decl_rtl (t, 0), t->decl.rtl)))->fld[1]).rtmem); - return (void*)-1; + return t1; } /* There should be precisely one load of ->decl.rtl. If there is diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-14.c b/gcc/testsuite/gcc.dg/tree-ssa/bool-14.c new file mode 100644 index 00000000000..0149380a63b --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-14.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ +/* PR tree-optimization/110937 */ + +_Bool f2(_Bool a, _Bool b) +{ + if (a) + return !b; + return b; +} + +/* We should be able to remove the conditional and convert it to an xor. */ +/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */ +/* { dg-final { scan-tree-dump-not "gimple_phi " "optimized" } } */ +/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bool-15.c b/gcc/testsuite/gcc.dg/tree-ssa/bool-15.c new file mode 100644 index 00000000000..1f496663863 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/bool-15.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ +/* PR tree-optimization/110937 */ + +_Bool f2(int x, int y, int w, int z) +{ + _Bool a = x == y; + _Bool b = w == z; + if (a) + return !b; + return b; +} + +/* We should be able to remove the conditional and convert it to an xor. */ +/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */ +/* { dg-final { scan-tree-dump-not "gimple_phi " "optimized" } } */ +/* { dg-final { scan-tree-dump-not "ne_expr, " "optimized" } } */ +/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-33.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-33.c new file mode 100644 index 00000000000..b79fe44187a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-33.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized-raw" } */ +/* PR tree-optimization/100798 */ + +int f(int a, int t) +{ + return (a=='s' ? ~t : t); +} + +/* This should be convert into t^-(a=='s'). */ +/* { dg-final { scan-tree-dump-times "bit_xor_expr, " 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times "negate_expr, " 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "bit_not_expr, " "optimized" } } */ From patchwork Tue Sep 5 07:28:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 137477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp1515975vqo; Tue, 5 Sep 2023 00:28:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IECegZKKiCR1ukOzz4RlfxlPr+QIQJeTe9Uq0PWOnytQwjBe49ljCqobqjl4csb9JqgxA9U X-Received: by 2002:a05:6402:1510:b0:522:586d:6f3a with SMTP id f16-20020a056402151000b00522586d6f3amr8290921edw.6.1693898930817; Tue, 05 Sep 2023 00:28:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693898930; cv=none; d=google.com; s=arc-20160816; b=aY7tA6wwVvYGX3f+/e8vS8dlXJ+Y2AoW1VdD3oyUEk1RIX48SqRYYxOgiApl/eHdVQ LPsIqb2oA8g9pMn4jINUg0EtbqaWPya8PDGKRYX70p2v6oFMd53rKlcrKC7ziIr1gVWB ymWKrGDFclkQhjVg7yzkymdmRcch7YeKExaiCwWSb4yejplM8/nM5cP0OlDnBxtDEodX GH3/p3vtI5tn3BrYXP3OJEfkiM1FkpdMFc3mhX+XRta+50keCkrLMkj2L/AZaHoore62 KsQRFyVlAboZ8AnOV92Cf0LafMhjPPCbnEJ2BFA2fuRaPa6Yhzm1jwCeL2txlYWOPdOs ANuA== 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:in-reply-to:mime-version:references:message-id :subject:cc:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=CWVuM+PF+VeXBqYuK7AXEJ0qx5/1/7papUx6+jLcucc=; fh=2qdt0TksaDMEtyRXgOEaiyy4AOp5SYWp0B8DmASKo1Y=; b=Ot35YrCGLXwMemEIPLwE6RkM9EfcS+P0EP9x7N4qs0Nifr6MwYyRMKPUNIH/JyKuSX zMYYOUJ414rIAf0rWX7Enb2yG855kvQpMwTDpC8f6D+plvAm5roApktfBhzqD/g78lhf 3qySKu49PBqq5eg/JEZbNBjCu0ooAJ35z5CKK/fY8jxQIzDQ9dEjAb96MH3BUxah+tUj 6QXD9As1ieJMr2Pn7GrGSMs2U3ERIpohbnnqINbbwDqdHyVPfqvqnh9nFp8GMs+Scdk2 LZ3zLV9XF6Z/KzyfV6DuIiH1rQMV6hFRteAvmRTA5mYeoHZTcP/w6uoe2NKX7OABha/1 6hIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UuqPVgb5; 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 y15-20020a056402358f00b0052e48d1114bsi1785058edc.595.2023.09.05.00.28.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 00:28:50 -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=UuqPVgb5; 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 7FF123858C2A for ; Tue, 5 Sep 2023 07:28:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FF123858C2A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693898929; bh=CWVuM+PF+VeXBqYuK7AXEJ0qx5/1/7papUx6+jLcucc=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=UuqPVgb52qReQN9jabCQ5EX3f7OMVHUSRBx8Run6wmh4N4znBLo6Vq9o4Or18TSSg kTIuagFSb+OjzFAqXZHCiR/v/kJI+5lMG0e+FndkDw8/+H/JXZp9ydrX0/rqFC/14F 5TZkuyEvMbZBxU5gHrGW7zfwdQzNAZGtcbj3v0Ow= 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 3E8043858D32 for ; Tue, 5 Sep 2023 07:28:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E8043858D32 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-446-fi2ck-ozMhGFAtjIYIR8MQ-1; Tue, 05 Sep 2023 03:28:04 -0400 X-MC-Unique: fi2ck-ozMhGFAtjIYIR8MQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0F3CC937705; Tue, 5 Sep 2023 07:28:04 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C7D421182E9; Tue, 5 Sep 2023 07:28:03 +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 3857S1Re2876992 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Sep 2023 09:28:02 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3857S1xx2876991; Tue, 5 Sep 2023 09:28:01 +0200 Date: Tue, 5 Sep 2023 09:28:01 +0200 To: Andrew Pinski , Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH 17/12] _BitInt a ? ~b : b match.pd fix [PR102989] Message-ID: References: <20230809191954.2668047-1-apinski@marvell.com> MIME-Version: 1.0 In-Reply-To: <20230809191954.2668047-1-apinski@marvell.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: , 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: 1776181765397796931 X-GMAIL-MSGID: 1776181765397796931 On Wed, Aug 09, 2023 at 12:19:54PM -0700, Andrew Pinski via Gcc-patches wrote: > PR tree-optimization/110937 > PR tree-optimization/100798 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -6460,6 +6460,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > (if (cmp == NE_EXPR) > { constant_boolean_node (true, type); }))))))) > > +#if GIMPLE > +/* a?~t:t -> (-(a))^t */ > +(simplify > + (cond @0 @1 @2) > + (if (INTEGRAL_TYPE_P (type) > + && bitwise_inverted_equal_p (@1, @2)) > + (with { > + auto prec = TYPE_PRECISION (type); > + auto unsign = TYPE_UNSIGNED (type); > + tree inttype = build_nonstandard_integer_type (prec, unsign); > + } > + (convert (bit_xor (negate (convert:inttype @0)) (convert:inttype @2)))))) > +#endif This broke one bitint test - bitint-42.c for -O1 and -Os (in admittedly not yet committed series). Using build_nonstandard_integer_type this way doesn't work well for larger precision BITINT_TYPEs, because it always creates an INTEGER_TYPE and say 467-bit INTEGER_TYPE doesn't work very well. To get a BITINT_TYPE, one needs to use build_bitint_type instead (but similarly to build_nonstandard_integer_type one should first make sure such a type actually can be created). I admit it isn't really clear to me what do you want to achieve by the above build_nonstandard_integer_type. Is it because of BOOLEAN_TYPE or perhaps ENUMERAL_TYPE as well? If type is INTEGER_TYPE or BITINT_TYPE, one doesn't really need to create a new type, type already is an integral type with that precision and signedness. In other places using unsigned_type_for or signed_type_for might be better than using build_nonstandard_integer_type if that is what one wants to achieve, those functions handle BITINT_TYPE. Or shall we instead test for == BOOLEAN_TYPE (or if ENUMERAL_TYPE for some reason needs the same treatment also || == ENUMERAL_TYPE)? 2023-09-05 Jakub Jelinek PR c/102989 * match.pd (a ? ~b : b): Don't use build_nonstandard_integer_type for INTEGER_TYPE or BITINT_TYPE. Jakub --- gcc/match.pd.jj 2023-09-04 09:45:33.553058301 +0200 +++ gcc/match.pd 2023-09-05 08:45:53.258078971 +0200 @@ -6631,7 +6631,9 @@ (define_operator_list SYNC_FETCH_AND_AND (with { auto prec = TYPE_PRECISION (type); auto unsign = TYPE_UNSIGNED (type); - tree inttype = build_nonstandard_integer_type (prec, unsign); + tree inttype = type; + if (TREE_CODE (type) != INTEGER_TYPE && TREE_CODE (type) != BITINT_TYPE) + inttype = build_nonstandard_integer_type (prec, unsign); } (convert (bit_xor (negate (convert:inttype @0)) (convert:inttype @2))))))) #endif