From patchwork Wed Sep 20 13:09:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lehua Ding X-Patchwork-Id: 142401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp4128337vqi; Wed, 20 Sep 2023 06:10:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEisBx2+ByuGEuyyYr5rxAJRJiG4lroDiKsxiE5HMArIPvOzmsiTeG4avPLTb+yZBW3TOYd X-Received: by 2002:a5d:5951:0:b0:319:6ae0:cae5 with SMTP id e17-20020a5d5951000000b003196ae0cae5mr2286340wri.70.1695215428454; Wed, 20 Sep 2023 06:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695215428; cv=none; d=google.com; s=arc-20160816; b=kw4HCjfRY7UJSwD9TGsJQOHSrupOiIIDUfnCR9uAJO8Ea67gzVEZycaPTKQ/TGzud0 5QYo5t5SZpmadlLWZGKxsP8rKQEggrm1M3ClQgu0mEiJQuhXddlmqPU83ZnM0nPEoEX4 0o7pD5w8kTsvJtnnpBfmoBfrKk8nuvBlxWGee+hazX9WSu9KiivNgVfMREqbxPAmu+47 OcfdlXdnubZbqIT2i17wod6FtqrC54r49NdBG5+cnvxQO2aOctHLZ5acTRDBAZ8Xwiuu ciwts5RKx5n+m72niHVOsQ+zq5ORTAIMV3/6AB3799yG2ICkPEHOwiWdu865erYx4pBD Nt/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dmarc-filter:delivered-to; bh=A6mgVcX2UdkND8Nwu6QBKPY5YkhCe3K6BZQ47edhLy8=; fh=/Q2YGrMEfKEUg9MgQeu13McC5yOVFH9WmNaJ+T1TUSg=; b=JDQRq+PVeaBoFQVs7sBXgUblt7pybTGemIuw6+6gn+kmJWLGI79FvjNZDyNf7QvnPX aeEz3gmO0kkQFeP7srn8rQxEd4u3RZBG59Zys3ughfBM/c37hyvnfxUjPOzc2oSq7m59 v4o6Uwf4HPHnAHF4rhbpIzZfl/KGZhZTxwR0tPByq/wsBrryz/62gb9JYb3xl1+Gcklo yel4ekTF+GK4KA2tMOcm1qcm5fjixOGtGrsQ4ZaoPURR6qeKopZS1TPL6BkJlyT18Jw7 JamXJ9HdN2/8Md9Qr2p7lj+FHslu9weIvq9+BBpwyNUo1TmrdUmGZoRuys2LeyY/zyfu jm6A== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id oz11-20020a170906cd0b00b009a1f0917c26si11252803ejb.677.2023.09.20.06.10.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 06:10:28 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 949AB385DC3A for ; Wed, 20 Sep 2023 13:09:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgau2.qq.com (smtpbgau2.qq.com [54.206.34.216]) by sourceware.org (Postfix) with ESMTPS id A29393857835 for ; Wed, 20 Sep 2023 13:09:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A29393857835 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp72t1695215345tbpbpg5d Received: from rios-cad121.hadoop.rioslab.org ( [58.60.1.9]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 20 Sep 2023 21:09:04 +0800 (CST) X-QQ-SSF: 01400000000000C0F000000A0000000 X-QQ-FEAT: bFY/iyWr6UlVWyfisEMauADSc+UTx67lKWieTUdNBgDndtpGD1zqchgT7qEJU Pg1fnkrfDzsZVWodVHBdfJY7byZlb7mosIIpvYdKqCXaJT/Bmf8w61qu79bSWPszZNp5d46 Q168FxsakafFnPsV+TmQlFoeZ0d35EOxxpDLmREvM0uBH2/FCmzjc0aTCi/kZfvu/2oGsXF izu1DX82d/lHDR/KuHGebOOja4XKKNLi/BDtKo3bQWgrtfn8R+53GBbg6JA/OH1dchbF4DM SIFl03emDQvKHS5vizhwvB/XDdGfnE/yWo1hprrCIDUE/mWjAnEq1M/kNA2CdxDYOWhcGXg f7Or43g38mkW/c+r7QDZQ1TjXB4tKTAXU+E9gzWEz7CnitzfdLWm8IZR6XKlDXFIOTDzRJ+ X-QQ-GoodBg: 2 X-BIZMAIL-ID: 7082885150224705628 From: Lehua Ding To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Cc: richard.guenther@gmail.com, juzhe.zhong@rivai.ai, jeffreyalaw@gmail.com, lehua.ding@rivai.ai Subject: [PATCH 1/2] match.pd: Support combine cond_len_op + vec_cond similar to cond_op Date: Wed, 20 Sep 2023 21:09:04 +0800 Message-Id: <20230920130904.2329151-1-lehua.ding@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz6a-0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777562212750284254 X-GMAIL-MSGID: 1777562212750284254 This patch adds combine cond_len_op and vec_cond to cond_len_op like cond_op. gcc/ChangeLog: * gimple-match.h (gimple_match_op::gimple_match_op): Add interfaces for more arguments. (gimple_match_op::set_op): Add interfaces for more arguments. * match.pd: Add support of combining cond_len_op + vec_cond --- gcc/gimple-match.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++ gcc/match.pd | 39 +++++++++++++++++++++++++ 2 files changed, 111 insertions(+) diff --git a/gcc/gimple-match.h b/gcc/gimple-match.h index bec3ff42e3e..9892c142285 100644 --- a/gcc/gimple-match.h +++ b/gcc/gimple-match.h @@ -92,6 +92,10 @@ public: code_helper, tree, tree, tree, tree, tree); gimple_match_op (const gimple_match_cond &, code_helper, tree, tree, tree, tree, tree, tree); + gimple_match_op (const gimple_match_cond &, + code_helper, tree, tree, tree, tree, tree, tree, tree); + gimple_match_op (const gimple_match_cond &, + code_helper, tree, tree, tree, tree, tree, tree, tree, tree); void set_op (code_helper, tree, unsigned int); void set_op (code_helper, tree, tree); @@ -100,6 +104,8 @@ public: void set_op (code_helper, tree, tree, tree, tree, bool); void set_op (code_helper, tree, tree, tree, tree, tree); void set_op (code_helper, tree, tree, tree, tree, tree, tree); + void set_op (code_helper, tree, tree, tree, tree, tree, tree, tree); + void set_op (code_helper, tree, tree, tree, tree, tree, tree, tree, tree); void set_value (tree); tree op_or_null (unsigned int) const; @@ -212,6 +218,39 @@ gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in, ops[4] = op4; } +inline +gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in, + code_helper code_in, tree type_in, + tree op0, tree op1, tree op2, tree op3, + tree op4, tree op5) + : cond (cond_in), code (code_in), type (type_in), reverse (false), + num_ops (6) +{ + ops[0] = op0; + ops[1] = op1; + ops[2] = op2; + ops[3] = op3; + ops[4] = op4; + ops[5] = op5; +} + +inline +gimple_match_op::gimple_match_op (const gimple_match_cond &cond_in, + code_helper code_in, tree type_in, + tree op0, tree op1, tree op2, tree op3, + tree op4, tree op5, tree op6) + : cond (cond_in), code (code_in), type (type_in), reverse (false), + num_ops (7) +{ + ops[0] = op0; + ops[1] = op1; + ops[2] = op2; + ops[3] = op3; + ops[4] = op4; + ops[5] = op5; + ops[6] = op6; +} + /* Change the operation performed to CODE_IN, the type of the result to TYPE_IN, and the number of operands to NUM_OPS_IN. The caller needs to set the operands itself. */ @@ -299,6 +338,39 @@ gimple_match_op::set_op (code_helper code_in, tree type_in, ops[4] = op4; } +inline void +gimple_match_op::set_op (code_helper code_in, tree type_in, + tree op0, tree op1, tree op2, tree op3, tree op4, + tree op5) +{ + code = code_in; + type = type_in; + num_ops = 6; + ops[0] = op0; + ops[1] = op1; + ops[2] = op2; + ops[3] = op3; + ops[4] = op4; + ops[5] = op5; +} + +inline void +gimple_match_op::set_op (code_helper code_in, tree type_in, + tree op0, tree op1, tree op2, tree op3, tree op4, + tree op5, tree op6) +{ + code = code_in; + type = type_in; + num_ops = 7; + ops[0] = op0; + ops[1] = op1; + ops[2] = op2; + ops[3] = op3; + ops[4] = op4; + ops[5] = op5; + ops[6] = op6; +} + /* Set the "operation" to be the single value VALUE, such as a constant or SSA_NAME. */ diff --git a/gcc/match.pd b/gcc/match.pd index a37af05f873..75b7e100120 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -103,12 +103,22 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) IFN_COND_FMIN IFN_COND_FMAX IFN_COND_AND IFN_COND_IOR IFN_COND_XOR IFN_COND_SHL IFN_COND_SHR) +(define_operator_list COND_LEN_BINARY + IFN_COND_LEN_ADD IFN_COND_LEN_SUB + IFN_COND_LEN_MUL IFN_COND_LEN_DIV + IFN_COND_LEN_MOD IFN_COND_LEN_RDIV + IFN_COND_LEN_MIN IFN_COND_LEN_MAX + IFN_COND_LEN_FMIN IFN_COND_LEN_FMAX + IFN_COND_LEN_AND IFN_COND_LEN_IOR IFN_COND_LEN_XOR + IFN_COND_LEN_SHL IFN_COND_LEN_SHR) /* Same for ternary operations. */ (define_operator_list UNCOND_TERNARY IFN_FMA IFN_FMS IFN_FNMA IFN_FNMS) (define_operator_list COND_TERNARY IFN_COND_FMA IFN_COND_FMS IFN_COND_FNMA IFN_COND_FNMS) +(define_operator_list COND_LEN_TERNARY + IFN_COND_LEN_FMA IFN_COND_LEN_FMS IFN_COND_LEN_FNMA IFN_COND_LEN_FNMS) /* __atomic_fetch_or_*, __atomic_fetch_xor_*, __atomic_xor_fetch_* */ (define_operator_list ATOMIC_FETCH_OR_XOR_N @@ -8861,6 +8871,35 @@ and, && element_precision (type) == element_precision (op_type)) (view_convert (cond_op @2 @3 @4 @5 (view_convert:op_type @1))))))) +/* Detect cases in which a VEC_COND_EXPR effectively replaces the + "else" value of an IFN_COND_LEN_*. */ +(for cond_len_op (COND_LEN_BINARY) + (simplify + (vec_cond @0 (view_convert? (cond_len_op @0 @1 @2 @3 @4 @5)) @6) + (with { tree op_type = TREE_TYPE (@3); } + (if (element_precision (type) == element_precision (op_type)) + (view_convert (cond_len_op @0 @1 @2 (view_convert:op_type @6) @4 @5))))) + (simplify + (vec_cond @0 @1 (view_convert? (cond_len_op @2 @3 @4 @5 @6 @7))) + (with { tree op_type = TREE_TYPE (@5); } + (if (inverse_conditions_p (@0, @2) + && element_precision (type) == element_precision (op_type)) + (view_convert (cond_len_op @2 @3 @4 (view_convert:op_type @1) @6 @7)))))) + +/* Same for ternary operations. */ +(for cond_len_op (COND_LEN_TERNARY) + (simplify + (vec_cond @0 (view_convert? (cond_len_op @0 @1 @2 @3 @4 @5 @6)) @7) + (with { tree op_type = TREE_TYPE (@4); } + (if (element_precision (type) == element_precision (op_type)) + (view_convert (cond_len_op @0 @1 @2 @3 (view_convert:op_type @7) @5 @6))))) + (simplify + (vec_cond @0 @1 (view_convert? (cond_len_op @2 @3 @4 @5 @6 @7 @8))) + (with { tree op_type = TREE_TYPE (@6); } + (if (inverse_conditions_p (@0, @2) + && element_precision (type) == element_precision (op_type)) + (view_convert (cond_len_op @2 @3 @4 @5 (view_convert:op_type @1) @7 @8)))))) + /* Detect simplication for a conditional reduction where a = mask1 ? b : 0