Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #80033 > unrolled thread

Have you ever noticed ...

Started byBonita Montero <Bonita.Montero@gmail.com>
First post2021-06-01 07:06 +0200
Last post2021-06-06 21:30 +0100
Articles 14 — 9 participants

Back to article view | Back to comp.lang.c++


Contents

  Have you ever noticed ... Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-01 07:06 +0200
    Re: Have you ever noticed ... Juha Nieminen <nospam@thanks.invalid> - 2021-06-01 07:11 +0000
      Re: Have you ever noticed ... Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-01 11:06 +0200
        Re: Have you ever noticed ... David Brown <david.brown@hesbynett.no> - 2021-06-01 11:54 +0200
          Re: Have you ever noticed ... Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-01 12:25 +0200
            Re: Have you ever noticed ... Bonita Montero <Bonita.Montero@gmail.com> - 2021-06-02 04:51 +0200
              Re: Have you ever noticed ... Doctor Who <doc@tardis.org> - 2021-06-02 05:12 +0200
                Re: Have you ever noticed ... doctor@doctor.nl2k.ab.ca (The Doctor) - 2021-06-02 04:10 +0000
          Re: Have you ever noticed ... Michael S <already5chosen@yahoo.com> - 2021-06-01 13:23 -0700
            Re: Have you ever noticed ... Real Troll <real.troll@trolls.com> - 2021-06-01 22:47 +0100
            Re: Have you ever noticed ... Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-06-01 18:24 -0700
              Re: Have you ever noticed ... Michael S <already5chosen@yahoo.com> - 2021-06-02 14:02 -0700
        Re: Have you ever noticed ... Juha Nieminen <nospam@thanks.invalid> - 2021-06-02 05:07 +0000
        Re: Have you ever noticed ... Vir Campestris <vir.campestris@invalid.invalid> - 2021-06-06 21:30 +0100

#80033 — Have you ever noticed ...

FromBonita Montero <Bonita.Montero@gmail.com>
Date2021-06-01 07:06 +0200
SubjectHave you ever noticed ...
Message-ID<s94f96$3pv$1@dont-email.me>
If you call ...
C:\Program Files (x86)\Microsoft Visual 
Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
... and then ...
clang --version
... then you get the nearly most recent clang (V11) with MSVC ?
But unfortunately for most benchmarks I wrote MSVC generates
better code than clang.

[toc] | [next] | [standalone]


#80036

FromJuha Nieminen <nospam@thanks.invalid>
Date2021-06-01 07:11 +0000
Message-ID<s94mij$1l4$2@gioia.aioe.org>
In reply to#80033
Bonita Montero <Bonita.Montero@gmail.com> wrote:
> If you call ...
> C:\Program Files (x86)\Microsoft Visual 
> Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
> ... and then ...
> clang --version
> ... then you get the nearly most recent clang (V11) with MSVC ?
> But unfortunately for most benchmarks I wrote MSVC generates
> better code than clang.

What optimization flags did you use?

[toc] | [prev] | [next] | [standalone]


#80037

FromBonita Montero <Bonita.Montero@gmail.com>
Date2021-06-01 11:06 +0200
Message-ID<s94t9r$iin$1@dont-email.me>
In reply to#80036
>> If you call ...
>> C:\Program Files (x86)\Microsoft Visual
>> Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
>> ... and then ...
>> clang --version
>> ... then you get the nearly most recent clang (V11) with MSVC ?
>> But unfortunately for most benchmarks I wrote MSVC generates
>> better code than clang.

> What optimization flags did you use?

-O3
There are also benchmarks which run faster with clang,
but most run faster with cl.

[toc] | [prev] | [next] | [standalone]


#80039

FromDavid Brown <david.brown@hesbynett.no>
Date2021-06-01 11:54 +0200
Message-ID<s95047$4dm$1@dont-email.me>
In reply to#80037
On 01/06/2021 11:06, Bonita Montero wrote:
>>> If you call ...
>>> C:\Program Files (x86)\Microsoft Visual
>>> Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
>>> ... and then ...
>>> clang --version
>>> ... then you get the nearly most recent clang (V11) with MSVC ?
>>> But unfortunately for most benchmarks I wrote MSVC generates
>>> better code than clang.
> 
>> What optimization flags did you use?
> 
> -O3
> There are also benchmarks which run faster with clang,
> but most run faster with cl.

