From patchwork Thu Jun 16 06:36:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HAO CHEN GUI X-Patchwork-Id: 55121 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 CB515385829C for ; Thu, 16 Jun 2022 06:38:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB515385829C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655361483; bh=xZEAt3XyDfNAInnHp+HxukfSN3Gs3UqWBIWtMMYaZak=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=xR1dCpcFTd2qJph2J+Q9UhJ//7NOIX6/zlGzZOsp+1UtHqeGZ0C9uKBkmubnBg7gx Z/j1/vECDyjvjy/mmubBpPvozZ7+J01lMS9vOk1Zozwnidk6FtXvokIIX+Skn9hFHg FvRtwGQpRNRX/si6u6zzkLZMbOSn5zf+g4FIffxs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 657BC3858407 for ; Thu, 16 Jun 2022 06:37:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 657BC3858407 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 25G5TlsG028610; Thu, 16 Jun 2022 06:37:03 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gqxe21eyu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Jun 2022 06:37:02 +0000 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 25G5lpPf006005; Thu, 16 Jun 2022 06:37:02 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3gqxe21exy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Jun 2022 06:37:02 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 25G6Ks2q027722; Thu, 16 Jun 2022 06:37:00 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04fra.de.ibm.com with ESMTP id 3gmjp8wbf5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 16 Jun 2022 06:37:00 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 25G6avMJ8978838 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Jun 2022 06:36:57 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1653D42047; Thu, 16 Jun 2022 06:36:57 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5D40F42042; Thu, 16 Jun 2022 06:36:55 +0000 (GMT) Received: from [9.200.32.23] (unknown [9.200.32.23]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 16 Jun 2022 06:36:55 +0000 (GMT) Message-ID: <887ce9bb-3a34-b880-41b1-4ac2cfb743eb@linux.ibm.com> Date: Thu, 16 Jun 2022 14:36:53 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Content-Language: en-US To: gcc-patches Subject: [PATCH, rs6000] Use CC for BCD operations [PR100736] X-TM-AS-GCONF: 00 X-Proofpoint-GUID: G7znkg5wk4lLdYAYJH9gf_fgFQN9wzEn X-Proofpoint-ORIG-GUID: FEVkhfPKKJXZqjDaKiLUyA2_zJ0xa7Fy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-16_02,2022-06-15_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 clxscore=1015 spamscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2204290000 definitions=main-2206160023 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: HAO CHEN GUI via Gcc-patches From: HAO CHEN GUI Reply-To: HAO CHEN GUI Cc: Peter Bergner , David , Segher Boessenkool Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch uses CC instead of CCFP for all BCD operations. Thus, infinite math flag has no impact on BCD operations. To support BCD overflow and invalid coding, ordered and unordered are added into CC mode. With CC, "ge" and "le" are converted to reverse comparison. So the invalid coding needs to be tested separately. This patch also replaces bcdadd with bcdsub for BCD invaliding coding expand. The bcdsub with two identical numbers doesn't cause overflow while bcdadd could. Another patch which creates a dedicated CC mode for BCD operations is ready. With this patch, we don't need ordered and unordered in CC. Please advice if I can submit it. Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. Is this okay for trunk? Any recommendations? Thanks a lot. 2022-06-16 Haochen Gui gcc/ PR target/100736 * config/rs6000/altivec.md (bcd_): Replace CCFP with CC (*bcd_test_): Replace CCFP with CC. Generate condition insn with CC mode. (*bcdinvalid_): Replace CCFP with CC. Replace bcdadd. with bcdsub. (bcdinvalid_): Replace CCFP with CC. (bcdshift_v16qi): Likewise. (bcdmul10_v16qi): Likewise. (bcddiv10_v16qi): Likewise. (peephole for bcd_add/sub): Likewise. * config/rs6000/predicates.md (branch_comparison_operator): Add ordered and unordered in CC mode. * config/rs6000/rs6000.cc (validate_condition_mode): Likewise. gcc/testsuite/ PR target/100736 * gcc.target/powerpc/bcd-4.c: Adjust number of bcdadd and bcdsub. Scan no cror insns. patch.diff diff --git a/gcc/config/rs6000/altivec.md b/gcc/config/rs6000/altivec.md index efc8ae35c2e..5ffbab17a9e 100644 --- a/gcc/config/rs6000/altivec.md +++ b/gcc/config/rs6000/altivec.md @@ -4379,7 +4379,7 @@ (define_insn "bcd_" (match_operand:VBCD 2 "register_operand" "v") (match_operand:QI 3 "const_0_to_1_operand" "n")] UNSPEC_BCD_ADD_SUB)) - (clobber (reg:CCFP CR6_REGNO))] + (clobber (reg:CC CR6_REGNO))] "TARGET_P8_VECTOR" "bcd. %0,%1,%2,%3" [(set_attr "type" "vecsimple")]) @@ -4389,9 +4389,9 @@ (define_insn "bcd_" ;; UNORDERED test on an integer type (like V1TImode) is not defined. The type ;; probably should be one that can go in the VMX (Altivec) registers, so we ;; can't use DDmode or DFmode. -(define_insn "*bcd_test_" - [(set (reg:CCFP CR6_REGNO) - (compare:CCFP +(define_insn "bcd_test_" + [(set (reg:CC CR6_REGNO) + (compare:CC (unspec:V2DF [(match_operand:VBCD 1 "register_operand" "v") (match_operand:VBCD 2 "register_operand" "v") (match_operand:QI 3 "const_0_to_1_operand" "i")] @@ -4408,8 +4408,8 @@ (define_insn "*bcd_test2_" (match_operand:VBCD 2 "register_operand" "v") (match_operand:QI 3 "const_0_to_1_operand" "i")] UNSPEC_BCD_ADD_SUB)) - (set (reg:CCFP CR6_REGNO) - (compare:CCFP + (set (reg:CC CR6_REGNO) + (compare:CC (unspec:V2DF [(match_dup 1) (match_dup 2) (match_dup 3)] @@ -4502,8 +4502,8 @@ (define_insn "vclrrb" [(set_attr "type" "vecsimple")]) (define_expand "bcd__" - [(parallel [(set (reg:CCFP CR6_REGNO) - (compare:CCFP + [(parallel [(set (reg:CC CR6_REGNO) + (compare:CC (unspec:V2DF [(match_operand:VBCD 1 "register_operand") (match_operand:VBCD 2 "register_operand") (match_operand:QI 3 "const_0_to_1_operand")] @@ -4511,33 +4511,56 @@ (define_expand "bcd__" (match_dup 4))) (clobber (match_scratch:VBCD 5))]) (set (match_operand:SI 0 "register_operand") - (BCD_TEST:SI (reg:CCFP CR6_REGNO) + (BCD_TEST:SI (reg:CC CR6_REGNO) (const_int 0)))] "TARGET_P8_VECTOR" { operands[4] = CONST0_RTX (V2DFmode); + emit_insn (gen_bcd_test_ (operands[0], operands[1], + operands[2], operands[3], + operands[4])); + + rtx cr6 = gen_rtx_REG (CCmode, CR6_REGNO); + rtx condition_rtx = gen_rtx_ (SImode, cr6, const0_rtx); + rtx_code cond_code = GET_CODE (condition_rtx); + + if (cond_code == GE || cond_code == LE) + { + rtx not_result = gen_reg_rtx (CCEQmode); + rtx not_op, rev_cond_rtx; + rev_cond_rtx = gen_rtx_fmt_ee (rs6000_reverse_condition (SImode, + cond_code), + SImode, XEXP (condition_rtx, 0), + const0_rtx); + not_op = gen_rtx_COMPARE (CCEQmode, rev_cond_rtx, const0_rtx); + emit_insn (gen_rtx_SET (not_result, not_op)); + condition_rtx = gen_rtx_EQ (SImode, not_result, const0_rtx); + } + + emit_insn (gen_rtx_SET (operands[0], condition_rtx)); + DONE; }) (define_insn "*bcdinvalid_" - [(set (reg:CCFP CR6_REGNO) - (compare:CCFP + [(set (reg:CC CR6_REGNO) + (compare:CC (unspec:V2DF [(match_operand:VBCD 1 "register_operand" "v")] UNSPEC_BCDADD) (match_operand:V2DF 2 "zero_constant" "j"))) (clobber (match_scratch:VBCD 0 "=v"))] "TARGET_P8_VECTOR" - "bcdadd. %0,%1,%1,0" + "bcdsub. %0,%1,%1,0" [(set_attr "type" "vecsimple")]) (define_expand "bcdinvalid_" - [(parallel [(set (reg:CCFP CR6_REGNO) - (compare:CCFP + [(parallel [(set (reg:CC CR6_REGNO) + (compare:CC (unspec:V2DF [(match_operand:VBCD 1 "register_operand")] UNSPEC_BCDADD) (match_dup 2))) (clobber (match_scratch:VBCD 3))]) (set (match_operand:SI 0 "register_operand") - (unordered:SI (reg:CCFP CR6_REGNO) + (unordered:SI (reg:CC CR6_REGNO) (const_int 0)))] "TARGET_P8_VECTOR" { @@ -4550,7 +4573,7 @@ (define_insn "bcdshift_v16qi" (match_operand:V16QI 2 "register_operand" "v") (match_operand:QI 3 "const_0_to_1_operand" "n")] UNSPEC_BCDSHIFT)) - (clobber (reg:CCFP CR6_REGNO))] + (clobber (reg:CC CR6_REGNO))] "TARGET_P8_VECTOR" "bcds. %0,%1,%2,%3" [(set_attr "type" "vecsimple")]) @@ -4559,7 +4582,7 @@ (define_expand "bcdmul10_v16qi" [(set (match_operand:V16QI 0 "register_operand") (unspec:V16QI [(match_operand:V16QI 1 "register_operand")] UNSPEC_BCDSHIFT)) - (clobber (reg:CCFP CR6_REGNO))] + (clobber (reg:CC CR6_REGNO))] "TARGET_P9_VECTOR" { rtx one = gen_reg_rtx (V16QImode); @@ -4574,7 +4597,7 @@ (define_expand "bcddiv10_v16qi" [(set (match_operand:V16QI 0 "register_operand") (unspec:V16QI [(match_operand:V16QI 1 "register_operand")] UNSPEC_BCDSHIFT)) - (clobber (reg:CCFP CR6_REGNO))] + (clobber (reg:CC CR6_REGNO))] "TARGET_P9_VECTOR" { rtx one = gen_reg_rtx (V16QImode); @@ -4598,9 +4621,9 @@ (define_peephole2 (match_operand:V1TI 2 "register_operand") (match_operand:QI 3 "const_0_to_1_operand")] UNSPEC_BCD_ADD_SUB)) - (clobber (reg:CCFP CR6_REGNO))]) - (parallel [(set (reg:CCFP CR6_REGNO) - (compare:CCFP + (clobber (reg:CC CR6_REGNO))]) + (parallel [(set (reg:CC CR6_REGNO) + (compare:CC (unspec:V2DF [(match_dup 1) (match_dup 2) (match_dup 3)] @@ -4613,8 +4636,8 @@ (define_peephole2 (match_dup 2) (match_dup 3)] UNSPEC_BCD_ADD_SUB)) - (set (reg:CCFP CR6_REGNO) - (compare:CCFP + (set (reg:CC CR6_REGNO) + (compare:CC (unspec:V2DF [(match_dup 1) (match_dup 2) (match_dup 3)] diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md index b1fcc69bb60..28567bcc64c 100644 --- a/gcc/config/rs6000/predicates.md +++ b/gcc/config/rs6000/predicates.md @@ -1316,7 +1316,7 @@ (define_predicate "branch_comparison_operator" (if_then_else (match_test "flag_finite_math_only") (match_code "lt,le,gt,ge,eq,ne,unordered,ordered") (match_code "lt,gt,eq,unordered,unge,unle,ne,ordered")) - (match_code "lt,ltu,le,leu,gt,gtu,ge,geu,eq,ne")) + (match_code "lt,ltu,le,leu,gt,gtu,ge,geu,eq,ne,unordered,ordered")) (match_test "validate_condition_mode (GET_CODE (op), GET_MODE (XEXP (op, 0))), 1"))) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index d4defc855d0..15f813d9cf5 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -11249,11 +11249,13 @@ validate_condition_mode (enum rtx_code code, machine_mode mode) || mode == CCUNSmode); gcc_assert (mode == CCFPmode - || (code != ORDERED && code != UNORDERED - && code != UNEQ && code != LTGT + || (code != UNEQ && code != LTGT && code != UNGT && code != UNLT && code != UNGE && code != UNLE)); + gcc_assert (mode == CCFPmode || mode == CCmode + || (code != ORDERED && code != UNORDERED)); + /* These are invalid; the information is not there. */ gcc_assert (mode != CCEQmode || code == EQ || code == NE); } diff --git a/gcc/testsuite/gcc.target/powerpc/bcd-4.c b/gcc/testsuite/gcc.target/powerpc/bcd-4.c index 2c8554dfe82..3c25ed60e17 100644 --- a/gcc/testsuite/gcc.target/powerpc/bcd-4.c +++ b/gcc/testsuite/gcc.target/powerpc/bcd-4.c @@ -2,10 +2,11 @@ /* { dg-require-effective-target int128 } */ /* { dg-require-effective-target power10_hw } */ /* { dg-options "-mdejagnu-cpu=power10 -O2 -save-temps" } */ -/* { dg-final { scan-assembler-times {\mbcdadd\M} 7 } } */ -/* { dg-final { scan-assembler-times {\mbcdsub\M} 18 } } */ +/* { dg-final { scan-assembler-times {\mbcdadd\M} 5 } } */ +/* { dg-final { scan-assembler-times {\mbcdsub\M} 20 } } */ /* { dg-final { scan-assembler-times {\mbcds\M} 2 } } */ /* { dg-final { scan-assembler-times {\mdenbcdq\M} 1 } } */ +/* { dg-final { scan-assembler-not {\mcror\M} 1 } } */ #include