From patchwork Fri Sep 17 05:25:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xionghu Luo X-Patchwork-Id: 45113 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82C05385841D for ; Fri, 17 Sep 2021 05:27:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82C05385841D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631856475; bh=sZtADC0xnjx7tqj4lBSyiQJM1Lqm7wOijxnqKSGhM4k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wR5fqw0zdCLMps6gEIGBCUzSVrRpnKMHaD90fJQjr9lfyZDIVDY+t7agc0YqQwaof e2GP/7BPATL3A0zKRb+W5QcqioMxSU6zaI2KcQx1bObiqQy9oRVAlb01nIro6QPt9Z 6Iq0LmddtA0NwBrpovVr13sEQQZlwQpWEpQndnbI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id B9499385742E; Fri, 17 Sep 2021 05:25:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B9499385742E Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18H4Msei028304; Fri, 17 Sep 2021 01:25:20 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3b4g674ef3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Sep 2021 01:25:20 -0400 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 18H4YBB0023261; Fri, 17 Sep 2021 01:25:19 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 3b4g674eem-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Sep 2021 01:25:19 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 18H5N1Wg009588; Fri, 17 Sep 2021 05:25:17 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 3b0m3asej1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Sep 2021 05:25:17 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 18H5PDLi43843906 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Sep 2021 05:25:13 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 12571A405C; Fri, 17 Sep 2021 05:25:13 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D1B78A4066; Fri, 17 Sep 2021 05:25:11 +0000 (GMT) Received: from genoa.aus.stglabs.ibm.com (unknown [9.40.192.157]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 17 Sep 2021 05:25:11 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH v2 1/2] rs6000: Fix wrong code generation for vec_sel [PR94613] Date: Fri, 17 Sep 2021 00:25:04 -0500 Message-Id: <20210917052505.2469224-2-luoxhu@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052505.2469224-1-luoxhu@linux.ibm.com> References: <20210917052505.2469224-1-luoxhu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: YwLSrrPzBIGfXgLT9ASQUhUmcMhQdlm3 X-Proofpoint-GUID: JynWYaBIn65pUSuVYs_D0XatklLUyibP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-09-17_02,2021-09-16_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 mlxscore=0 mlxlogscore=999 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109170032 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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-Patchwork-Original-From: Xionghu Luo via Gcc-patches From: Xionghu Luo Reply-To: Xionghu Luo Cc: segher@kernel.crashing.org, Xionghu Luo , wschmidt@linux.ibm.com, linkw@gcc.gnu.org, dje.gcc@gmail.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The vsel instruction is a bit-wise select instruction. Using an IF_THEN_ELSE to express it in RTL is wrong and leads to wrong code being generated in the combine pass. Per element selection is a subset of per bit-wise selection,with the patch the pattern is written using bit operations. But there are 8 different patterns to define "op0 := (op1 & ~op3) | (op2 & op3)": (~op3&op1) | (op3&op2), (~op3&op1) | (op2&op3), (op3&op2) | (~op3&op1), (op2&op3) | (~op3&op1), (op1&~op3) | (op3&op2), (op1&~op3) | (op2&op3), (op3&op2) | (op1&~op3), (op2&op3) | (op1&~op3), The latter 4 cases does not follow canonicalisation rules, non-canonical RTL is invalid RTL in vregs pass. Secondly, combine pass will swap (op1&~op3) to (~op3&op1) by commutative canonical, which could reduce it to the FIRST 4 patterns, but it won't swap (op2&op3) | (~op3&op1) to (~op3&op1) | (op2&op3), so this patch handles it with 4 patterns with different NOT op3 position and check equality inside it. Tested pass on Power8LE, any comments? gcc/ChangeLog: 2021-09-17 Xionghu Luo * config/rs6000/altivec.md (*altivec_vsel): Change to ... (altivec_vsel): ... this and update define. (*altivec_vsel_uns): Delete. (altivec_vsel2): New define_insn. (altivec_vsel3): Likewise. (altivec_vsel4): Likewise. * config/rs6000/rs6000-call.c (altivec_expand_vec_sel_builtin): New. (altivec_expand_builtin): Call altivec_expand_vec_sel_builtin to expand vel_sel. * config/rs6000/rs6000.c (rs6000_emit_vector_cond_expr): Use bit-wise selection instead of per element. * config/rs6000/vector.md: * config/rs6000/vsx.md (*vsx_xxsel): Change to ... (vsx_xxsel): ... this and update define. (*vsx_xxsel_uns): Delete. (vsx_xxsel2): New define_insn. (vsx_xxsel3): Likewise. (vsx_xxsel4): Likewise. gcc/testsuite/ChangeLog: 2021-09-17 Xionghu Luo * gcc.target/powerpc/pr94613.c: New test. --- gcc/config/rs6000/altivec.md | 62 ++++++++++++++++------ gcc/config/rs6000/rs6000-call.c | 62 ++++++++++++++++++++++ gcc/config/rs6000/rs6000.c | 19 +++---- gcc/config/rs6000/vector.md | 26 +++++---- gcc/config/rs6000/vsx.md | 60 ++++++++++++++++----- gcc/testsuite/gcc.target/powerpc/pr94613.c | 47 ++++++++++++++++ 6 files changed, 221 insertions(+), 55 deletions(-) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr94613.c diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md index 93d237156d5..a3424e1a458 100644 --- a/gcc/config/rs6000/altivec.md +++ b/gcc/config/rs6000/altivec.md @@ -683,26 +683,56 @@ (define_insn "*altivec_gev4sf" "vcmpgefp %0,%1,%2" [(set_attr "type" "veccmp")]) -(define_insn "*altivec_vsel" +(define_insn "altivec_vsel" [(set (match_operand:VM 0 "altivec_register_operand" "=v") - (if_then_else:VM - (ne:CC (match_operand:VM 1 "altivec_register_operand" "v") - (match_operand:VM 4 "zero_constant" "")) - (match_operand:VM 2 "altivec_register_operand" "v") - (match_operand:VM 3 "altivec_register_operand" "v")))] - "VECTOR_MEM_ALTIVEC_P (mode)" - "vsel %0,%3,%2,%1" + (ior:VM + (and:VM + (not:VM (match_operand:VM 3 "altivec_register_operand" "v")) + (match_operand:VM 1 "altivec_register_operand" "v")) + (and:VM + (match_dup 3) + (match_operand:VM 2 "altivec_register_operand" "v"))))] + "VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)" + "vsel %0,%1,%2,%3" [(set_attr "type" "vecmove")]) -(define_insn "*altivec_vsel_uns" +(define_insn "altivec_vsel2" [(set (match_operand:VM 0 "altivec_register_operand" "=v") - (if_then_else:VM - (ne:CCUNS (match_operand:VM 1 "altivec_register_operand" "v") - (match_operand:VM 4 "zero_constant" "")) - (match_operand:VM 2 "altivec_register_operand" "v") - (match_operand:VM 3 "altivec_register_operand" "v")))] - "VECTOR_MEM_ALTIVEC_P (mode)" - "vsel %0,%3,%2,%1" + (ior:VM + (and:VM + (not:VM (match_operand:VM 3 "altivec_register_operand" "v")) + (match_operand:VM 1 "altivec_register_operand" "v")) + (and:VM + (match_operand:VM 2 "altivec_register_operand" "v") + (match_dup 3))))] + "VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)" + "vsel %0,%1,%2,%3" + [(set_attr "type" "vecmove")]) + +(define_insn "altivec_vsel3" + [(set (match_operand:VM 0 "altivec_register_operand" "=v") + (ior:VM + (and:VM + (match_operand:VM 3 "altivec_register_operand" "v") + (match_operand:VM 1 "altivec_register_operand" "v")) + (and:VM + (not:VM (match_dup 3)) + (match_operand:VM 2 "altivec_register_operand" "v"))))] + "VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)" + "vsel %0,%2,%1,%3" + [(set_attr "type" "vecmove")]) + +(define_insn "altivec_vsel4" + [(set (match_operand:VM 0 "altivec_register_operand" "=v") + (ior:VM + (and:VM + (match_operand:VM 1 "altivec_register_operand" "v") + (match_operand:VM 3 "altivec_register_operand" "v")) + (and:VM + (not:VM (match_dup 3)) + (match_operand:VM 2 "altivec_register_operand" "v"))))] + "VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)" + "vsel %0,%2,%1,%3" [(set_attr "type" "vecmove")]) ;; Fused multiply add. diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c index e8625d17d18..cddfa76e7cb 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -11109,6 +11109,45 @@ altivec_expand_vec_ext_builtin (tree exp, rtx target) return target; } +/* Expand vec_sel builtin. */ +static rtx +altivec_expand_vec_sel_builtin (enum insn_code icode, tree exp, rtx target) +{ + rtx op0, op1, op2, pat; + tree arg0, arg1, arg2; + + arg0 = CALL_EXPR_ARG (exp, 0); + op0 = expand_normal (arg0); + arg1 = CALL_EXPR_ARG (exp, 1); + op1 = expand_normal (arg1); + arg2 = CALL_EXPR_ARG (exp, 2); + op2 = expand_normal (arg2); + + machine_mode tmode = insn_data[icode].operand[0].mode; + machine_mode mode0 = insn_data[icode].operand[1].mode; + machine_mode mode1 = insn_data[icode].operand[2].mode; + machine_mode mode2 = insn_data[icode].operand[3].mode; + + if (target == 0 || GET_MODE (target) != tmode + || !(*insn_data[icode].operand[0].predicate) (target, tmode)) + target = gen_reg_rtx (tmode); + + if (!(*insn_data[icode].operand[1].predicate) (op0, mode0)) + op0 = copy_to_mode_reg (mode0, op0); + if (!(*insn_data[icode].operand[2].predicate) (op1, mode1)) + op1 = copy_to_mode_reg (mode1, op1); + if (!(*insn_data[icode].operand[3].predicate) (op2, mode2)) + op2 = copy_to_mode_reg (mode2, op2); + + pat = GEN_FCN (icode) (target, op0, op1, op2, op2); + if (pat) + emit_insn (pat); + else + return NULL_RTX; + + return target; +} + /* Expand the builtin in EXP and store the result in TARGET. Store true in *EXPANDEDP if we found a builtin to expand. */ static rtx @@ -11294,6 +11333,29 @@ altivec_expand_builtin (tree exp, rtx target, bool *expandedp) emit_insn (pat); return NULL_RTX; + case ALTIVEC_BUILTIN_VSEL_2DF: + return altivec_expand_vec_sel_builtin (CODE_FOR_altivec_vselv2df, exp, + target); + case ALTIVEC_BUILTIN_VSEL_2DI: + case ALTIVEC_BUILTIN_VSEL_2DI_UNS: + return altivec_expand_vec_sel_builtin (CODE_FOR_altivec_vselv2di, exp, + target); + case ALTIVEC_BUILTIN_VSEL_4SF: + return altivec_expand_vec_sel_builtin (CODE_FOR_altivec_vselv4sf, exp, + target); + case ALTIVEC_BUILTIN_VSEL_4SI: + case ALTIVEC_BUILTIN_VSEL_4SI_UNS: + return altivec_expand_vec_sel_builtin (CODE_FOR_altivec_vselv4si, exp, + target); + case ALTIVEC_BUILTIN_VSEL_8HI: + case ALTIVEC_BUILTIN_VSEL_8HI_UNS: + return altivec_expand_vec_sel_builtin (CODE_FOR_altivec_vselv8hi, exp, + target); + case ALTIVEC_BUILTIN_VSEL_16QI: + case ALTIVEC_BUILTIN_VSEL_16QI_UNS: + return altivec_expand_vec_sel_builtin (CODE_FOR_altivec_vselv16qi, exp, + target); + case ALTIVEC_BUILTIN_DSSALL: emit_insn (gen_altivec_dssall ()); return NULL_RTX; diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index ad81dfb316d..c9ce0550df1 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -15785,9 +15785,7 @@ rs6000_emit_vector_cond_expr (rtx dest, rtx op_true, rtx op_false, machine_mode dest_mode = GET_MODE (dest); machine_mode mask_mode = GET_MODE (cc_op0); enum rtx_code rcode = GET_CODE (cond); - machine_mode cc_mode = CCmode; rtx mask; - rtx cond2; bool invert_move = false; if (VECTOR_UNIT_NONE_P (dest_mode)) @@ -15827,8 +15825,6 @@ rs6000_emit_vector_cond_expr (rtx dest, rtx op_true, rtx op_false, case GEU: case LTU: case LEU: - /* Mark unsigned tests with CCUNSmode. */ - cc_mode = CCUNSmode; /* Invert condition to avoid compound test if necessary. */ if (rcode == GEU || rcode == LEU) @@ -15848,6 +15844,9 @@ rs6000_emit_vector_cond_expr (rtx dest, rtx op_true, rtx op_false, if (!mask) return 0; + if (mask_mode != dest_mode) + mask = simplify_gen_subreg (dest_mode, mask, mask_mode, 0); + if (invert_move) std::swap (op_true, op_false); @@ -15887,13 +15886,11 @@ rs6000_emit_vector_cond_expr (rtx dest, rtx op_true, rtx op_false, if (!REG_P (op_false) && !SUBREG_P (op_false)) op_false = force_reg (dest_mode, op_false); - cond2 = gen_rtx_fmt_ee (NE, cc_mode, gen_lowpart (dest_mode, mask), - CONST0_RTX (dest_mode)); - emit_insn (gen_rtx_SET (dest, - gen_rtx_IF_THEN_ELSE (dest_mode, - cond2, - op_true, - op_false))); + rtx tmp = gen_rtx_IOR (dest_mode, + gen_rtx_AND (dest_mode, gen_rtx_NOT (dest_mode, mask), + op_false), + gen_rtx_AND (dest_mode, mask, op_true)); + emit_insn (gen_rtx_SET (dest, tmp)); return 1; } diff --git a/gcc/config/rs6000/vector.md b/gcc/config/rs6000/vector.md index 7e36c788b97..062aef70f2b 100644 --- a/gcc/config/rs6000/vector.md +++ b/gcc/config/rs6000/vector.md @@ -916,23 +916,21 @@ (define_insn_and_split "vector_" ;; which is in the reverse order that we want (define_expand "vector_select_" [(set (match_operand:VEC_L 0 "vlogical_operand") - (if_then_else:VEC_L - (ne:CC (match_operand:VEC_L 3 "vlogical_operand") - (match_dup 4)) - (match_operand:VEC_L 2 "vlogical_operand") - (match_operand:VEC_L 1 "vlogical_operand")))] - "VECTOR_UNIT_ALTIVEC_OR_VSX_P (mode)" - "operands[4] = CONST0_RTX (mode);") + (ior:VEC_L + (and:VEC_L (not:VEC_L (match_operand:VEC_L 3 "vlogical_operand")) + (match_operand:VEC_L 1 "vlogical_operand")) + (and:VEC_L (match_dup 3) + (match_operand:VEC_L 2 "vlogical_operand"))))] + "VECTOR_UNIT_ALTIVEC_OR_VSX_P (mode)") (define_expand "vector_select__uns" [(set (match_operand:VEC_L 0 "vlogical_operand") - (if_then_else:VEC_L - (ne:CCUNS (match_operand:VEC_L 3 "vlogical_operand") - (match_dup 4)) - (match_operand:VEC_L 2 "vlogical_operand") - (match_operand:VEC_L 1 "vlogical_operand")))] - "VECTOR_UNIT_ALTIVEC_OR_VSX_P (mode)" - "operands[4] = CONST0_RTX (mode);") + (ior:VEC_L + (and:VEC_L (not:VEC_L (match_operand:VEC_L 3 "vlogical_operand")) + (match_operand:VEC_L 1 "vlogical_operand")) + (and:VEC_L (match_dup 3) + (match_operand:VEC_L 2 "vlogical_operand"))))] + "VECTOR_UNIT_ALTIVEC_OR_VSX_P (mode)") ;; Expansions that compare vectors producing a vector result and a predicate, ;; setting CR6 to indicate a combined status diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md index bf033e31c1c..601eb81e316 100644 --- a/gcc/config/rs6000/vsx.md +++ b/gcc/config/rs6000/vsx.md @@ -2185,30 +2185,62 @@ (define_insn "*vsx_ge__p" [(set_attr "type" "")]) ;; Vector select -(define_insn "*vsx_xxsel" +(define_insn "vsx_xxsel" [(set (match_operand:VSX_L 0 "vsx_register_operand" "=,?wa") - (if_then_else:VSX_L - (ne:CC (match_operand:VSX_L 1 "vsx_register_operand" ",wa") - (match_operand:VSX_L 4 "zero_constant" "")) - (match_operand:VSX_L 2 "vsx_register_operand" ",wa") - (match_operand:VSX_L 3 "vsx_register_operand" ",wa")))] + (ior:VSX_L + (and:VSX_L + (not:VSX_L (match_operand:VSX_L 3 "vsx_register_operand" ",wa")) + (match_operand:VSX_L 1 "vsx_register_operand" ",wa")) + (and:VSX_L + (match_dup 3) + (match_operand:VSX_L 2 "vsx_register_operand" ",wa"))))] "VECTOR_MEM_VSX_P (mode)" - "xxsel %x0,%x3,%x2,%x1" + "xxsel %x0,%x1,%x2,%x3" [(set_attr "type" "vecmove") (set_attr "isa" "")]) -(define_insn "*vsx_xxsel_uns" +(define_insn "vsx_xxsel2" [(set (match_operand:VSX_L 0 "vsx_register_operand" "=,?wa") - (if_then_else:VSX_L - (ne:CCUNS (match_operand:VSX_L 1 "vsx_register_operand" ",wa") - (match_operand:VSX_L 4 "zero_constant" "")) - (match_operand:VSX_L 2 "vsx_register_operand" ",wa") - (match_operand:VSX_L 3 "vsx_register_operand" ",wa")))] + (ior:VSX_L + (and:VSX_L + (not:VSX_L (match_operand:VSX_L 3 "vsx_register_operand" ",wa")) + (match_operand:VSX_L 1 "vsx_register_operand" ",wa")) + (and:VSX_L + (match_operand:VSX_L 2 "vsx_register_operand" ",wa") + (match_dup 3))))] "VECTOR_MEM_VSX_P (mode)" - "xxsel %x0,%x3,%x2,%x1" + "xxsel %x0,%x1,%x2,%x3" [(set_attr "type" "vecmove") (set_attr "isa" "")]) +(define_insn "vsx_xxsel3" + [(set (match_operand:VSX_L 0 "vsx_register_operand" "=,?wa") + (ior:VSX_L + (and:VSX_L + (match_operand:VSX_L 3 "vsx_register_operand" ",wa") + (match_operand:VSX_L 1 "vsx_register_operand" ",wa")) + (and:VSX_L + (not:VSX_L (match_dup 3)) + (match_operand:VSX_L 2 "vsx_register_operand" ",wa"))))] + "VECTOR_MEM_VSX_P (mode)" + "xxsel %x0,%x2,%x1,%x3" + [(set_attr "type" "vecmove") + (set_attr "isa" "")]) + +(define_insn "vsx_xxsel4" + [(set (match_operand:VSX_L 0 "vsx_register_operand" "=,?wa") + (ior:VSX_L + (and:VSX_L + (match_operand:VSX_L 1 "vsx_register_operand" ",wa") + (match_operand:VSX_L 3 "vsx_register_operand" ",wa")) + (and:VSX_L + (not:VSX_L (match_dup 3)) + (match_operand:VSX_L 2 "vsx_register_operand" ",wa"))))] + "VECTOR_MEM_VSX_P (mode)" + "xxsel %x0,%x2,%x1,%x3" + [(set_attr "type" "vecmove") + (set_attr "isa" "")]) + ;; Copy sign (define_insn "vsx_copysign3" [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa") diff --git a/gcc/testsuite/gcc.target/powerpc/pr94613.c b/gcc/testsuite/gcc.target/powerpc/pr94613.c new file mode 100644 index 00000000000..13cab13cb83 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr94613.c @@ -0,0 +1,47 @@ +/* { dg-do run } */ +/* { dg-require-effective-target vmx_hw } */ +/* { dg-options "-O2 -maltivec" } */ + +#include + +/* The initial implementation of vec_sel used an IF_THEN_ELSE rtx. + This did NOT match what the vsel instruction does. vsel is a + bit-wise operation. Using IF_THEN_ELSE made the + operation to be + simplified away in combine. A plus operation affects other bits in + the same element. Hence per-element simplifications are wrong for + vsel. */ +vector unsigned char __attribute__((noinline)) +foo (vector unsigned char a, vector unsigned char b, vector unsigned char c) +{ + return vec_sel (a + b, c, a); +} + +vector unsigned char __attribute__((noinline)) +foor (vector unsigned char a, vector unsigned char b, vector unsigned char c) +{ + return vec_sel (c, a + b, ~a); +} + +vector unsigned char __attribute__((noinline)) +bar (vector unsigned char a, vector unsigned char b, vector unsigned char c) +{ + return vec_sel (a | b, c, a); +} + +int +main () +{ + vector unsigned char v = (vector unsigned char){ 1 }; + + if (foo (v, v, v)[0] != 3) + __builtin_abort (); + + if (bar (v, v, v)[0] != 1) + __builtin_abort (); + + if (foor (v, v, v)[0] != 3) + __builtin_abort (); + + return 0; +} + From patchwork Fri Sep 17 05:25:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xionghu Luo X-Patchwork-Id: 45111 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DFFE33857415 for ; Fri, 17 Sep 2021 05:26:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFFE33857415 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631856361; bh=+4t5XUd6f50e1dPqWSH8En8PgFJV94hCslsXKxJHxxQ=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wOigUbFo9bBxRP1NqAFAYTs8i1QB1A5IXf8z0XeExe13bnR64vX0dh2qRWSyz4JIF ctA2TghwJqq3SQD3b4dUfEp3QAM3dHNEZL1C1Zxj2TNTK2flTcBFqBxDo9o9qN1ZRa NoNesL6hD0gKQt4riiF1kFUHTsjII4VhPyIuY7Bw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 49CF93857437; Fri, 17 Sep 2021 05:25:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 49CF93857437 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18H4YESk012867; Fri, 17 Sep 2021 01:25:21 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3b4g6ecdvt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Sep 2021 01:25:20 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 18H52PLE021486; Fri, 17 Sep 2021 01:25:20 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 3b4g6ecduy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Sep 2021 01:25:20 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 18H5Mfkh018321; Fri, 17 Sep 2021 05:25:18 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03fra.de.ibm.com with ESMTP id 3b0m3a7ff5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Sep 2021 05:25:18 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 18H5PEed47382880 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Sep 2021 05:25:15 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 96E81A4071; Fri, 17 Sep 2021 05:25:14 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 64E0FA405F; Fri, 17 Sep 2021 05:25:13 +0000 (GMT) Received: from genoa.aus.stglabs.ibm.com (unknown [9.40.192.157]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 17 Sep 2021 05:25:13 +0000 (GMT) To: gcc-patches@gcc.gnu.org Subject: [PATCH v2 2/2] rs6000: Fold xxsel to vsel since they have same semantics Date: Fri, 17 Sep 2021 00:25:05 -0500 Message-Id: <20210917052505.2469224-3-luoxhu@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917052505.2469224-1-luoxhu@linux.ibm.com> References: <20210917052505.2469224-1-luoxhu@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: PnvoGlqKtuygqC8ISb9gQnvOI5JRUiOe X-Proofpoint-ORIG-GUID: 1R75z83Zxt5c1lxst8UP3QZ0kgLXRH32 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-09-17_02,2021-09-16_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 mlxlogscore=977 bulkscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 impostorscore=0 malwarescore=0 priorityscore=1501 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109170032 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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-Patchwork-Original-From: Xionghu Luo via Gcc-patches From: Xionghu Luo Reply-To: Xionghu Luo Cc: segher@kernel.crashing.org, Xionghu Luo , wschmidt@linux.ibm.com, linkw@gcc.gnu.org, dje.gcc@gmail.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Fold xxsel to vsel like xxperm/vperm to avoid duplicate code. gcc/ChangeLog: 2021-09-17 Xionghu Luo * config/rs6000/altivec.md: Add vsx register constraints. * config/rs6000/vsx.md (vsx_xxsel): Delete. (vsx_xxsel2): Likewise. (vsx_xxsel3): Likewise. (vsx_xxsel4): Likewise. --- gcc/config/rs6000/altivec.md | 60 +++++++++++-------- gcc/config/rs6000/vsx.md | 57 ------------------ gcc/testsuite/gcc.target/powerpc/builtins-1.c | 2 +- 3 files changed, 37 insertions(+), 82 deletions(-) diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md index a3424e1a458..4b4ca2c5d17 100644 --- a/gcc/config/rs6000/altivec.md +++ b/gcc/config/rs6000/altivec.md @@ -684,56 +684,68 @@ (define_insn "*altivec_gev4sf" [(set_attr "type" "veccmp")]) (define_insn "altivec_vsel" - [(set (match_operand:VM 0 "altivec_register_operand" "=v") + [(set (match_operand:VM 0 "register_operand" "=wa,v") (ior:VM (and:VM - (not:VM (match_operand:VM 3 "altivec_register_operand" "v")) - (match_operand:VM 1 "altivec_register_operand" "v")) + (not:VM (match_operand:VM 3 "register_operand" "wa,v")) + (match_operand:VM 1 "register_operand" "wa,v")) (and:VM (match_dup 3) - (match_operand:VM 2 "altivec_register_operand" "v"))))] + (match_operand:VM 2 "register_operand" "wa,v"))))] "VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)" - "vsel %0,%1,%2,%3" - [(set_attr "type" "vecmove")]) + "@ + xxsel %x0,%x1,%x2,%x3 + vsel %0,%1,%2,%3" + [(set_attr "type" "vecmove") + (set_attr "isa" "")]) (define_insn "altivec_vsel2" - [(set (match_operand:VM 0 "altivec_register_operand" "=v") + [(set (match_operand:VM 0 "register_operand" "=wa,v") (ior:VM (and:VM - (not:VM (match_operand:VM 3 "altivec_register_operand" "v")) - (match_operand:VM 1 "altivec_register_operand" "v")) + (not:VM (match_operand:VM 3 "register_operand" "wa,v")) + (match_operand:VM 1 "register_operand" "wa,v")) (and:VM - (match_operand:VM 2 "altivec_register_operand" "v") + (match_operand:VM 2 "register_operand" "wa,v") (match_dup 3))))] "VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)" - "vsel %0,%1,%2,%3" - [(set_attr "type" "vecmove")]) + "@ + xxsel %x0,%x1,%x2,%x3 + vsel %0,%1,%2,%3" + [(set_attr "type" "vecmove") + (set_attr "isa" "")]) (define_insn "altivec_vsel3" - [(set (match_operand:VM 0 "altivec_register_operand" "=v") + [(set (match_operand:VM 0 "register_operand" "=wa,v") (ior:VM (and:VM - (match_operand:VM 3 "altivec_register_operand" "v") - (match_operand:VM 1 "altivec_register_operand" "v")) + (match_operand:VM 3 "register_operand" "wa,v") + (match_operand:VM 1 "register_operand" "wa,v")) (and:VM (not:VM (match_dup 3)) - (match_operand:VM 2 "altivec_register_operand" "v"))))] + (match_operand:VM 2 "register_operand" "wa,v"))))] "VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)" - "vsel %0,%2,%1,%3" - [(set_attr "type" "vecmove")]) + "@ + xxsel %x0,%x2,%x1,%x3 + vsel %0,%2,%1,%3" + [(set_attr "type" "vecmove") + (set_attr "isa" "")]) (define_insn "altivec_vsel4" - [(set (match_operand:VM 0 "altivec_register_operand" "=v") + [(set (match_operand:VM 0 "register_operand" "=wa,v") (ior:VM (and:VM - (match_operand:VM 1 "altivec_register_operand" "v") - (match_operand:VM 3 "altivec_register_operand" "v")) + (match_operand:VM 1 "register_operand" "wa,v") + (match_operand:VM 3 "register_operand" "wa,v")) (and:VM (not:VM (match_dup 3)) - (match_operand:VM 2 "altivec_register_operand" "v"))))] + (match_operand:VM 2 "register_operand" "wa,v"))))] "VECTOR_MEM_ALTIVEC_OR_VSX_P (mode)" - "vsel %0,%2,%1,%3" - [(set_attr "type" "vecmove")]) + "@ + xxsel %x0,%x2,%x1,%x3 + vsel %0,%2,%1,%3" + [(set_attr "type" "vecmove") + (set_attr "isa" "")]) ;; Fused multiply add. diff --git a/gcc/config/rs6000/vsx.md b/gcc/config/rs6000/vsx.md index 601eb81e316..1d9a1eaaa54 100644 --- a/gcc/config/rs6000/vsx.md +++ b/gcc/config/rs6000/vsx.md @@ -2184,63 +2184,6 @@ (define_insn "*vsx_ge__p" "xvcmpgep. %x0,%x1,%x2" [(set_attr "type" "")]) -;; Vector select -(define_insn "vsx_xxsel" - [(set (match_operand:VSX_L 0 "vsx_register_operand" "=,?wa") - (ior:VSX_L - (and:VSX_L - (not:VSX_L (match_operand:VSX_L 3 "vsx_register_operand" ",wa")) - (match_operand:VSX_L 1 "vsx_register_operand" ",wa")) - (and:VSX_L - (match_dup 3) - (match_operand:VSX_L 2 "vsx_register_operand" ",wa"))))] - "VECTOR_MEM_VSX_P (mode)" - "xxsel %x0,%x1,%x2,%x3" - [(set_attr "type" "vecmove") - (set_attr "isa" "")]) - -(define_insn "vsx_xxsel2" - [(set (match_operand:VSX_L 0 "vsx_register_operand" "=,?wa") - (ior:VSX_L - (and:VSX_L - (not:VSX_L (match_operand:VSX_L 3 "vsx_register_operand" ",wa")) - (match_operand:VSX_L 1 "vsx_register_operand" ",wa")) - (and:VSX_L - (match_operand:VSX_L 2 "vsx_register_operand" ",wa") - (match_dup 3))))] - "VECTOR_MEM_VSX_P (mode)" - "xxsel %x0,%x1,%x2,%x3" - [(set_attr "type" "vecmove") - (set_attr "isa" "")]) - -(define_insn "vsx_xxsel3" - [(set (match_operand:VSX_L 0 "vsx_register_operand" "=,?wa") - (ior:VSX_L - (and:VSX_L - (match_operand:VSX_L 3 "vsx_register_operand" ",wa") - (match_operand:VSX_L 1 "vsx_register_operand" ",wa")) - (and:VSX_L - (not:VSX_L (match_dup 3)) - (match_operand:VSX_L 2 "vsx_register_operand" ",wa"))))] - "VECTOR_MEM_VSX_P (mode)" - "xxsel %x0,%x2,%x1,%x3" - [(set_attr "type" "vecmove") - (set_attr "isa" "")]) - -(define_insn "vsx_xxsel4" - [(set (match_operand:VSX_L 0 "vsx_register_operand" "=,?wa") - (ior:VSX_L - (and:VSX_L - (match_operand:VSX_L 1 "vsx_register_operand" ",wa") - (match_operand:VSX_L 3 "vsx_register_operand" ",wa")) - (and:VSX_L - (not:VSX_L (match_dup 3)) - (match_operand:VSX_L 2 "vsx_register_operand" ",wa"))))] - "VECTOR_MEM_VSX_P (mode)" - "xxsel %x0,%x2,%x1,%x3" - [(set_attr "type" "vecmove") - (set_attr "isa" "")]) - ;; Copy sign (define_insn "vsx_copysign3" [(set (match_operand:VSX_F 0 "vsx_register_operand" "=wa") diff --git a/gcc/testsuite/gcc.target/powerpc/builtins-1.c b/gcc/testsuite/gcc.target/powerpc/builtins-1.c index 83aed5a5141..3ec1024a955 100644 --- a/gcc/testsuite/gcc.target/powerpc/builtins-1.c +++ b/gcc/testsuite/gcc.target/powerpc/builtins-1.c @@ -326,7 +326,7 @@ int main () /* { dg-final { scan-assembler-times {\mvpkudus\M} 1 } } */ /* { dg-final { scan-assembler-times "vperm" 4 } } */ /* { dg-final { scan-assembler-times "xvrdpi" 2 } } */ -/* { dg-final { scan-assembler-times "xxsel" 10 } } */ +/* { dg-final { scan-assembler-times "xxsel" 5 } } */ /* { dg-final { scan-assembler-times "xxlxor" 6 } } */ /* { dg-final { scan-assembler-times "divd" 8 { target lp64 } } } */ /* { dg-final { scan-assembler-times "divdu" 2 { target lp64 } } } */