-O3 is sometimes faster than -O2, and often slower.  Don't use -O3
unless you know what you are doing, and have tested it to see that it is
helpful for your particular requirements.  (The same applies to gcc, to
a slightly lesser extent.)

clang also has a tendency to be enthusiastic about vectorisation and
loop unrolling that can help for big data sets, but be noticeably bigger
and slower on small sets.  You see that especially on -O3, but also on
-O2.  Optimising is not just a matter of "bigger number means faster for
all tests".

(That said, MSVC can be quite efficient for some kinds of code - it's
entirely possible that it is simply better for the examples you were using.)

[toc] | [prev] | [next] | [standalone]


#80040

FromBonita Montero <Bonita.Montero@gmail.com>
Date2021-06-01 12:25 +0200
Message-ID<s951vm$ib3$1@dont-email.me>
In reply to#80039
> -O3 is sometimes faster than -O2, and often slower. ...

For my benchmars it's always faster than -O2. F.e I've got an
improved version of CRC64 and FNV64, which profits a lot from
loop-unrolling.

[toc] | [prev] | [next] | [standalone]


#80063

FromBonita Montero <Bonita.Montero@gmail.com>
Date2021-06-02 04:51 +0200
Message-ID<s96rml$ksp$1@dont-email.me>
In reply to#80040
>> -O3 is sometimes faster than -O2, and often slower. ...

> For my benchmars it's always faster than -O2. F.e I've got an
> improved version of CRC64 and FNV64, which profits a lot from
> loop-unrolling.


I've just installed clang12 and now my lock-free LRU-cache-algorithm
is nearly twice as fast than with clang11, and faster than with MSVC !

[toc] | [prev] | [next] | [standalone]


#80065

FromDoctor Who <doc@tardis.org>
Date2021-06-02 05:12 +0200
Message-ID<qotdbg9mkvkhe0obbmsvtgpnglld4vp3ls@4ax.com>
In reply to#80063
On Wed, 2 Jun 2021 04:51:02 +0200, Bonita Montero
<Bonita.Montero@gmail.com> wrote:

>>> -O3 is sometimes faster than -O2, and often slower. ...
>
>> For my benchmars it's always faster than -O2. F.e I've got an
>> improved version of CRC64 and FNV64, which profits a lot from
>> loop-unrolling.
>
>
>I've just installed clang12 and now my lock-free LRU-cache-algorithm
>is nearly twice as fast than with clang11, and faster than with MSVC !

good catch!

[toc] | [prev] | [next] | [standalone]


#80068

Fromdoctor@doctor.nl2k.ab.ca (The Doctor)
Date2021-06-02 04:10 +0000
Message-ID<s970bo$ftb$31@gallifrey.nk.ca>
In reply to#80065
In article <qotdbg9mkvkhe0obbmsvtgpnglld4vp3ls@4ax.com>,
Doctor Who  <doc@tardis.org> wrote:
>On Wed, 2 Jun 2021 04:51:02 +0200, Bonita Montero
><Bonita.Montero@gmail.com> wrote:
>
>>>> -O3 is sometimes faster than -O2, and often slower. ...
>>
>>> For my benchmars it's always faster than -O2. F.e I've got an
>>> improved version of CRC64 and FNV64, which profits a lot from
>>> loop-unrolling.
>>
>>
>>I've just installed clang12 and now my lock-free LRU-cache-algorithm
>>is nearly twice as fast than with clang11, and faster than with MSVC !
>
>good catch!

Oi! What are you not in rec.arts.drwho ?

-- 
Member - Liberal International This is doctor@@nl2k.ab.ca Ici doctor@@nl2k.ab.ca
Yahweh, Queen & country!Never Satan President Republic!Beware AntiChrist rising!
Look at Psalms 14 and 53 on Atheism https://www.empire.kred/ROOTNK?t=94a1f39b  
If one could not qualify for the ark, then how for heaven?  -unknown

[toc] | [prev] | [next] | [standalone]


#80058

