From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id C65CC3858D39 for ; Wed, 19 Oct 2022 07:43:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C65CC3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x630.google.com with SMTP id d26so37881437eje.10 for ; Wed, 19 Oct 2022 00:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=VQGrfY4GQQ+CXnZ5yH/ZOP5syVadYi2rXwnfyyEThEs=; b=lrsROiN1lRAJTd+ujtbjnB1Sj/NDmODeZyj9MoatCsi63WPyjEYTSdrAlqe/NOeduK lmFOpCFEMjrneQEdiQoJ+bO7CXmfjGdoopubhjGUhmD2PhVidhve6xtDFV9A+IbZC2cF aXhXWk5lsVPlU+B6H7yiLCfjs0h8GBwCz/bRP3SHappoJhvSAa7edFl5Q8kjhXJYIMmc IxEUqHDIg++BEfIUv/5YdFxDucjqI9FK1pABCmvwcqZRhrcEoU5zmRp8b+tDRu1yMOFP Yo/cfLRn6JvZ8AxnVHJypEQt2xrMWLhhbk7foqQ6SSx90xA1cShtkZfq36MhtSSD3ye5 XDuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=VQGrfY4GQQ+CXnZ5yH/ZOP5syVadYi2rXwnfyyEThEs=; b=HoROE6SHdlCYz8jkaHSpgitBI8QTFJMevJ4hKbiuHidO5z6KXDsge78IVrsIW4FUgx PMy1cXyTirg7vYVQbih8mDbYvvd53yc1Fw5S7vYljv5Ogv7qbrc0uLnwSTFUvRtQJXO5 ExennPx/M3WMki/j4CdCR84zSMMJFwP1wKaLNWIsJzy6M0CMOihCi8bJ0LpSG3YgtfLx WNL/Gogd7XnwwdtUqSUS+RF1PXWlYliq/zxELj+VV0kgovS9+45r2dd9owpHO1uZCiHB y2cfnjPvf7wdg5zVmPtjhiX7CinEUxN4oZYFKGOWhbEOoUkHl02YPJh6EP5pb6PNgIHJ 22gA== X-Gm-Message-State: ACrzQf2D8zsppvvIJYryo21nZMNtDxs/yKQ6uZgJ6uiiiFctSHFZd0m7 o3Rb3qEADbcQWDxKHy4O+h1I1et76Uh1UDC8FXk= X-Google-Smtp-Source: AMsMyM58oNDs/ZQw1CUbxLsCTgAPAE8KDu/I+1AFB9tB8vr+QHWGJ3h15rhQZ/wnuqOCpJ4NCtF7q+0F2NdjRRLQhqM= X-Received: by 2002:a17:906:d54d:b0:78e:2fbf:ca2a with SMTP id cr13-20020a170906d54d00b0078e2fbfca2amr5742598ejc.488.1666165425551; Wed, 19 Oct 2022 00:43:45 -0700 (PDT) MIME-Version: 1.0 References: <31c05be7-64bf-8d93-934c-63262e082e68@linux.ibm.com> In-Reply-To: <31c05be7-64bf-8d93-934c-63262e082e68@linux.ibm.com> From: Richard Biener Date: Wed, 19 Oct 2022 09:43:33 +0200 Message-ID: Subject: Re: [PATCH] vect: Try folding first for shifted value generation [PR107240] To: "Kewen.Lin" Cc: GCC Patches , "Andre Vieira (lists)" , Segher Boessenkool , Richard Sandiford Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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 List-Id: On Wed, Oct 19, 2022 at 5:18 AM Kewen.Lin 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