From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id E0D9B3858403 for ; Sat, 13 Nov 2021 20:13:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E0D9B3858403 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 1ADCrcvb005191 for ; Sat, 13 Nov 2021 12:13:58 -0800 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3cadrsruqj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 13 Nov 2021 12:13:58 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sat, 13 Nov 2021 12:13:56 -0800 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.18 via Frontend Transport; Sat, 13 Nov 2021 12:13:56 -0800 Received: from linux.wrightpinski.org.com (unknown [10.69.242.198]) by maili.marvell.com (Postfix) with ESMTP id C62873F7071; Sat, 13 Nov 2021 12:13:55 -0800 (PST) From: To: CC: Andrew Pinski Subject: [PATCH] tree-optimization: [PR103218] Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit Date: Sat, 13 Nov 2021 12:13:47 -0800 Message-ID: <1636834427-22589-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-ORIG-GUID: IZydzKChyBLaH_TsoPw2sSC9HihjJNjm X-Proofpoint-GUID: IZydzKChyBLaH_TsoPw2sSC9HihjJNjm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-13_02,2021-11-12_01,2020-04-07_01 X-Spam-Status: No, score=-14.7 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.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-List-Received-Date: Sat, 13 Nov 2021 20:14:00 -0000 From: Andrew Pinski This folds Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit inside match.pd. This was already handled in fold-cost by: /* A < 0 ? : 0 is simply (A & ). */ I have not removed as we only simplify "a ? POW2 : 0" at the gimple level to "a << CST1" and fold actually does the reverse of folding "(a<0)<> C) into -(x > 0) where C = precision(type) - 1. */ (for cst (INTEGER_CST VECTOR_CST) (simplify diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr103218-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr103218-1.c new file mode 100644 index 00000000000..f086f073b38 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr103218-1.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* PR tree-optimization/103218 */ + +/* These first two are removed during forwprop1 */ +signed char f(signed char a) +{ + signed char t = a < 0; + int tt = (unsigned char)(t << 7); + return tt; +} +signed char f0(signed char a) +{ + unsigned char t = a < 0; + int tt = (unsigned char)(t << 7); + return tt; +} + +/* This one is removed during phiopt. */ +signed char f1(signed char a) +{ + if (a < 0) + return 1u<<7; + return 0; +} + +/* These three examples should remove "a < 0" by optimized. */ +/* { dg-final { scan-tree-dump-times "< 0" 0 "optimized"} } */ -- 2.17.1