From patchwork Fri Jun 21 07:09:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eikansh Gupta X-Patchwork-Id: 1950564 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=KsJuVqr3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W57pJ1MhBz20X4 for ; Fri, 21 Jun 2024 17:12:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 758823896C1E for ; Fri, 21 Jun 2024 07:12:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by sourceware.org (Postfix) with ESMTPS id A68543896C27 for ; Fri, 21 Jun 2024 07:10:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A68543896C27 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A68543896C27 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718953862; cv=none; b=tx2I2Wc1gX2qFA42+bdNCURnqG3ArGcXYfkWklOZGSqCD00MUarJ3RgTbMgRDr2K6dWpayl7jZPQyZubCmmP+1Bnc+HzZHPUT25Vn6x5SW6i86K88R+3Of6melrruk405pXYbf8OwefHVRwPUpYrLKLpYF4496g6OC7QiYLRMlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718953862; c=relaxed/simple; bh=0o1ESdD9sUxDdvfBjOxHzo5Mw5cyfJBqhpxj8gOiSbw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=p3YdWhKI/dL1TKcfIvhbAExLyd4D1ZvS20IZO7JUo/rwl9AYwGnV+diIuOzXJuBbUnuYmuRLFjArk7Alk15Da3UBKGh9uL054wr6BpqaMn5OhmPigWli0DJy/7ffVQl1zlZosE3DL41r9F7O/bVlu9lt60yM1IsCEUkLzhAEwlg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45L6ENHu010564 for ; Fri, 21 Jun 2024 07:10:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-type:date:from:message-id:mime-version:subject:to; s= qcppdkim1; bh=TphtGSQYDUbJCqxwVbyLTh0FICzq5Tvkd6aaqyxWYuw=; b=Ks JuVqr3CsMYmvP+PrRxQwOF6bnLrOXiM5e/nH/vahDL+XRCT/wuYAo8Vx2s0ff/Y8 6FkHQCoKMuLd/sr6i2XAwgdRE35r/VttjmNAnIlQ5SwOfKoykPhAd0Ii3glJ1ATQ G3XPSygnUze9mmRA6qTdYO8/y24vXxLv3j1ndVbJGTY/w7h4AgwuiCBlEePmM9ps v6XBPuh81mxdrBMlkmDq4pIYA2sVDJvMdz7/nDHeHxSniYwMBHnnhL6LkLR0vMib Fu57fOdmvRriztv1Bu5vzgZTAHXcByjdWd14wqEWymECPbKV9mIdjoe9OVw9CMLG hOZu8y2yULsW/8Qdp/LQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yvrrc9r65-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jun 2024 07:10:57 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 45L7Auko028646 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jun 2024 07:10:56 GMT Received: from hu-eikagupt-hyd.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Fri, 21 Jun 2024 00:10:55 -0700 From: Eikansh Gupta To: CC: Eikansh Gupta Subject: [PATCH] MATCH: Simplify (vec CMP vec) eq/ne (vec CMP vec) [PR111150] Date: Fri, 21 Jun 2024 12:39:42 +0530 Message-ID: <20240621070942.16086-1-quic_eikagupt@quicinc.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: RHLxaFh09M6D4k8Gd2EuU-Ympfv1FcmE X-Proofpoint-ORIG-GUID: RHLxaFh09M6D4k8Gd2EuU-Ympfv1FcmE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-21_01,2024-06-20_04,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 mlxlogscore=839 spamscore=0 lowpriorityscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 suspectscore=0 malwarescore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406210052 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org We can optimize (vec_cond eq/ne vec_cond) when vec_cond is a result of (vec CMP vec). The optimization is because of the observation that in vec_cond, (-1 != 0) is true. So, we can generate vec_cond of xor of vec resulting in a single VEC_COND_EXPR instead of 3. The patch adds match pattern for vec a, b: (a ? -1 : 0) != (b ? -1 : 0) --> (a^b) ? -1 : 0 (a ? -1 : 0) == (b ? -1 : 0) --> ~(a^b) ? -1 : 0 PR tree-optimization/111150 gcc/ChangeLog: * match.pd: Optimization for above mentioned pattern. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr111150.c: New test. Signed-off-by: Eikansh Gupta --- gcc/match.pd | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr111150.c | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr111150.c diff --git a/gcc/match.pd b/gcc/match.pd index 3d0689c9312..5cb78bd7ff9 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -5522,6 +5522,24 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (vec_cond (bit_and (bit_not @0) @1) @2 @3))) #endif +/* (a ? -1 : 0) != (b ? -1 : 0) --> (a^b) ? -1 : 0 */ +/* (a ? -1 : 0) == (b ? -1 : 0) --> ~(a^b) ? -1 : 0 */ +(for eqne (eq ne) + (simplify + (eqne:c (vec_cond @0 uniform_integer_cst_p@2 uniform_integer_cst_p@3) + (vec_cond @1 @2 @3)) + (with + { + tree newop1 = @2; + tree newop2 = @3; + if (eqne == NE_EXPR) + std::swap (newop1, newop2); + } + (if (integer_all_onesp (@2) && integer_zerop (@3)) + (vec_cond (bit_xor @0 @1) {newop1;} {newop2;}) + (if (integer_all_onesp (@3) && integer_zerop (@2)) + (vec_cond (bit_xor @0 @1) {newop2;} {newop1;})))))) + /* Canonicalize mask ? { 0, ... } : { -1, ...} to ~mask if the mask types are compatible. */ (simplify diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111150.c b/gcc/testsuite/gcc.dg/tree-ssa/pr111150.c new file mode 100644 index 00000000000..d10564fd722 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr111150.c @@ -0,0 +1,19 @@ +/* PR tree-optimization/111150 */ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop1" } */ + +typedef int v4si __attribute((__vector_size__(4 * sizeof(int)))); + +v4si f1_(v4si a, v4si b, v4si c, v4si d) { + v4si X = a == b; + v4si Y = c == d; + return (X != Y); +} + +v4si f2_(v4si a, v4si b, v4si c, v4si d) { + v4si X = a == b; + v4si Y = c == d; + return (X == Y); +} + +/* { dg-final { scan-tree-dump-times " VEC_COND_EXPR " 2 "forwprop1" } } */