From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by sourceware.org (Postfix) with ESMTPS id 625613858416 for ; Tue, 9 Jan 2024 16:02:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 625613858416 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 625613858416 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704816140; cv=none; b=jpvikOTEwLG4avXG/mV+qCWkldHNXb3R+KVGme7bgEjNPOhFUYl/rnWaQiSWLXgyLzrICVZdErtOZVX1Q2KL0Qf/4jk9ba6TXRuRpsbkoquOnmnX2JER3d/YPoehDq2jg/TYXQ/XFK+ThKgek3Q/cmKnqMkxfrZIXiUKcIkoCww= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704816140; c=relaxed/simple; bh=MaEYV/wsPKKBfEFkfES7fLKJR7ORRZDGtf7ZGs8ekVI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=KwQQgCBa/j32eP0uFOgmJuOhhIxyKCPtSxLmdNd4BSfpnR0IBhPzODGDrEe9qsr9mRMYeE18P23j5CApVuYMjj65VucSqHjzYe8vU23NXYNuakohPUeEnhdHBDETwT5JTPcCNRwEHcIuxdJGBnOQp/AF7fsTX0+JJ7Ukq+D1Zkw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-5e6c8b70766so28481437b3.3 for ; Tue, 09 Jan 2024 08:02:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704816130; x=1705420930; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=n9DLnbVW4r5AvNM0WbVeaRLvcs5RmXGVtObDwxAiECY=; b=IqVRTscC13vv5+mlrWUl1dPSxvbS8rrATbumEcBLd8U9r0Z8SK0o2SMmPPafP3Sr00 36vqQqAr5KodUIXMb/egQGJr1h0NkvH16LJXu7+PoAYdjTy2Lpe6rLHNGmF/43vfBx0T WnUXU8vev3zePYzciC4nO28mE+/Zpd5ZP7FQGm0bScTK/njQBrZ7uAiLMmBHKEQN965A VvVy2cFq3UVaB9gjtJN5/JRF4B0Fplb0Li5H/TVhYP4pXGL5e+QD8C+XQaSXxukmTOa9 vXrKIPWBvUghmxqMyaIYk6byyiB6RpM8QyzS4yvHgAg1xjS9tPBVo9eT0yHdVWTsWE7u DzSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704816130; x=1705420930; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n9DLnbVW4r5AvNM0WbVeaRLvcs5RmXGVtObDwxAiECY=; b=TextK4Tbm17x5Y0qgr7a2B9C0nt4oMWMKSLfz2e3CVtkiMdCzbFdWhHCemBRurcit0 JziLHi6Mscj8B1FfZj+1Wz88qLrgClC3u5T8rBaG2xH/z/dnMrqPkCyBzalaXlAvFFHW PQEvj6+mSSAROotKy/4ChZfVvSOdrpKlNlaF4HSV/paKnRigtGonBHT+6R057Hka0iM9 HJ4EMDYggXREcFkr6x4Qr5F7+oqScTd2WFlRJlcEk6hl568P8DO8t065i+bjWFPWDDoN ln9Vpiwrbj+tSEnErNm+yIO5spIRqCtO6ESKcPWJmtmKRJrgkoY6zwi0ADIWyDVQjgWW qWrw== X-Gm-Message-State: AOJu0Yw3YTb88cePc9QV3jYLJ+xekL1u6MIS0EMKsxKKRLURP/PTwMse +21+vjwiA+GddAjEroLXw+s0DhelQ4Ia+xk4j4LAc9KtrMI= X-Google-Smtp-Source: AGHT+IEG8U44Zh7Zz59yHGXgWj4Wm2K/N3Pst7U7rCf4mCfCILaMmMwrcJoPNSYqC1g0iZRDMt2kuLkDPyMZBnf/ueQ= X-Received: by 2002:a81:c201:0:b0:5e9:fa4a:fd70 with SMTP id z1-20020a81c201000000b005e9fa4afd70mr3655649ywc.55.1704816129607; Tue, 09 Jan 2024 08:02:09 -0800 (PST) MIME-Version: 1.0 References: <472o65so-2n1q-s6pn-0os5-s2o22npso06o@fhfr.qr> In-Reply-To: From: "H.J. Lu" Date: Tue, 9 Jan 2024 08:01:33 -0800 Message-ID: Subject: Re: [PATCH]middle-end: check if target can do extract first for early breaks [PR113199] To: Richard Biener Cc: Tamar Christina , "gcc-patches@gcc.gnu.org" , nd , "jlaw@ventanamicro.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3021.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,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 List-Id: On Tue, Jan 9, 2024 at 4:13=E2=80=AFAM Richard Biener w= rote: > > On Tue, 9 Jan 2024, Tamar Christina wrote: > > > > > - > > > > - gimple_seq_add_seq (&stmts, tem); > > > > - > > > > - scalar_res =3D gimple_build (&stmts, CFN_EXTRACT_LAST, scala= r_type, > > > > - mask, vec_lhs_phi); > > > > + scalar_res =3D gimple_build (&stmts, CFN_VEC_EXTRACT, TREE_TYPE > > > (vectype), > > > > + vec_lhs_phi, bitstart); > > > > > > So bitstart is always zero? I wonder why using CFN_VEC_EXTRACT over > > > BIT_FIELD_REF here which wouldn't need any additional target support. > > > > > > > Ok, how about... > > > > --- > > > > I was generating the vector reverse mask without checking if the target > > actually supported such an operation. > > > > This patch changes it to if the bitstart is 0 then use BIT_FIELD_REF in= stead > > to extract the first element since this is supported by all targets. > > > > This is good for now since masks always come from whilelo. But in the = future > > when masks can come from other sources we will need the old code back. > > > > Bootstrapped Regtested on aarch64-none-linux-gnu, x86_64-pc-linux-gnu > > and no issues with --enable-checking=3Drelease --enable-lto > > --with-build-config=3Dbootstrap-O3 --enable-checking=3Dyes,rtl,extra. > > tested on cross cc1 for amdgcn-amdhsa and issue fixed. > > > > Ok for master? > > OK. > > > Thanks, > > Tamar > > > > gcc/ChangeLog: > > > > PR tree-optimization/113199 > > * tree-vect-loop.cc (vectorizable_live_operation_1): Use > > BIT_FIELD_REF. > > > > gcc/testsuite/ChangeLog: > > > > PR tree-optimization/113199 > > * gcc.target/gcn/pr113199.c: New test. > > > > --- inline copy of patch --- > > > > diff --git a/gcc/testsuite/gcc.target/gcn/pr113199.c b/gcc/testsuite/gc= c.target/gcn/pr113199.c > > new file mode 100644 > > index 0000000000000000000000000000000000000000..8a641e5536e80e207ca0163= cac66c0f4f6ca93f7 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/gcn/pr113199.c > > @@ -0,0 +1,44 @@ > > +/* { dg-do compile } */ > > +/* { dg-additional-options "-O2" } */ > > + > > +typedef long unsigned int size_t; > > +typedef int wchar_t; > > +struct tm > > +{ > > + int tm_mon; > > + int tm_year; > > +}; > > +int abs (int); > > +struct lc_time_T { const char *month[12]; }; > > +struct __locale_t * __get_current_locale (void) { } > > +const struct lc_time_T * __get_time_locale (struct __locale_t *locale)= { } > > +const wchar_t * __ctloc (wchar_t *buf, const char *elem, size_t *len_r= et) { return buf; } > > +size_t > > +__strftime (wchar_t *s, size_t maxsize, const wchar_t *format, > > + const struct tm *tim_p, struct __locale_t *locale) > > +{ > > + size_t count =3D 0; > > + const wchar_t *ctloc; > > + wchar_t ctlocbuf[256]; > > + size_t i, ctloclen; > > + const struct lc_time_T *_CurrentTimeLocale =3D __get_time_locale (lo= cale); > > + { > > + switch (*format) > > + { > > + case L'B': > > + (ctloc =3D __ctloc (ctlocbuf, _CurrentTimeLocale->month[tim_p->tm_m= on], &ctloclen)); > > + for (i =3D 0; i < ctloclen; i++) > > + { > > + if (count < maxsize - 1) > > + s[count++] =3D ctloc[i]; > > + else > > + return 0; > > + { > > + int century =3D tim_p->tm_year >=3D 0 > > + ? tim_p->tm_year / 100 + 1900 / 100 > > + : abs (tim_p->tm_year + 1900) / 100; > > + } > > + } > > + } > > + } > > +} > > diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc > > index 37f1be1101ffae779214056a0886411e0683e887..39b1161309d8ff8bfe88ee2= 6df9147df0af0a58c 100644 > > --- a/gcc/tree-vect-loop.cc > > +++ b/gcc/tree-vect-loop.cc > > @@ -10592,7 +10592,17 @@ vectorizable_live_operation_1 (loop_vec_info l= oop_vinfo, > > > > gimple_seq stmts =3D NULL; > > tree new_tree; > > - if (LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo)) > > + > > + /* If bitstart is 0 then we can use a BIT_FIELD_REF */ > > + if (integer_zerop (bitstart)) > > + { > > + tree scalar_res =3D gimple_build (&stmts, BIT_FIELD_REF, TREE_TY= PE (vectype), > > + vec_lhs_phi, bitsize, bitstart); > > + > > + /* Convert the extracted vector element to the scalar type. */ > > + new_tree =3D gimple_convert (&stmts, lhs_type, scalar_res); > > + } > > + else if (LOOP_VINFO_FULLY_WITH_LENGTH_P (loop_vinfo)) > > { > > /* Emit: > > > > @@ -10618,12 +10628,6 @@ vectorizable_live_operation_1 (loop_vec_info l= oop_vinfo, > > tree last_index =3D gimple_build (&stmts, PLUS_EXPR, TREE_TYPE (= len), > > len, bias_minus_one); > > > > - /* This needs to implement extraction of the first index, but no= t sure > > - how the LEN stuff works. At the moment we shouldn't get here si= nce > > - there's no LEN support for early breaks. But guard this so ther= e's > > - no incorrect codegen. */ > > - gcc_assert (!LOOP_VINFO_EARLY_BREAKS (loop_vinfo)); > > - > > /* SCALAR_RES =3D VEC_EXTRACT . */ > > tree scalar_res > > =3D gimple_build (&stmts, CFN_VEC_EXTRACT, TREE_TYPE (vectype), > > @@ -10648,32 +10652,6 @@ vectorizable_live_operation_1 (loop_vec_info l= oop_vinfo, > > &LOOP_VINFO_MASKS (loop_vinfo), > > 1, vectype, 0); > > tree scalar_res; > > - > > - /* For an inverted control flow with early breaks we want EXTRAC= T_FIRST > > - instead of EXTRACT_LAST. Emulate by reversing the vector and ma= sk. */ > > - if (restart_loop && LOOP_VINFO_EARLY_BREAKS (loop_vinfo)) This breaks bootstrap: https://gcc.gnu.org/pipermail/gcc-regression/2024-January/078955.html ../../src-master/gcc/tree-vect-loop.cc: In function =E2=80=98tree_node* vectorizable_live_operation_1(loop_vec_info, stmt_vec_info, basic_block, tree, int, slp_tree, tree, tree, tree, tree, bool, gimple_stmt_iterator*)=E2=80=99: ../../src-master/gcc/tree-vect-loop.cc:10598:52: error: unused parameter =E2=80=98restart_loop=E2=80=99 [-Werror=3Dunused-parameter] 10598 | tree lhs_type, bool restart_loop, | > > - { > > - /* First create the permuted mask. */ > > - tree perm_mask =3D perm_mask_for_reverse (TREE_TYPE (mask)); > > - tree perm_dest =3D copy_ssa_name (mask); > > - gimple *perm_stmt > > - =3D gimple_build_assign (perm_dest, VEC_PERM_EXPR, mask, > > - mask, perm_mask); > > - vect_finish_stmt_generation (loop_vinfo, stmt_info, perm_stmt, > > - &gsi); > > - mask =3D perm_dest; > > - > > - /* Then permute the vector contents. */ > > - tree perm_elem =3D perm_mask_for_reverse (vectype); > > - perm_dest =3D copy_ssa_name (vec_lhs_phi); > > - perm_stmt > > - =3D gimple_build_assign (perm_dest, VEC_PERM_EXPR, vec_lh= s_phi, > > - vec_lhs_phi, perm_elem); > > - vect_finish_stmt_generation (loop_vinfo, stmt_info, perm_stmt, > > - &gsi); > > - vec_lhs_phi =3D perm_dest; > > - } > > - > > gimple_seq_add_seq (&stmts, tem); > > > > scalar_res =3D gimple_build (&stmts, CFN_EXTRACT_LAST, scalar_ty= pe, > > > > -- > Richard Biener > SUSE Software Solutions Germany GmbH, > Frankenstrasse 146, 90461 Nuernberg, Germany; > GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg= ) --=20 H.J.