From patchwork Wed Jan 18 08:36:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HAO CHEN GUI X-Patchwork-Id: 63330 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 E8F493858C52 for ; Wed, 18 Jan 2023 08:37:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8F493858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674031032; bh=/XC1+fGSYbjiTEGGWMUQNrkVza6wPuZ+x0xAehFgyZ4=; h=Date:Cc:To:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=tBmYAvW332EAW+1CQ7q8JIBcIncAzxb50mqeJHycOxM4AzGkiod8RA0toXCMDOnNh 6JhdlY4eyixhZKsGNWG8dotwNRYzWa4VFqjvlZcsje5V6XBxIJy+PVjgQCcTBSkP6F a4BuhLCH01GZqgeru6Sj+cXE5mfF2pWBYCyRxjVU= 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 9A2673858D28 for ; Wed, 18 Jan 2023 08:36:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9A2673858D28 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30I7uuoU028843; Wed, 18 Jan 2023 08:36:38 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3n6ctrgvm6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Jan 2023 08:36:37 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 30I7w6jv031365; Wed, 18 Jan 2023 08:36:37 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3n6ctrgvkj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Jan 2023 08:36:37 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 30HMNxhu004735; Wed, 18 Jan 2023 08:36:35 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3n3m16myqf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 Jan 2023 08:36:35 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 30I8aVPg44695858 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Jan 2023 08:36:32 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E0FE320040; Wed, 18 Jan 2023 08:36:31 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 003AF20043; Wed, 18 Jan 2023 08:36:29 +0000 (GMT) Received: from [9.197.224.227] (unknown [9.197.224.227]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 18 Jan 2023 08:36:29 +0000 (GMT) Message-ID: Date: Wed, 18 Jan 2023 16:36:29 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US Cc: Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner To: gcc-patches Subject: [PATCH, rs6000] Convert TI AND with a special constant to DI AND [PR93123] X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ZDN6q_pmHOfhgIZLMXn2pi80B5OhcrBq X-Proofpoint-GUID: E5zk8M9KlA5VtqyRLsUwocbS8N3nKApf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.923,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-18_03,2023-01-17_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 phishscore=0 clxscore=1015 suspectscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301180073 X-Spam-Status: No, score=-12.5 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 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 Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, When TI AND with a special constant (the high part or low part is all ones), it may be converted to DI AND with a 64-bit constant and a simple DI move. When the DI AND can be implemented by rotate and mask or "andi.", it eliminates the 128-bit constant loading to save the cost. The patch creates three insn_and_split patterns to match these cases in combine pass and splits them later. The new predicate "double_wide_cint_operand" is used to identify if a constant is a double wide constant. Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. Is this okay for trunk? Any recommendations? Thanks a lot. Gui Haochen ChangeLog 2023-01-18 Haochen Gui gcc/ PR target/93123 * config/rs6000/predicates.md (double_wide_cint_operand): New. * config/rs6000/rs6000.md (*andti3_128bit_imm_highpart): New. (*andti3_128bit_imm_lowpart): New. (*andti3_64bit_imm): New. gcc/testsuite/ PR target/93123 * gcc.target/powerpc/pr93123.c: New. patch.diff diff --git a/gcc/config/rs6000/predicates.md b/gcc/config/rs6000/predicates.md index a1764018545..bacb87c3fb2 100644 --- a/gcc/config/rs6000/predicates.md +++ b/gcc/config/rs6000/predicates.md @@ -255,6 +255,19 @@ (define_predicate "u10bit_cint_operand" (and (match_code "const_int") (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 1023"))) +;; Return 1 if op is a 65-128 bits constant integer. +(define_predicate "double_wide_cint_operand" + (match_operand 0 "const_scalar_int_operand") +{ + if (CONST_INT_P (op)) + return 0; + + if (CONST_WIDE_INT_NUNITS (op) == 2) + return 1; + + return 0; +}) + ;; Return 1 if op is a constant integer that can fit in a D field. (define_predicate "short_cint_operand" (and (match_code "const_int") diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index 6011f5bf76a..1fecb2d734e 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -7199,6 +7199,128 @@ (define_expand "orc3" "mode == TImode || mode == PTImode || TARGET_P8_VECTOR" "") +(define_insn_and_split "*andti3_128bit_imm_highpart" + [(set (match_operand:TI 0 "gpc_reg_operand" "=r") + (and:TI + (match_operand:TI 1 "gpc_reg_operand" "r") + (match_operand:TI 2 "double_wide_cint_operand" "n")))] + "CONST_WIDE_INT_ELT (operands[2], 0) == -1 + && (rs6000_is_valid_and_mask (GEN_INT (CONST_WIDE_INT_ELT (operands[2], 1)), + E_DImode) + || logical_const_operand (GEN_INT (CONST_WIDE_INT_ELT (operands[2], 1)), + E_DImode))" + "#" + "&& 1" + [(const_int 0)] +{ + rtx in_lo, in_hi, out_lo, out_hi; + rtx imm = GEN_INT (CONST_WIDE_INT_ELT (operands[2], 1)); + int hi_off, lo_off; + + if (BYTES_BIG_ENDIAN) + { + hi_off = 0; + lo_off = 8; + } + else + { + hi_off = 8; + lo_off = 0; + } + + in_lo = simplify_gen_subreg (DImode, operands[1], TImode, lo_off); + out_lo = simplify_gen_subreg (DImode, operands[0], TImode, lo_off); + in_hi = simplify_gen_subreg (DImode, operands[1], TImode, hi_off); + out_hi = simplify_gen_subreg (DImode, operands[0], TImode, hi_off); + + if (rs6000_is_valid_and_mask (imm, E_DImode)) + emit_insn (gen_anddi3_mask (out_hi, in_hi, imm)); + else + emit_insn (gen_anddi3_imm (out_hi, in_hi, imm)); + + emit_move_insn (out_lo, in_lo); +} + [(set_attr "length" "8")]) + +(define_insn_and_split "*andti3_128bit_imm_lowpart" + [(set (match_operand:TI 0 "gpc_reg_operand" "=r") + (and:TI + (match_operand:TI 1 "gpc_reg_operand" "r") + (match_operand:TI 2 "double_wide_cint_operand" "n")))] + "CONST_WIDE_INT_ELT (operands[2], 1) == -1 + && (rs6000_is_valid_and_mask (GEN_INT (CONST_WIDE_INT_ELT (operands[2], 0)), + E_DImode) + || logical_const_operand (GEN_INT (CONST_WIDE_INT_ELT (operands[2], 0)), + E_DImode))" + "#" + "&& 1" + [(const_int 0)] +{ + rtx in_lo, in_hi, out_lo, out_hi; + rtx imm = GEN_INT (CONST_WIDE_INT_ELT (operands[2], 0)); + int hi_off, lo_off; + + if (BYTES_BIG_ENDIAN) + { + hi_off = 0; + lo_off = 8; + } + else + { + hi_off = 8; + lo_off = 0; + } + + in_lo = simplify_gen_subreg (DImode, operands[1], TImode, lo_off); + out_lo = simplify_gen_subreg (DImode, operands[0], TImode, lo_off); + in_hi = simplify_gen_subreg (DImode, operands[1], TImode, hi_off); + out_hi = simplify_gen_subreg (DImode, operands[0], TImode, hi_off); + + if (rs6000_is_valid_and_mask (imm, E_DImode)) + emit_insn (gen_anddi3_mask (out_lo, in_lo, imm)); + else + emit_insn (gen_anddi3_imm (out_lo, in_lo, imm)); + + emit_move_insn (out_hi, in_hi); +} + [(set_attr "length" "8")]) + + +(define_insn_and_split "*andti3_64bit_imm" + [(set (match_operand:TI 0 "gpc_reg_operand" "=r") + (and:TI + (match_operand:TI 1 "gpc_reg_operand" "r") + (match_operand:TI 2 "const_int_operand" "n")))] + "INTVAL (operands[2]) < 0 + && rs6000_is_valid_and_mask (operands[2], E_DImode)" + "#" + "&& 1" + [(const_int 0)] +{ + rtx in_lo, in_hi, out_lo, out_hi; + int hi_off, lo_off; + + if (BYTES_BIG_ENDIAN) + { + hi_off = 0; + lo_off = 8; + } + else + { + hi_off = 8; + lo_off = 0; + } + + in_lo = simplify_gen_subreg (DImode, operands[1], TImode, lo_off); + out_lo = simplify_gen_subreg (DImode, operands[0], TImode, lo_off); + in_hi = simplify_gen_subreg (DImode, operands[1], TImode, hi_off); + out_hi = simplify_gen_subreg (DImode, operands[0], TImode, hi_off); + + emit_insn (gen_anddi3_mask (out_lo, in_lo, operands[2])); + emit_move_insn (out_hi, in_hi); +} + [(set_attr "length" "8")]) + ;; 128-bit logical operations insns and split operations (define_insn_and_split "*and3_internal" [(set (match_operand:BOOL_128 0 "vlogical_operand" "=") diff --git a/gcc/testsuite/gcc.target/powerpc/pr93123.c b/gcc/testsuite/gcc.target/powerpc/pr93123.c new file mode 100644 index 00000000000..7dcaa59be1d --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr93123.c @@ -0,0 +1,46 @@ +/* { dg-options "-O2" } */ +/* { dg-require-effective-target int128 } */ + +unsigned __int128 +and128WithConst1 (unsigned __int128 a) +{ + unsigned __int128 c128 = (((unsigned __int128)(~0ULL)) << 64) + | ((unsigned __int128)(~0xFULL)); + return a & c128; +} + +unsigned __int128 +and128WithConst2 (unsigned __int128 a) +{ + unsigned __int128 c128 = (((unsigned __int128)(~0ULL)) << 64) + | ((unsigned __int128)(0xFFULL)); + return a & c128; +} + +unsigned __int128 +and128WithConst3 (unsigned __int128 a) +{ + unsigned __int128 c128 = (((unsigned __int128)(~0ULL)) << 64) + | ((unsigned __int128)(0xF1ULL)); + return a & c128; +} + +unsigned __int128 +and128WithConst4 (unsigned __int128 a) +{ + unsigned __int128 c128 = (((unsigned __int128) (~0xFULL)) << 64) + | ((unsigned __int128) (~0ULL)); + return a & c128; +} + +unsigned __int128 +and128WithConst5 (unsigned __int128 a) +{ + unsigned __int128 c128 = (((unsigned __int128) (0xF1ULL)) << 64) + | ((unsigned __int128) (~0ULL)); + return a & c128; +} + +/* { dg-final { scan-assembler-times {\mrldicr\M} 2 } } */ +/* { dg-final { scan-assembler-times {\mrldicl\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mandi\M} 2 } } */