Disabling vectorisation at '-O3'

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Disabling vectorisation at '-O3'

Joerg Sonnenberger via cfe-dev

Hi CFE-Devs,

 

While debugging a problem in our back-end, I want to temporarily remove JUST ‘-vectorize’ and ‘-vectorize-slp’ from the flags passed with ‘-cc1’, but I want to leave all the other command-line options the same.  But when I use:

 

clang -S -O3 -fno-vectorize -fno-slp-vectorize foo.c

 

it is still inserting ‘-vectorize -vectorize-slp’.  The code in ‘Clang.cpp’ for this is at line #4858 (on the v6.0 branch):

 

  // Enable vectorization per default according to the optimization level

  // selected. For optimization levels that want vectorization we use the alias

  // option to simplify the hasFlag logic.

  bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false);

  OptSpecifier VectorizeAliasOption =

      EnableVec ? options::OPT_O_Group : options::OPT_fvectorize;

  if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption,

                   options::OPT_fno_vectorize, EnableVec))

    CmdArgs.push_back("-vectorize-loops");

 

  // -fslp-vectorize is enabled based on the optimization level selected.

  bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true);

  OptSpecifier SLPVectAliasOption =

      EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;

  if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,

                   options::OPT_fno_slp_vectorize, EnableSLPVec))

    CmdArgs.push_back("-vectorize-slp");

 

but this is ignoring the ‘-fno-*’ flags and overriding because of the presence of ‘-O3’ and the defaults for ‘-O3’.

 

Am I just using ‘clang’ incorrectly, and if so, how can I achieve what I am trying to achieve?  I don’t want to use ‘-O0’ or ‘-O1’ because I still want all of the other options passed as usual with ‘-cc1’ as would normally be passed with ‘-O3’.  I am not just debugging one file, but would like to build hundreds of sources with the amended options by just changing some variables in the Makefiles to see what the impact is.

 

Thanks,

 

            MartinO

 


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Disabling vectorisation at '-O3'

Joerg Sonnenberger via cfe-dev
On 1 Mar 2018 09:16, "Martin J. O'Riordan via cfe-dev" <[hidden email]> wrote:

Hi CFE-Devs,

 

While debugging a problem in our back-end, I want to temporarily remove JUST ‘-vectorize’ and ‘-vectorize-slp’ from the flags passed with ‘-cc1’, but I want to leave all the other command-line options the same.  But when I use:

 

clang -S -O3 -fno-vectorize -fno-slp-vectorize foo.c

 

it is still inserting ‘-vectorize -vectorize-slp’.  The code in ‘Clang.cpp’ for this is at line #4858 (on the v6.0 branch):

 

  // Enable vectorization per default according to the optimization level

  // selected. For optimization levels that want vectorization we use the alias

  // option to simplify the hasFlag logic.

  bool EnableVec = shouldEnableVectorizerAtOLevel(Args, false);

  OptSpecifier VectorizeAliasOption =

      EnableVec ? options::OPT_O_Group : options::OPT_fvectorize;

  if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption,

                   options::OPT_fno_vectorize, EnableVec))

    CmdArgs.push_back("-vectorize-loops");

 

  // -fslp-vectorize is enabled based on the optimization level selected.

  bool EnableSLPVec = shouldEnableVectorizerAtOLevel(Args, true);

  OptSpecifier SLPVectAliasOption =

      EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;

  if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,

                   options::OPT_fno_slp_vectorize, EnableSLPVec))

    CmdArgs.push_back("-vectorize-slp");

 

but this is ignoring the ‘-fno-*’ flags and overriding because of the presence of ‘-O3’ and the defaults for ‘-O3’.

 

Am I just using ‘clang’ incorrectly, and if so, how can I achieve what I am trying to achieve?  I don’t want to use ‘-O0’ or ‘-O1’ because I still want all of the other options passed as usual with ‘-cc1’ as would normally be passed with ‘-O3’.  I am not just debugging one file, but would like to build hundreds of sources with the amended options by just changing some variables in the Makefiles to see what the impact is.


This looks like a bug to me; I'd expect -fno-* to override the -O flag rather than meaning "use the default for this -O level". I'd suggest you look up who added these flags and check with them to make sure this wasn't the intent (it it was, we'll need further discussion), then fix the driver to do the "obvious" thing.