FromMichael S <already5chosen@yahoo.com>
Date2021-06-01 13:23 -0700
Message-ID<af084372-37bb-44f6-93fa-f80d4ed25d04n@googlegroups.com>
In reply to#80039
On Tuesday, June 1, 2021 at 12:54:30 PM UTC+3, David Brown wrote:
> On 01/06/2021 11:06, Bonita Montero wrote: 
> >>> If you call ... 
> >>> C:\Program Files (x86)\Microsoft Visual 
> >>> Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat 
> >>> ... and then ... 
> >>> clang --version 
> >>> ... then you get the nearly most recent clang (V11) with MSVC ? 
> >>> But unfortunately for most benchmarks I wrote MSVC generates 
> >>> better code than clang. 
> > 
> >> What optimization flags did you use? 
> > 
> > -O3 
> > There are also benchmarks which run faster with clang, 
> > but most run faster with cl.
> -O3 is sometimes faster than -O2, and often slower. Don't use -O3 
> unless you know what you are doing, and have tested it to see that it is 
> helpful for your particular requirements. (The same applies to gcc, to 
> a slightly lesser extent.) 
> 
> clang also has a tendency to be enthusiastic about vectorisation and 
> loop unrolling that can help for big data sets, but be noticeably bigger 
> and slower on small sets. You see that especially on -O3, but also on 
> -O2. Optimising is not just a matter of "bigger number means faster for 
> all tests". 
> 
> (That said, MSVC can be quite efficient for some kinds of code - it's 
> entirely possible that it is simply better for the examples you were using.)

I was under impression that in clang -O3 is the same as -O2. A flag that exists for compatibility with gcc and nothing else.

[toc] | [prev] | [next] | [standalone]


#80059

FromReal Troll <real.troll@trolls.com>
Date2021-06-01 22:47 +0100
Message-ID<s96a2f$m4e$1@gioia.aioe.org>
In reply to#80058
On 01/06/2021 21:23, Michael S wrote:
> I was under impression that in clang -O3 is the same as -O2. A flag that exists for compatibility with gcc and nothing else.


Just checked in clang, latest version 12.0.0-win64, and nothing in it -O3. Not sure what are they talking about.


[toc] | [prev] | [next] | [standalone]


#80062

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2021-06-01 18:24 -0700
Message-ID<87a6o9xdmr.fsf@nosuchdomain.example.com>
In reply to#80058
Michael S <already5chosen@yahoo.com> writes:
> On Tuesday, June 1, 2021 at 12:54:30 PM UTC+3, David Brown wrote:
>> On 01/06/2021 11:06, Bonita Montero wrote: 
>> >>> If you call ... 
>> >>> C:\Program Files (x86)\Microsoft Visual 
>> >>> Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat 
>> >>> ... and then ... 
>> >>> clang --version 
>> >>> ... then you get the nearly most recent clang (V11) with MSVC ? 
>> >>> But unfortunately for most benchmarks I wrote MSVC generates 
>> >>> better code than clang. 
>> > 
>> >> What optimization flags did you use? 
>> > 
>> > -O3 
>> > There are also benchmarks which run faster with clang, 
>> > but most run faster with cl.
>> -O3 is sometimes faster than -O2, and often slower. Don't use -O3 
>> unless you know what you are doing, and have tested it to see that it is 
>> helpful for your particular requirements. (The same applies to gcc, to 
>> a slightly lesser extent.) 
>> 
>> clang also has a tendency to be enthusiastic about vectorisation and 
>> loop unrolling that can help for big data sets, but be noticeably bigger 
>> and slower on small sets. You see that especially on -O3, but also on 
>> -O2. Optimising is not just a matter of "bigger number means faster for 
>> all tests". 
>> 
>> (That said, MSVC can be quite efficient for some kinds of code - it's 
>> entirely possible that it is simply better for the examples you were using.)
>
> I was under impression that in clang -O3 is the same as -O2. A flag
> that exists for compatibility with gcc and nothing else.

As of version 12.0.0, "man clang" says:

    -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4
    Specify which optimization level to use:

    -O0 Means “no optimization”: this level compiles the 
        fastest and generates the most debuggable code.

    -O1 Somewhere between -O0 and -O2.

    -O2 Moderate level of optimization which enables most
        optimizations.

    -O3 Like -O2, except that it enables optimizations that
        take longer to perform or that may generate larger
        code (in an attempt to make the program run faster).

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */

[toc] | [prev] | [next] | [standalone]


#80113

