From patchwork Thu Sep 14 17:48:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 139753 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp519839vqi; Thu, 14 Sep 2023 10:49:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvMzqkCCVnli6pl06RWvHZ+nESfuTB9WTSfe9PxXJMKXuqa4HYsanmDjAtjavasGr7g1uW X-Received: by 2002:a05:6402:1355:b0:522:b929:9f01 with SMTP id y21-20020a056402135500b00522b9299f01mr5234476edw.9.1694713794305; Thu, 14 Sep 2023 10:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694713794; cv=none; d=google.com; s=arc-20160816; b=uyw45M23TiOHt4d6VHynFRJIC271CFR0SGwIsax/FZxJEEWNF0zkzDvszJpCh8T4/7 3jgCjg7Hh3X/Nj/d1qCECDwxinyVt6n9yHdhJjOocM81u4p7JKnCO9dYUjiWy01aKpoE 7fJj17sXpt2p60L3DtvlD3BWje2im3RxhfDy0abxZcyoOIbcvQv7cBxWV0zonxBGNOLX QmYmBO9c4MUO2Ge7GCkOy3Nz7SrSfeqXRN6/P0cYv1AOayLWSQo0D3xOMxMTohCqp8SG nVN73EwztziOIiBLgdhEyaVNEehZuo9ckCNGSB/zIFwi0U9ed0sDmnxOElSLa49sp2mp 2b3w== 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=Qvd6AttmySmjiPz/VNj//CQcqC5xYYCWrHWtVUwyhco=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=PIV/oIgs0cvcQk2Ae7d3YICISfTPF+vbi/HhwwwH+u5VAQsDynNss6UMxa5M9/6bKx d8WIY2NcUTKMEwd9cYP94vX8uZ5Fpyqgzsxp2iVGzkVrSorPWBsHvOWUd+uUENbNUTgz KP/nHyKKGop+U/aFZi1dBzU9PJdJTMpFQXARuJdJoXAit8J87vggi5jDFfOimUUbcIve yDgFdnTkqvrsrrGUVZBXrhnDMTfr3DJjeOCZZF0MllrMrxbiQku8B82ZmTcnaKIIxL7z YCTk45ips08qzfh1ZBgKVCgd/jD4wgSK6mIHBp2GQUqM2VE8ztrpAi7Q3XqynEcpMh5A mRaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dphOPwJJ; 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 d6-20020a056402078600b00523ccc09db8si1785900edy.272.2023.09.14.10.49.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 10:49:54 -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=dphOPwJJ; 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 DCB633856954 for ; Thu, 14 Sep 2023 17:49:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DCB633856954 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694713785; bh=Qvd6AttmySmjiPz/VNj//CQcqC5xYYCWrHWtVUwyhco=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=dphOPwJJcvVi0YoqGzu6iLgui8uc504xuUnaOrN3PY6zVp0AxOx+CV72npLZoAb1m CmIZ63zfu+sONnvNXQIBYBNJxDVnT7V3TYatg4OCiTC1CIpgO/2DV7VeEPYQ3jtzQI tKy2eBFYrwz+s3+VgwmtOhh6aTPjVjzDXo9GXgag= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id D013C3858CDA for ; Thu, 14 Sep 2023 17:48:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D013C3858CDA Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38EE4DMX008646 for ; Thu, 14 Sep 2023 10:48:57 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3t3kqrmha9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 14 Sep 2023 10:48:57 -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; Thu, 14 Sep 2023 10:48:55 -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; Thu, 14 Sep 2023 10:48:55 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 0CF663F7053; Thu, 14 Sep 2023 10:48:54 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Fix `(1 >> X) != 0` pattern for vector types Date: Thu, 14 Sep 2023 10:48:47 -0700 Message-ID: <20230914174847.1564836-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: hoQC6CCXUMLVqwaKjkKfPs_EdZCRpR57 X-Proofpoint-GUID: hoQC6CCXUMLVqwaKjkKfPs_EdZCRpR57 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-14_09,2023-09-14_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.30 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: 1777036211621369686 X-GMAIL-MSGID: 1777036211621369686 I had missed that integer_onep can match vector types with uniform constant of `1`. This means the shifter could be an scalar type and then doing a comparison against `0` would be an invalid transformation. This fixes the problem by adding a check for the type of the integer_onep to make sure it is a INTEGRAL_TYPE_P (which does not match a vector type). OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/111414 gcc/ChangeLog: * match.pd (`(1 >> X) != 0`): Check to see if the integer_onep was an integral type (not a vector type). gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr111414-1.c: New test. --- gcc/match.pd | 5 +++-- gcc/testsuite/gcc.c-torture/compile/pr111414-1.c | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr111414-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 07ffd831132..97db0eb5f25 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4206,8 +4206,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* `(1 >> X) != 0` -> `X == 0` */ /* `(1 >> X) == 0` -> `X != 0` */ (simplify - (cmp (rshift integer_onep @0) integer_zerop) - (icmp @0 { build_zero_cst (TREE_TYPE (@0)); }))) + (cmp (rshift integer_onep@1 @0) integer_zerop) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@1))) + (icmp @0 { build_zero_cst (TREE_TYPE (@0)); })))) /* (CST1 << A) == CST2 -> A == ctz (CST2) - ctz (CST1) (CST1 << A) != CST2 -> A != ctz (CST2) - ctz (CST1) diff --git a/gcc/testsuite/gcc.c-torture/compile/pr111414-1.c b/gcc/testsuite/gcc.c-torture/compile/pr111414-1.c new file mode 100644 index 00000000000..13fbdae7230 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr111414-1.c @@ -0,0 +1,13 @@ +int a, b, c, d, e, f, g; +int h(int i) { return b >= 2 ?: i >> b; } +void j() { + int k; + int *l = &c; + for (; d; d++) { + g = h(0 != j); + f = g >> a; + k = f << 7; + e = k > 5 ? k : 0; + *l ^= e; + } +}