Thanks,

 

            MartinO

 


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Disabling vectorisation at '-O3'

Joerg Sonnenberger via cfe-dev

Thanks Richard, I’ll do that - and I can add it as a bug.  It’s almost certainly easy enough to fix, but I wanted to be sure that I wasn’t just making a naïve mistake.

 

            MartinO

 

From: Richard Smith [mailto:[hidden email]]
Sent: 01 March 2018 17:44
To: Martin J. O'Riordan <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Disabling vectorisation at '-O3'

 

On 1 Mar 2018 09:16, "Martin J. O'Riordan via cfe-dev" <[hidden email]> wrote:

Hi CFE-Devs,

While debugging a problem in our back-end, I want to temporarily remove JUST ‘-vectorize’ and ‘-vectorize-slp’ from the flags passed with ‘-cc1’, but I want to leave all the other command-line options the same.  But when I use:

clang -S -O3 -fno-vectorize -fno-slp-vectorize foo.c

it is still inserting ‘-vectorize -vectorize-slp’.  The code in ‘Clang.cpp’ for this is at line #4858 (on the v6.0 branch):

This looks like a bug to me; I'd expect -fno-* to override the -O flag rather than meaning "use the default for this -O level". I'd suggest you look up who added these flags and check with them to make sure this wasn't the intent (it it was, we'll need further discussion), then fix the driver to do the "obvious" thing.

 


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Disabling vectorisation at '-O3'

Joerg Sonnenberger via cfe-dev

No, I’m wrong.  I think that bug is actually in ‘hasFlag’ itself.  In ‘llvm/lib/Option/ArgList.cpp’ line #70:

 

    bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,

                          bool Default) const {

      if (Arg *A = getLastArg(Pos, PosAlias, Neg))

        return A->getOption().matches(Pos) || A->getOption().matches(PosAlias);

      return Default;

    }

 

This doesn’t match when ‘Neg’ is matched, and should probably be:

 

    bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,

                          bool Default) const {

      if (Arg *A = getLastArg(Pos, PosAlias, Neg))

        return A->getOption().matches(Pos) || A->getOption().matches(PosAlias);

      else

        return !A->getOption().matches(Neg) && Default;

    }

 

So the logic in ‘CLang.cpp’ looks valid.  I’ve posted this to LLVM-Dev.

 

Thanks again,

 

            MartinO

 

From: Martin J. O'Riordan [mailto:[hidden email]]
Sent: 01 March 2018 18:15
To: 'LLVM Developers' <[hidden email]>; 'Richard Smith' <[hidden email]>
Subject: RE: [cfe-dev] Disabling vectorisation at '-O3'

 

Yes, it looks like passing ‘EnableVec’ and ‘EnableSLPVec’ to ‘Args.hasFlag’ should be replaced with ‘false’ and then it has the expected behaviour.

 

            MartinO

 

From: cfe-dev [[hidden email]] On Behalf Of Martin J. O'Riordan via cfe-dev
Sent: 01 March 2018 18:02
To: 'Richard Smith' <[hidden email]>
Cc: 'Clang Dev' <[hidden email]>
Subject: Re: [cfe-dev] Disabling vectorisation at '-O3'

 

Thanks Richard, I’ll do that - and I can add it as a bug.  It’s almost certainly easy enough to fix, but I wanted to be sure that I wasn’t just making a naïve mistake.

 

            MartinO

 

From: Richard Smith [[hidden email]]
Sent: 01 March 2018 17:44
To: Martin J. O'Riordan <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Disabling vectorisation at '-O3'

 

On 1 Mar 2018 09:16, "Martin J. O'Riordan via cfe-dev" <[hidden email]> wrote:

Hi CFE-Devs,

While debugging a problem in our back-end, I want to temporarily remove JUST ‘-vectorize’ and ‘-vectorize-slp’ from the flags passed with ‘-cc1’, but I want to leave all the other command-line options the same.  But when I use:

clang -S -O3 -fno-vectorize -fno-slp-vectorize foo.c

it is still inserting ‘-vectorize -vectorize-slp’.  The code in ‘Clang.cpp’ for this is at line #4858 (on the v6.0 branch):

