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 3DA4E3858CDB for ; Tue, 25 Jul 2023 20:53:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3DA4E3858CDB 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=1690318397; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5fIXQvgfTxAajmAGPynvzgKICGR0ppOjHgvYYD8XpzQ=; b=HxwHNu58I1WDxsp7OMPputFB6wEo+bWe9qVv/ogEwbtxU8Nwt/jcPLMtOLuABFwQOXmSWV GzvgEJVfOUmudVlkVjUQXUknswm4o5L5ojz+VF59hXoaBvmwzVkBHG7T5j+WW2B2wQ9nsC l4M6gbQvKQWuno/ZSuPGnIQBDTqid5g= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-573-osCSf-3cN-y3xD-g6TdUjA-1; Tue, 25 Jul 2023 16:53:15 -0400 X-MC-Unique: osCSf-3cN-y3xD-g6TdUjA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7683f415a45so907553285a.3 for ; Tue, 25 Jul 2023 13:53:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690318395; x=1690923195; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5fIXQvgfTxAajmAGPynvzgKICGR0ppOjHgvYYD8XpzQ=; b=WxycDtoAMqBJXA0wSfnnq4L9zF4XDYiCzXtuFumjgH83w7CgvcdSAU2EmSFqhUiFjc XC/Z42TalHj0TkBBt4LF+P4EylcS+bZnMCEtq8XTKPTlhBKhXC3Jq2q39aAikulfsqLY SiPJAHtYUw9Ql7PvT9E1qWTGa2RtdKbCnRi8haphrPsZ2I+P3GliHDYjvMHCeuuYHXXd NAD7aflJTOHSKjFaJkOBsF/d7hV+eNGZCa49JoJobjoo5O+Agf3MWiaS9dpxeKsEo+nj waSqC6hWOU8VrO6mh1Vy3y2giWlT934E2dCP4i2RDKySGB2r5YN/KfSE7L56c7+zlk5A +H9A== X-Gm-Message-State: ABy/qLbdQ0RoeuQKv66Vr9oy+RMytJSjghAFdGoIFXrf+LGnGwoMhzlW +tXP+KhCO1ubQWOSvfoJhr5x7ZhB68OH6wfqU//4+l6LS2bliAb0+LIfA9iafgEDH5mZbRLJN+N TQsINIwAmSPqTzyCxNUoy03XVXA== X-Received: by 2002:a05:620a:2801:b0:767:e785:15cb with SMTP id f1-20020a05620a280100b00767e78515cbmr68525qkp.76.1690318394943; Tue, 25 Jul 2023 13:53:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlGbpTTq2O0r6rPiMHiLONgh+jSVI3E95/VPITawm7aHopQgfc/FurloualplKj0oGyZeyVi1A== X-Received: by 2002:a05:620a:2801:b0:767:e785:15cb with SMTP id f1-20020a05620a280100b00767e78515cbmr68517qkp.76.1690318394686; Tue, 25 Jul 2023 13:53:14 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id b1-20020a05620a126100b0076227222e49sm3927912qkl.6.2023.07.25.13.53.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Jul 2023 13:53:13 -0700 (PDT) Message-ID: <1437ed35-e278-4eea-eb50-fa918af927bd@redhat.com> Date: Tue, 25 Jul 2023 16:53:13 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH 1/2][frontend] Add novector C++ pragma To: Tamar Christina , gcc-patches@gcc.gnu.org Cc: nd@arm.com, nathan@acm.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_LOTSOFHASH,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 7/19/23 11:15, Tamar Christina wrote: > Hi All, > > FORTRAN currently has a pragma NOVECTOR for indicating that vectorization should > not be applied to a particular loop. > > ICC/ICX also has such a pragma for C and C++ called #pragma novector. > > As part of this patch series I need a way to easily turn off vectorization of > particular loops, particularly for testsuite reasons. > > This patch proposes a #pragma GCC novector that does the same for C++ > as gfortan does for FORTRAN and what ICX/ICX does for C++. > > I added only some basic tests here, but the next patch in the series uses this > in the testsuite in about ~800 tests. > > Bootstrapped Regtested on aarch64-none-linux-gnu and no issues. > > Ok for master? > > Thanks, > Tamar > > gcc/cp/ChangeLog: > > * cp-tree.def (RANGE_FOR_STMT): Update comment. > * cp-tree.h (RANGE_FOR_NOVECTOR): New. > (cp_convert_range_for, finish_while_stmt_cond, finish_do_stmt, > finish_for_cond): Add novector param. > * init.cc (build_vec_init): Default novector to false. > * method.cc (build_comparison_op): Likewise. > * parser.cc (cp_parser_statement): Likewise. > (cp_parser_for, cp_parser_c_for, cp_parser_range_for, > cp_convert_range_for, cp_parser_iteration_statement, > cp_parser_omp_for_loop, cp_parser_pragma): Support novector. > (cp_parser_pragma_novector): New. > * pt.cc (tsubst_expr): Likewise. > * semantics.cc (finish_while_stmt_cond, finish_do_stmt, > finish_for_cond): Likewise. > > gcc/ChangeLog: > > * doc/extend.texi: Document it. > > gcc/testsuite/ChangeLog: > > * g++.dg/vect/vect.exp (support vect- prefix). > * g++.dg/vect/vect-novector-pragma.cc: New test. > > --- inline copy of patch -- > diff --git a/gcc/cp/cp-tree.def b/gcc/cp/cp-tree.def > index 0e66ca70e00caa1dc4beada1024ace32954e2aaf..c13c8ea98a523c4ef1c55a11e02d5da9db7e367e 100644 > --- a/gcc/cp/cp-tree.def > +++ b/gcc/cp/cp-tree.def > @@ -305,8 +305,8 @@ DEFTREECODE (IF_STMT, "if_stmt", tcc_statement, 4) > > /* Used to represent a range-based `for' statement. The operands are > RANGE_FOR_DECL, RANGE_FOR_EXPR, RANGE_FOR_BODY, RANGE_FOR_SCOPE, > - RANGE_FOR_UNROLL, and RANGE_FOR_INIT_STMT, respectively. Only used in > - templates. */ > + RANGE_FOR_UNROLL, RANGE_FOR_NOVECTOR and RANGE_FOR_INIT_STMT, > + respectively. Only used in templates. */ This change is unnecessary; RANGE_FOR_NOVECTOR is a flag, not an operand. > DEFTREECODE (RANGE_FOR_STMT, "range_for_stmt", tcc_statement, 6) > > /* Used to represent an expression statement. Use `EXPR_STMT_EXPR' to > diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc > index dd3665c8ccf48a8a0b1ba2c06400fe50999ea240..8776e8f4cf8266ee715c3e7f943602fdb1acaf79 100644 > --- a/gcc/cp/parser.cc > +++ b/gcc/cp/parser.cc > @@ -13658,7 +13660,13 @@ cp_parser_c_for (cp_parser *parser, tree scope, tree init, bool ivdep, > "% pragma"); > condition = error_mark_node; > } > - finish_for_cond (condition, stmt, ivdep, unroll); > + else if (novector) > + { > + cp_parser_error (parser, "missing loop condition in loop with " > + "% pragma"); > + condition = error_mark_node; > + } Why is it a problem for a loop with novector to have no condition? This error makes sense for the other pragmas that want to optimize based on the condition, it seems unneeded for this pragma. > + > + cp_token *tok = pragma_tok; > + > + do > { > - tok = cp_lexer_consume_token (parser->lexer); > - ivdep = cp_parser_pragma_ivdep (parser, tok); > - tok = cp_lexer_peek_token (the_parser->lexer); > + switch (cp_parser_pragma_kind (tok)) > + { > + case PRAGMA_IVDEP: > + { > + if (tok != pragma_tok) > + tok = cp_lexer_consume_token (parser->lexer); > + ivdep = cp_parser_pragma_ivdep (parser, tok); > + tok = cp_lexer_peek_token (the_parser->lexer); > + break; > + } > + case PRAGMA_UNROLL: > + { > + if (tok != pragma_tok) > + tok = cp_lexer_consume_token (parser->lexer); > + unroll = cp_parser_pragma_unroll (parser, tok); > + tok = cp_lexer_peek_token (the_parser->lexer); > + break; > + } > + case PRAGMA_NOVECTOR: > + { > + if (tok != pragma_tok) > + tok = cp_lexer_consume_token (parser->lexer); > + novector = cp_parser_pragma_novector (parser, tok); > + tok = cp_lexer_peek_token (the_parser->lexer); > + break; > + } > + default: > + gcc_unreachable (); This unreachable seems to assert that if a pragma follows one of these pragmas, it must be another one of these pragmas? That seems wrong; instead of hitting gcc_unreachable() in that case we should fall through to the diagnostic below. I also think you could factor the peek out of the switch. > diff --git a/gcc/testsuite/g++.dg/vect/vect-novector-pragma.cc b/gcc/testsuite/g++.dg/vect/vect-novector-pragma.cc > new file mode 100644 > index 0000000000000000000000000000000000000000..cd5fb7ba9d4806f4d5e484ec68c707ea0e28ad7c > --- /dev/null > +++ b/gcc/testsuite/g++.dg/vect/vect-novector-pragma.cc > @@ -0,0 +1,68 @@ > +/* { dg-skip-if "incorrect syntax for c++98" { *-*-* } { "-std=c++98" } { "" } } */ > +/* { dg-do compile } */ This is usually expressed as { dg-do compile { target c++11 } } Or you could run in C++98 mode but guard the range-for tests with #if __cpp_range_based_for Jason