From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 048163857803 for ; Wed, 30 Nov 2022 15:38:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 048163857803 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669822687; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=F7VFAgY0abDDiovQraaR3wh/pVTu0ubqywtSyeQLIZM=; b=ZdB7o8Amr29bF1YMxlg3/y5T+PijeJWOhLLv2rxNarPlGHcJ5kr29XLV37ipyIUiPEtyK5 OkW0fZfS3IKRr5aJgw0Ui8xK/snfLariEkbUVNWzPImbAVOt56/opjV0LLE3NjmFRAFSY9 v7XCNwfAAA0tAkV7Eq61+6Qjx4HVjas= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-593-9MpUd_biMDSRNMorsV8mvw-1; Wed, 30 Nov 2022 10:38:03 -0500 X-MC-Unique: 9MpUd_biMDSRNMorsV8mvw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43BA0185A794; Wed, 30 Nov 2022 15:38:03 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE65A1415119; Wed, 30 Nov 2022 15:38:02 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2AUFbvaI1868610 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 30 Nov 2022 16:37:57 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2AUFbuSd1868609; Wed, 30 Nov 2022 16:37:56 +0100 Date: Wed, 30 Nov 2022 16:37:55 +0100 From: Jakub Jelinek To: Andrew Stubbs Cc: Richard Biener , gcc-patches@gcc.gnu.org Subject: Re: [PATCH 3/3] vect: inbranch SIMD clones Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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, Nov 30, 2022 at 03:17:30PM +0000, Andrew Stubbs wrote: > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-16.c > @@ -0,0 +1,89 @@ > +/* { dg-require-effective-target vect_simd_clones } */ > +/* { dg-additional-options "-fopenmp-simd -fdump-tree-optimized" } */ > +/* { dg-additional-options "-mavx" { target avx_runtime } } */ ... > +/* Ensure the the in-branch simd clones are used on targets that support > + them. These counts include all call and definitions. */ > + > +/* { dg-skip-if "" { x86_64-*-* } { "-flto" } { "" } } */ Maybe better add -ffat-lto-objects to dg-additional-options and drop the dg-skip-if (if it works with that, for all similar tests)? > @@ -1063,7 +1064,8 @@ if_convertible_gimple_assign_stmt_p (gimple *stmt, > A statement is if-convertible if: > - it is an if-convertible GIMPLE_ASSIGN, > - it is a GIMPLE_LABEL or a GIMPLE_COND, > - - it is builtins call. */ > + - it is builtins call. s/call\./call,/ above > + - it is a call to a function with a SIMD clone. */ > > static bool > if_convertible_stmt_p (gimple *stmt, vec refs) > @@ -1083,13 +1085,23 @@ if_convertible_stmt_p (gimple *stmt, vec refs) > tree fndecl = gimple_call_fndecl (stmt); > if (fndecl) > { > + /* We can vectorize some builtins and functions with SIMD > + "inbranch" clones. */ > int flags = gimple_call_flags (stmt); > + struct cgraph_node *node = cgraph_node::get (fndecl); > if ((flags & ECF_CONST) > && !(flags & ECF_LOOPING_CONST_OR_PURE) > - /* We can only vectorize some builtins at the moment, > - so restrict if-conversion to those. */ > && fndecl_built_in_p (fndecl)) > return true; > + else if (node && node->simd_clones != NULL) I don't see much value in the "else " above, the if branch returns if condition is true, so just if (node && node->simd_clones != NULL) would do it. > + /* Ensure that at least one clone can be "inbranch". */ > + for (struct cgraph_node *n = node->simd_clones; n != NULL; > + n = n->simdclone->next_clone) > + if (n->simdclone->inbranch) > + { > + need_to_predicate = true; > + return true; > + } > } > return false; > } > @@ -2603,6 +2615,29 @@ predicate_statements (loop_p loop) > gimple_assign_set_rhs1 (stmt, ifc_temp_var (type, rhs, &gsi)); > update_stmt (stmt); > } > + > + /* Convert functions that have a SIMD clone to IFN_MASK_CALL. This > + will cause the vectorizer to match the "in branch" clone variants, > + and serves to build the mask vector in a natural way. */ > + gcall *call = dyn_cast (gsi_stmt (gsi)); > + if (call && !gimple_call_internal_p (call)) > + { > + tree orig_fn = gimple_call_fn (call); > + int orig_nargs = gimple_call_num_args (call); > + auto_vec args; > + args.safe_push (orig_fn); > + for (int i=0; i < orig_nargs; i++) Formatting - int i = 0; > + args.safe_push (gimple_call_arg (call, i)); > + args.safe_push (cond); > + > + /* Replace the call with a IFN_MASK_CALL that has the extra > + condition parameter. */ > + gcall *new_call = gimple_build_call_internal_vec (IFN_MASK_CALL, > + args); > + gimple_call_set_lhs (new_call, gimple_call_lhs (call)); > + gsi_replace (&gsi, new_call, true); > + } > + > lhs = gimple_get_lhs (gsi_stmt (gsi)); > if (lhs && TREE_CODE (lhs) == SSA_NAME) > ssa_names.add (lhs); > --- a/gcc/tree-vect-stmts.cc > +++ b/gcc/tree-vect-stmts.cc > @@ -3987,6 +3987,7 @@ vectorizable_simd_clone_call (vec_info *vinfo, stmt_vec_info stmt_info, > size_t i, nargs; > tree lhs, rtype, ratype; > vec *ret_ctor_elts = NULL; > + int arg_offset = 0; > > /* Is STMT a vectorizable call? */ > gcall *stmt = dyn_cast (stmt_info->stmt); > @@ -3994,6 +3995,16 @@ vectorizable_simd_clone_call (vec_info *vinfo, stmt_vec_info stmt_info, > return false; > > fndecl = gimple_call_fndecl (stmt); > + if (fndecl == NULL_TREE > + && gimple_call_internal_p (stmt) > + && gimple_call_internal_fn (stmt) == IFN_MASK_CALL) Replace the above 2 lines with && gimple_call_internal_p (stmt, IFN_MASK_CALL)) ? > --- a/gcc/tree-vect-loop.cc > +++ b/gcc/tree-vect-loop.cc > @@ -2121,6 +2121,15 @@ vect_get_datarefs_in_loop (loop_p loop, basic_block *bbs, > if (is_gimple_call (stmt) && loop->safelen) > { > tree fndecl = gimple_call_fndecl (stmt), op; > + if (fndecl == NULL_TREE > + && gimple_call_internal_p (stmt) > + && gimple_call_internal_fn (stmt) == IFN_MASK_CALL) Similarly. Otherwise LGTM. Jakub