This looks like a bug to me; I'd expect -fno-* to override the -O flag rather than meaning "use the default for this -O level". I'd suggest you look up who added these flags and check with them to make sure this wasn't the intent (it it was, we'll need further discussion), then fix the driver to do the "obvious" thing.

 


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Disabling vectorisation at '-O3'

Joerg Sonnenberger via cfe-dev
In reply to this post by Joerg Sonnenberger via cfe-dev

Please ignore this thread - I got myself confused, the code is fine - too many long days and nights staring at code.

 

There is an issue, but it is different to what I thought.

 

My command line is not:

 

    clang -S -O3 -fno-vectorize -fno-slp-vectorize foo.c

but:

    clang -S -fno-vectorize -fno-slp-vectorize -O3 foo.c

 

The difference was subtly hidden in a much longer argument list built by a Makefile.

 

So it seems that the position of ‘-O3’ is overriding the other flags.  The code in both ‘Clang.cpp’ and ‘ArgList.cpp’ are fine, my mistake, and sorry for wasting people’s time.

 

            MartinO

 

From: Martin J. O'Riordan [mailto:[hidden email]]
Sent: 01 March 2018 18:27
To: 'Richard Smith' <[hidden email]>; 'Clang Dev' <[hidden email]>
Cc: 'LLVM Developers' <[hidden email]>
Subject: RE: [cfe-dev] Disabling vectorisation at '-O3'

 

No, I’m wrong.  I think that bug is actually in ‘hasFlag’ itself.  In ‘llvm/lib/Option/ArgList.cpp’ line #70:

 

    bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,

                          bool Default) const {

      if (Arg *A = getLastArg(Pos, PosAlias, Neg))

        return A->getOption().matches(Pos) || A->getOption().matches(PosAlias);

      return Default;

    }

 

This doesn’t match when ‘Neg’ is matched, and should probably be:

 

    bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,

                          bool Default) const {

      if (Arg *A = getLastArg(Pos, PosAlias, Neg))

        return A->getOption().matches(Pos) || A->getOption().matches(PosAlias);

      else

        return !A->getOption().matches(Neg) && Default;

    }

 

So the logic in ‘CLang.cpp’ looks valid.  I’ve posted this to LLVM-Dev.

 

Thanks again,

 

            MartinO

 

From: Martin J. O'Riordan [[hidden email]]
Sent: 01 March 2018 18:15
To: 'LLVM Developers' <[hidden email]>; 'Richard Smith' <[hidden email]>
Subject: RE: [cfe-dev] Disabling vectorisation at '-O3'

 

Yes, it looks like passing ‘EnableVec’ and ‘EnableSLPVec’ to ‘Args.hasFlag’ should be replaced with ‘false’ and then it has the expected behaviour.

 

            MartinO

 

From: cfe-dev [[hidden email]] On Behalf Of Martin J. O'Riordan via cfe-dev
Sent: 01 March 2018 18:02
To: 'Richard Smith' <[hidden email]>
Cc: 'Clang Dev' <[hidden email]>
Subject: Re: [cfe-dev] Disabling vectorisation at '-O3'

 

Thanks Richard, I’ll do that - and I can add it as a bug.  It’s almost certainly easy enough to fix, but I wanted to be sure that I wasn’t just making a naïve mistake.

 

            MartinO

 

From: Richard Smith [[hidden email]]
Sent: 01 March 2018 17:44
To: Martin J. O'Riordan <[hidden email]>
Cc: Clang Dev <[hidden email]>
Subject: Re: [cfe-dev] Disabling vectorisation at '-O3'

 

On 1 Mar 2018 09:16, "Martin J. O'Riordan via cfe-dev" <[hidden email]> wrote:

Hi CFE-Devs,

While debugging a problem in our back-end, I want to temporarily remove JUST ‘-vectorize’ and ‘-vectorize-slp’ from the flags passed with ‘-cc1’, but I want to leave all the other command-line options the same.  But when I use:

clang -S -O3 -fno-vectorize -fno-slp-vectorize foo.c

it is still inserting ‘-vectorize -vectorize-slp’.  The code in ‘Clang.cpp’ for this is at line #4858 (on the v6.0 branch):

This looks like a bug to me; I'd expect -fno-* to override the -O flag rather than meaning "use the default for this -O level". I'd suggest you look up who added these flags and check with them to make sure this wasn't the intent (it it was, we'll need further discussion), then fix the driver to do the "obvious" thing.

 


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev