Message ID | 31c05be7-64bf-8d93-934c-63262e082e68@linux.ibm.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 681A13857825 for <patchwork@sourceware.org>; Wed, 19 Oct 2022 03:19:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 681A13857825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666149564; bh=xljZ062+MrNEfKEe2Uv9KejKqWRQ9xnAi4ydjkbj/Iw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=WY9NUMGSibvtmHXdrNpFWJ7HEDi2viutRq428KfRqtnyszJTEPcaL/CjvY2i8Hlo3 iHH8mgQMOtk0aT8+UtkPgt8KiYzMIFVABjgABQ19rZYpbbAqsPm8GKVW5UOg6Le3/m LV7vHZuUlXXRuZnXDgDSyJkG6PT0Ig/lzfIZ741M= 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 A51113858D39 for <gcc-patches@gcc.gnu.org>; Wed, 19 Oct 2022 03:18:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A51113858D39 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29J3DArZ029963; Wed, 19 Oct 2022 03:18:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ka94wr3rv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Oct 2022 03:18:51 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29J3GoQH008158; Wed, 19 Oct 2022 03:18:50 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ka94wr3r0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Oct 2022 03:18:50 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29J37EZm002208; Wed, 19 Oct 2022 03:18:48 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 3k7m4jpas3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 19 Oct 2022 03:18:48 +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 29J3Iksr8127210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 19 Oct 2022 03:18:46 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 37F15A405B; Wed, 19 Oct 2022 03:18:46 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 58B12A4054; Wed, 19 Oct 2022 03:18:44 +0000 (GMT) Received: from [9.197.229.72] (unknown [9.197.229.72]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 19 Oct 2022 03:18:44 +0000 (GMT) Message-ID: <31c05be7-64bf-8d93-934c-63262e082e68@linux.ibm.com> Date: Wed, 19 Oct 2022 11:18:42 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Content-Language: en-US To: GCC Patches <gcc-patches@gcc.gnu.org> Subject: [PATCH] vect: Try folding first for shifted value generation [PR107240] Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: KZSQHTkyVV34wkfAX61SLVO8q_PujTyd X-Proofpoint-GUID: FKlpL9g6zKgPu1QZuUtlcssu7AVMyUib X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-18_10,2022-10-18_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=978 adultscore=0 impostorscore=0 mlxscore=0 bulkscore=0 clxscore=1011 priorityscore=1501 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210190015 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: "Kewen.Lin via Gcc-patches" <gcc-patches@gcc.gnu.org> Reply-To: "Kewen.Lin" <linkw@linux.ibm.com> Cc: Richard Sandiford <richard.sandiford@arm.com>, Segher Boessenkool <segher@kernel.crashing.org> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
vect: Try folding first for shifted value generation [PR107240]
|
|
Commit Message
Kewen.Lin
Oct. 19, 2022, 3:18 a.m. UTC
Hi, As PR107240 shows, when both the value to be shifted and the count used for shifting are constants, it doesn't actually requires a target to support vector shift operations. This patch is to try fold_build2 for the generation of the shifted value first, if it's folded, the shift is gone, otherwise it's the same as before. It can help to make the failures of vect-bitfield-write-{2,3}.c gone on Power. Bootstrapped and regtested on x86_64-redhat-linux, aarch64-linux-gnu and powerpc64{,le}-linux-gnu. Is it ok for trunk? BR, Kewen ----- PR tree-optimization/107240 gcc/ChangeLog: * tree-vect-patterns.cc (vect_recog_bit_insert_pattern): Attempt to fold shifted value. --- gcc/tree-vect-patterns.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.27.0
Comments
On Wed, Oct 19, 2022 at 5:18 AM Kewen.Lin <linkw@linux.ibm.com> wrote: > > Hi, > > As PR107240 shows, when both the value to be shifted and the > count used for shifting are constants, it doesn't actually > requires a target to support vector shift operations. > > This patch is to try fold_build2 for the generation of the > shifted value first, if it's folded, the shift is gone, > otherwise it's the same as before. > > It can help to make the failures of vect-bitfield-write-{2,3}.c > gone on Power. > > Bootstrapped and regtested on x86_64-redhat-linux, > aarch64-linux-gnu and powerpc64{,le}-linux-gnu. > > Is it ok for trunk? > > BR, > Kewen > ----- > PR tree-optimization/107240 > > gcc/ChangeLog: > > * tree-vect-patterns.cc (vect_recog_bit_insert_pattern): Attempt to > fold shifted value. > --- > gcc/tree-vect-patterns.cc | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc > index 6afd57a50c4..3beda774ec3 100644 > --- a/gcc/tree-vect-patterns.cc > +++ b/gcc/tree-vect-patterns.cc > @@ -2098,9 +2098,11 @@ vect_recog_bit_insert_pattern (vec_info *vinfo, stmt_vec_info stmt_info, > tree shifted = value; > if (shift_n) > { > + tree shifted_tmp > + = fold_build2 (LSHIFT_EXPR, container_type, value, shift); > pattern_stmt > = gimple_build_assign (vect_recog_temp_ssa_var (container_type), > - LSHIFT_EXPR, value, shift); > + shifted_tmp); The canonical way would be to use gimple_seq stmts = NULL; shifted = gimple_build (&stmts, LSHIFT_EXPR, container_type, value, shift); if (!gimple_seq_empty_p (stmts)) append_pattern_def_seq (vinfo, stmt_info, gimple_seq_first_stmt (stmts)); That also avoids the spurious val = constant; with your patch. OK if that works. thanks, Richard. > append_pattern_def_seq (vinfo, stmt_info, pattern_stmt); > shifted = gimple_get_lhs (pattern_stmt); > } > -- > 2.27.0
Hi Richi, on 2022/10/19 15:43, Richard Biener wrote: > On Wed, Oct 19, 2022 at 5:18 AM Kewen.Lin <linkw@linux.ibm.com> wrote: >> >> Hi, >> >> As PR107240 shows, when both the value to be shifted and the >> count used for shifting are constants, it doesn't actually >> requires a target to support vector shift operations. >> >> This patch is to try fold_build2 for the generation of the >> shifted value first, if it's folded, the shift is gone, >> otherwise it's the same as before. >> >> It can help to make the failures of vect-bitfield-write-{2,3}.c >> gone on Power. >> >> Bootstrapped and regtested on x86_64-redhat-linux, >> aarch64-linux-gnu and powerpc64{,le}-linux-gnu. >> >> Is it ok for trunk? >> >> BR, >> Kewen >> ----- >> PR tree-optimization/107240 >> >> gcc/ChangeLog: >> >> * tree-vect-patterns.cc (vect_recog_bit_insert_pattern): Attempt to >> fold shifted value. >> --- >> gcc/tree-vect-patterns.cc | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc >> index 6afd57a50c4..3beda774ec3 100644 >> --- a/gcc/tree-vect-patterns.cc >> +++ b/gcc/tree-vect-patterns.cc >> @@ -2098,9 +2098,11 @@ vect_recog_bit_insert_pattern (vec_info *vinfo, stmt_vec_info stmt_info, >> tree shifted = value; >> if (shift_n) >> { >> + tree shifted_tmp >> + = fold_build2 (LSHIFT_EXPR, container_type, value, shift); >> pattern_stmt >> = gimple_build_assign (vect_recog_temp_ssa_var (container_type), >> - LSHIFT_EXPR, value, shift); >> + shifted_tmp); > > The canonical way would be to use > > gimple_seq stmts = NULL; > shifted = gimple_build (&stmts, LSHIFT_EXPR, container_type, > value, shift); > if (!gimple_seq_empty_p (stmts)) > append_pattern_def_seq (vinfo, stmt_info, > gimple_seq_first_stmt (stmts)); > > That also avoids the spurious val = constant; with your patch. > Thanks for the suggestion! This works well by testing those two cases locally. I searched around, it seems gimple_build doesn't provide one interface for its users to specify a ssa name for the result, previously we use vect_recog_temp_ssa_var for the shifted result, but I think it's trivial. I'll do a full testing further as before and push it if everything goes well. Thanks again. BR, Kewen > OK if that works. > > thanks, > Richard. > >> append_pattern_def_seq (vinfo, stmt_info, pattern_stmt); >> shifted = gimple_get_lhs (pattern_stmt); >> } >> -- >> 2.27.0
diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index 6afd57a50c4..3beda774ec3 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -2098,9 +2098,11 @@ vect_recog_bit_insert_pattern (vec_info *vinfo, stmt_vec_info stmt_info, tree shifted = value; if (shift_n) { + tree shifted_tmp + = fold_build2 (LSHIFT_EXPR, container_type, value, shift); pattern_stmt = gimple_build_assign (vect_recog_temp_ssa_var (container_type), - LSHIFT_EXPR, value, shift); + shifted_tmp); append_pattern_def_seq (vinfo, stmt_info, pattern_stmt); shifted = gimple_get_lhs (pattern_stmt); }