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: 45098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2215094wrn; Wed, 18 Jan 2023 00:37:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXuwFcdNZFUGaCE60vG1Ywi1shrKkZ18r2F5wAgXYwquOl7Pc6Qnt7Xw0wAHUemKhL9ye6Y1 X-Received: by 2002:a17:907:d68c:b0:812:d53e:1222 with SMTP id wf12-20020a170907d68c00b00812d53e1222mr6390015ejc.31.1674031049276; Wed, 18 Jan 2023 00:37:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674031049; cv=none; d=google.com; s=arc-20160816; b=D9Hj4JqEk0V7kXzW5GucnTZIXoDZVwhFvNiLKHdEF7DMX1G7MpciXPcTBRdWrbl7Y6 Ki521dTWlfasAptPf6+JTOgsd0ROXGpDbM3UJh9XVD+XbaVvNIMFXeRrPU33iHXWM4BO pyv4Da/hlwU6eteg1ZijD+2xmes1/Qccd2uEHc/sOs8MLccRSLSmKFk+ZSTKMrROuYXe b4jRH7EkD0BRU0tglqeGzPNhHRUnHA2zK4S3VgTR5hpnIIzUKCFlpnON2OO8iApVxxQD W+MA4HDgsj/3r4WkDqYIhHSUkviwWlRfBpxehO65oLePANlPxCiow4eWVu9GddzHPAhB 5deg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:subject:to:cc:content-language:user-agent :mime-version:date:message-id:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=/XC1+fGSYbjiTEGGWMUQNrkVza6wPuZ+x0xAehFgyZ4=; b=WMVUhYGJvuaiJ2FlGkwL4nWZ9RkIwcY1a8iHal0wp6zqcg2UmQnX/3pELZfKDyyRlj JIvOW/5KpN9yOJidH0Xx/fs94GDpC5pffn/KEPJLdOw8vRm9ufmT5N9Wv5/8SplOAUCo GrGsKPaIyRRpQwin6gFDqTntjkHCeMeuqO/XIeCzMSqt3F63Tx/QfwGQczBtp6xa0Wyi FKOKI3Utbc8Wt3nPKWs1fkduwuFZbkalA8u4yNTnKgjOToyxQAV6W+uH6pg7BzGiXZeq dZfRLOSaY7KKB/VXLcuDmcaIsM9joqotOrjx2+uUHqAp7XUQBQYwT9/isYtoCeOC+J2W 7X1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Dau/YMne"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id et19-20020a170907295300b00871b6dea6adsi5184870ejc.872.2023.01.18.00.37.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Jan 2023 00:37:29 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="Dau/YMne"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 468E03858421 for ; Wed, 18 Jan 2023 08:37:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 468E03858421 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674031048; 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=Dau/YMnee7HplgS/1HzBce39CbhoUdxQispKIIyqYhaLQnd6H1OVAbVe+JQfSwY9W 2XfVIgNW4aImJtbhPHOsbw/ZnhwwVGNbeVFkPUO+kuIdEgv8eYvPy19rsTTQZcmQ4y in8oWSuQp88SFl+U3xBkKsA57V8DHPPuboV3pSao= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755348781531717746?= X-GMAIL-MSGID: =?utf-8?q?1755348781531717746?= 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 } } */