FromMichael S <already5chosen@yahoo.com>
Date2021-06-02 14:02 -0700
Message-ID<160a1f58-9941-4f9a-9fe7-a6c6289904b1n@googlegroups.com>
In reply to#80062
On Wednesday, June 2, 2021 at 4:24:31 AM UTC+3, Keith Thompson wrote:
> Michael S <already...@yahoo.com> writes: 
> > On Tuesday, June 1, 2021 at 12:54:30 PM UTC+3, David Brown wrote: 
> >> On 01/06/2021 11:06, Bonita Montero wrote: 
> >> >>> If you call ... 
> >> >>> C:\Program Files (x86)\Microsoft Visual 
> >> >>> Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat 
> >> >>> ... and then ... 
> >> >>> clang --version 
> >> >>> ... then you get the nearly most recent clang (V11) with MSVC ? 
> >> >>> But unfortunately for most benchmarks I wrote MSVC generates 
> >> >>> better code than clang. 
> >> > 
> >> >> What optimization flags did you use? 
> >> > 
> >> > -O3 
> >> > There are also benchmarks which run faster with clang, 
> >> > but most run faster with cl. 
> >> -O3 is sometimes faster than -O2, and often slower. Don't use -O3 
> >> unless you know what you are doing, and have tested it to see that it is 
> >> helpful for your particular requirements. (The same applies to gcc, to 
> >> a slightly lesser extent.) 
> >> 
> >> clang also has a tendency to be enthusiastic about vectorisation and 
> >> loop unrolling that can help for big data sets, but be noticeably bigger 
> >> and slower on small sets. You see that especially on -O3, but also on 
> >> -O2. Optimising is not just a matter of "bigger number means faster for 
> >> all tests". 
> >> 
> >> (That said, MSVC can be quite efficient for some kinds of code - it's 
> >> entirely possible that it is simply better for the examples you were using.) 
> > 
> > I was under impression that in clang -O3 is the same as -O2. A flag 
> > that exists for compatibility with gcc and nothing else.
> As of version 12.0.0, "man clang" says: 
> 
> -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4 
> Specify which optimization level to use: 
> 
> -O0 Means “no optimization”: this level compiles the 
> fastest and generates the most debuggable code. 
> 
> -O1 Somewhere between -O0 and -O2. 
> 
> -O2 Moderate level of optimization which enables most 
> optimizations. 
> 
> -O3 Like -O2, except that it enables optimizations that 
> take longer to perform or that may generate larger 
> code (in an attempt to make the program run faster). 
> 

It sounds like a generic statement that was likely written at the very beginning of LLVM development and does not mean much in practice.
Same statement 6 years ago:
https://web.archive.org/web/20151027095342/https://clang.llvm.org/docs/CommandGuide/clang.html

In gcc, there is a list of sub-optimizations enabled by various -O flags.
https://gcc.gnu.org/onlinedocs/gcc-11.1.0/gcc/Optimize-Options.html#Optimize-Options
I  had never seen similar list for clang/LLVM.

Also, when observing asm code, generated by clang, I never encountered different results between -O2 and -O3.
To be fair, typically I looked at relatively small snippets, so if the differences are related to interprocedural optimizations I could have overlooked them.

> -- 
> Keith Thompson (The_Other_Keith) Keith.S.T...@gmail.com 
> Working, but not speaking, for Philips Healthcare 
> void Void(void) { Void(); } /* The recursive call of the void */

[toc] | [prev] | [next] | [standalone]


#80071

FromJuha Nieminen <nospam@thanks.invalid>
Date2021-06-02 05:07 +0000
Message-ID<s973ls$j81$2@gioia.aioe.org>
In reply to#80037
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>> If you call ...
>>> C:\Program Files (x86)\Microsoft Visual
>>> Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
>>> ... and then ...
>>> clang --version
>>> ... then you get the nearly most recent clang (V11) with MSVC ?
>>> But unfortunately for most benchmarks I wrote MSVC generates
>>> better code than clang.
> 
>> What optimization flags did you use?
> 
> -O3
> There are also benchmarks which run faster with clang,
> but most run faster with cl.

I also recommend using -march=native.

[toc] | [prev] | [next] | [standalone]


#80200

FromVir Campestris <vir.campestris@invalid.invalid>
Date2021-06-06 21:30 +0100
Message-ID<s9jb9t$rs9$2@dont-email.me>
In reply to#80037
On 01/06/2021 10:06, Bonita Montero wrote:
> -O3
> There are also benchmarks which run faster with clang,
> but most run faster with cl.

I found some code the other day that was faster with O3 on GCC but Ofast 
on clang. (or it could have been the other way around).

Always benchmark if performance matters that much to you.

Andy

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web