Understanding Compiler Optimization - Chandler Carruth - Opening Keynote Meeting C++ 2015

Sdílet
Vložit
  • čas přidán 18. 12. 2015
  • Understanding Compiler Optimization
    Chandler Carruth
    Opening Keynote Meeting C++ 2015
    Slides: meetingcpp.com/files/mcpp/201...
  • Věda a technologie

Komentáře • 81

  • @napat9
    @napat9 Před 3 lety +71

    0:00: C++ performance based on compiler optimization
    6:10: high level parts of compiler
    9:10: LLVM's IR example, simple routine
    10:22: LLVM's IR example, modelling data control flow
    16:38: optimizer duties, cleanup
    18:56: optimizer duties, canonicalization
    22:26: optimizer duties, collapse abstractions
    23:40: 3 key abstractions (function calls, memory, loops)
    25:48: function calls abstraction, inlining
    27:40: function calls abstraction, call graph
    36:18: function calls abstraction, variadic functions
    40:28: memory abstraction
    44:20: memory abstraction (partitioning, isolating, other)
    50:51: loop abstraction
    54:30: loop abstraction, canonicalization
    58:50: loop abstraction, loop unroll
    1:04:00: loop abstraction, invariant control flow
    1:09:00: loop abstraction, questions from audience
    1:30:58: optimizing combined abstractions
    1:35:30: const not optimized
    1:37:52: conclusion and questions

  • @inthegaps
    @inthegaps Před 3 lety +41

    Kudos to whatever genius decided to put the dot pattern at the back of the stage, so that any camera motion is distracting at best, and nauseating at worst.

    • @MeetingCPP
      @MeetingCPP  Před 3 lety +8

      Yes, I hate that wall so much :/

    • @jacobschmidt
      @jacobschmidt Před 3 lety +8

      I didn't notice until you pointed it out :/

  • @DatMilu2K
    @DatMilu2K Před 7 lety +40

    When he asked the crowd if they are excited about C++ I was totally with him. :D

    • @ChristopherGray00
      @ChristopherGray00 Před rokem +10

      How can you tell a C developer versus a C++ developer?
      The C++ developer is hyped for both, the C developer hates anything that is not C

    • @nickwilson1883
      @nickwilson1883 Před rokem

      @@ChristopherGray00 Usually c++ people complain about how bad C is all day and how you're a mongrel for not using C++

  • @KirillShvesov
    @KirillShvesov Před 8 lety +213

    This cellular background makings me dizziness.

  • @nero512
    @nero512 Před 7 lety +30

    The first suggested video linked to this one is "Don't help the compiler" haha.

  • @ihatenumberinemail
    @ihatenumberinemail Před 7 lety +25

    1:45:41 "once you have code that is clean on the sanitizers, then you know you have a compiler bug" "If we don't sanitize for it, we aren't going to optimize based on it"
    That guarantee makes me feel warm and fuzzy inside.

  • @nathasion9556
    @nathasion9556 Před 3 lety +11

    Chandler dude when someone asks you a question, please stop walking, and surely don't give him your back while walking. Also when there is a question in the public, please repeat the question so everyone knows what you are answering to....It is abc in public talking. Except that, brilliant lecture.

    • @MeetingCPP
      @MeetingCPP  Před 3 lety +3

      I think he has learned that by now, video is from 2015.

    • @nathasion9556
      @nathasion9556 Před 3 lety

      @@MeetingCPP haha well seen

  • @dkierans
    @dkierans Před 3 lety +5

    I know this is five years old but looking through this comment section is a bit sad. It’s a pretty good talk.

  • @budiardjo6610
    @budiardjo6610 Před 8 měsíci +3

    8 years later this person build carbon language

  • @nnicolas17
    @nnicolas17 Před 6 lety +15

    The slides going out of sync made this really hard to follow.

  • @aaronr.9644
    @aaronr.9644 Před 6 lety +2

    Very interesting talk. I am not familiar with fortran so I did not exactly follow what he said at 1:20:59 . As for sanitizers, yes ubsan is cool but it is runtime. This is the type of stuff I want to catch with static analysis.

  • @kamilziemian995
    @kamilziemian995 Před rokem

    What a fantastic talk.

  • @jean-francoiscaron5706
    @jean-francoiscaron5706 Před 8 lety +30

    This is pretty hard to follow because the slide shown doesn't sync with the slide he's talking about. E.g. around 1:03:00 is pretty bad.

    • @jensw.6173
      @jensw.6173 Před 8 lety

      +Jean-Francois Caron Well, slides aren't recorded, so at some point it wasn't that easy to get it synced. But you can download the slides from Meeting C++.

  • @OMARI-yp6dk
    @OMARI-yp6dk Před 7 lety

    thank you very much sir

  • @nguonbonnit
    @nguonbonnit Před rokem

    Wow ! So great. You help me a lots.

  • @szirsp
    @szirsp Před 2 lety

    20:40 Doesn't that discard potential branch prediction hint from the programmer who might know if it is going to be more likely for the 'if' condition to be true?

  • @juzujuzu4555
    @juzujuzu4555 Před 5 lety +9

    I have been wondering, what kind of information we could provide within our source code, for example through annotations, that could help the compiler to optimize better or to allow completely new optimizations? We could add new annotations as we find more useful information for compilers. What kind of information the developer knows of how his code should work that the compiler could use?

    • @darkengine5931
      @darkengine5931 Před 3 lety +6

      The top priority that comes to mind for me is hot/cold splitting of both branches and especially data. We have a lot in the way of indicating hot/cold branching paths with most compilers although they tend to be compiler-specific, such as 'likely' and 'unlikely' in GCC, '__assume' in MSVC, and 'noinline' and 'forceinline' available in most compilers.
      The trickier part is hot/cold splitting of data (and it tends to make the bigger difference in most domains). Consider an example like this:
      struct Particle
      {
      // hot fields constantly accessed in critical loops
      __hot float x=0.0f, y=0.0f, z=0.0f, w=0.0f;
      // cold field only accessed in non-performance critical UI areas
      __cold uint32_t q = 0;
      };
      Ideally in a such a scenario, storing a collection of particles such as in std::vector would not store all particle fields in a contiguous interleaved format like 'xyzwqxyzwqxyzwq', since 'q' would not be accessed in those critical loops. Loading it into a cache line would just be loading irrelevant data into it and wasting it. Instead it should store the data like: 'xyzwxyzwxyzw....' with an array for the cold field(s) like 'qqqqqq....' in parallel. Things of this nature, or even being able to store an SoA representation of such a structure without collapsing it into multiple structures.

    • @OmarChida
      @OmarChida Před 3 lety +3

      @@darkengine5931 thanks this was very helpful :)

    • @ChristopherGray00
      @ChristopherGray00 Před rokem

      with o2 or o3 flag, the compiler isn't leaving out optimizations that you could otherwise specify with annotations, the idea is that it already does all of that for you, providing optimizations without the sacrifice of safety (as long as you are not using o3 then maybe)

    • @bobweiram6321
      @bobweiram6321 Před 4 měsíci

      Ada's strict type system specifies intent, which hints possible optimizations to the compiler.

  • @Courserasrikanthdrk
    @Courserasrikanthdrk Před 7 lety

    very descriptive :)

  • @diegonayalazo
    @diegonayalazo Před 2 lety

    Thanks

  • @nameguy101
    @nameguy101 Před 8 lety +3

    You didn't have to re-upload. Just add the tag "yt:stretch=16:9" to the original video.

    • @jensw.6173
      @jensw.6173 Před 8 lety +3

      +Nameguy didn't work & would also stretch the slides...

  • @alexanderwesterstahl
    @alexanderwesterstahl Před 8 lety +1

    Around 8 minutes in, the AST is mentioned, and dismissed as uninteresting for this subject.
    Isn't the AST a great place for optimizations?

    • @user-jq2tz6yw6p
      @user-jq2tz6yw6p Před 8 lety +22

      AST is Front End level representation of a program, it is a good place to do language specific optimizations. LLVM Intermediate Representation level has no language specific (although it inherits some notions like memory model from C/C++11) and this is good from compiler architecture level.
      Here you see Clang AST, but what if you want to create other than C-like programming language? In this case you will have to create another Front End which produces its own AST so to be able to benefit from generic optimizations and machine code generation (this is already implemented in LLVM) it may translate it to LLVM IR and voila, you have a complete working compiler for a huge variety of target machines from Intel, AMD, ARM, and so on.

    • @alexanderwesterstahl
      @alexanderwesterstahl Před 8 lety

      Пеш Любоп
      Thanks!

  • @SamualN
    @SamualN Před 9 měsíci +1

    1:35 "they get ever smaller" he doesn't know

  • @karnajitw
    @karnajitw Před 6 lety

    Awesome point 4:30

  • @533rosy
    @533rosy Před 7 lety +4

    What was the bug at 18.40?

    • @JohannesSchreiner1
      @JohannesSchreiner1 Před 7 lety +4

      The arguments to the phi-node are flipped!

    • @Shockszzbyyous
      @Shockszzbyyous Před 7 lety

      i think i don't understand why must they be flipped to be right?

  • @User-cv4ee
    @User-cv4ee Před 2 lety +1

    I had fun learning something new but that's about the extent of it. I would not remember any of the details after a week, except for some key takeaways which could have been like 5 slides. Great talk nonetheless.

  • @ochgottnochma
    @ochgottnochma Před 8 lety +3

    To help dem lost culture in germanies: The Goldilocks principle is derived from a children's story "The Three Bears"
    in which a little girl named Goldilocks finds a house owned by three
    bears. Each bear has its own preference of food and beds. After testing
    all three examples of both items, Goldilocks determines that one of them
    is always too much in one extreme (too hot or too large), one is too
    much in the opposite extreme (too cold or too small), and one is "just
    right".[1]

  • @jrmoulton
    @jrmoulton Před rokem

  • @juzujuzu4555
    @juzujuzu4555 Před 5 lety +3

    It sucks that we can't unite and put our collective effort on researching better optimizations, tools and methods that allow those optimizations etc.
    How many devices we have that run C/C++ coded kernel and software? If those devices are battery powered, then saving CPU is having even more benefits. All major software and hardware giants should donate to this research, or participate at least somehow.
    Interesting question is what is theoretically possible, or what can we know for sure is or isn't possible, if we would have like exabyte of ram and exa instruction per second CPU and couple of days time to wait for the compiler to optimize. Perhaps in the future we compile the production quality version by sending our sources to supercomputer that does the optimization. While this sounds funny right now, there are still lots of thought behind these lines that hold truths. Anyway, bug free coding to you all =)

  • @andydufresne9387
    @andydufresne9387 Před 2 lety

    those dots on the wall make me dizzy

  • @azizas9366
    @azizas9366 Před 6 lety +3

    The prerequisite for this talk: Assembly language.

    • @TheBilly
      @TheBilly Před 4 lety +4

      The Intermediate Representation may resemble assembly language, but it is not. It is abstract, representing operations on values but not machine-level operations on memory locations and physical registers.

  •  Před 6 lety +4

    "The keyword inline has nothing to do with optimization"...
    Say that again?

    • @jonesconrad1
      @jonesconrad1 Před 5 lety +20

      it tells the compiler the symbol or function can appear in multiple translation units and not to freak out, it does not tell the compiler to inline it.

    • @greenfloatingtoad
      @greenfloatingtoad Před 3 lety +5

      It sometimes gives a hint to the compiler but the compiler is free to ignore it (or decide to inline something you didn't mark inline)
      The only guarantee is inline allows repeating the definition in multiple translation units

    •  Před 3 lety

      @@jonesconrad1 But it allows it, so it has something to do with it, a lot actually #ThatsWhyPeopleUseInlinePrimarily

  • @TheEVEInspiration
    @TheEVEInspiration Před 6 lety +4

    Compiler and language builders are doing something wrong if they consider "const" as not helpful. It is information and can be a guarantee something does not get modified. That the "constness" can be casted away for out of program "API reasons" is no excuse. Having such a cast anywhere else in the code is just as bad as a non-atomic memory access in a multi-threaded application and would just be a bug.
    People link libraries, and especially there, knowing a provided argument will not change during a library call is gold. There is no other way to optimize that case with the same guarantee that the argument will not change.
    It is not the first time I seen this attitude among language and compiler builders and it annoys me quite a bit.

    • @Verdagon
      @Verdagon Před 5 lety +11

      (Not counting const_cast) I believe you're mixing up "const" with "immutable". When I have a const reference to something, there's a guarantee that I won't change it, but there's no guarantee that nobody else will change it. See stackoverflow.com/questions/4486326/does-const-just-mean-read-only-or-something-more I think what you want is a language that takes immutability into account, so you'd want something like functional languages or Rust.

    • @nicolasabramlujan
      @nicolasabramlujan Před 4 lety +2

      I believe you could make an argument that that's a language level issue and not really the compiler's fault

    • @whydoineedausername1386
      @whydoineedausername1386 Před 4 lety +2

      @@Verdagon Rust pretty much ignores immutability when compiling because LLVM is so buggy when you have so many consts. Yes really. It used to but then they had to disable it because of LLVM bugs

    • @SolomonUcko
      @SolomonUcko Před 3 lety

      @@Verdagon stackoverflow.com/questions/57259126/why-does-the-rust-compiler-not-optimize-code-assuming-that-two-mutable-reference/57259339#57259339

  • @Courserasrikanthdrk
    @Courserasrikanthdrk Před 7 lety

    the alk gave me idea about compiler innerworking....................

  • @Fl4shback
    @Fl4shback Před 7 lety +10

    Claiming that C++ is the fastest with least overhead and totally forgetting about C.... Not saying that C is completly superior but it is still quite relevent in these aspects...

    • @MeetingCPP
      @MeetingCPP  Před 7 lety +12

      Well, C++ is superior, as it has access to a different feature set, that isn't available to C. While C is a subset of C++...

    • @cthutu
      @cthutu Před 7 lety +7

      I disagree. In theory it can be but in practice it isn't due to way C++ is normally used. The way C++ classes tend to be organically made plays havoc with the cache and is very anti-data-oriented.

    • @Fl4shback
      @Fl4shback Před 7 lety +15

      Saying that C is a subset of C++ is completly wrong. They are different languages with different grammar. Expressions can be valid in one but illegal in the other. And BECAUSE of the bigger "feature set" it starts with a disadvantage for optimization, given that nowadays this is not really an issue. Still if C++ would be superior in every aspect then C would not be the number 1 language in embedded development( at least this is what I last saw in usage polls). Still I don't say C is generally superior, I just say C++ is not generally better than C nor is C a subset of C++. They evolved differently.

    • @Dima-ht4rb
      @Dima-ht4rb Před 6 lety +8

      Spot C programmer.

    • @kristupasantanavicius9093
      @kristupasantanavicius9093 Před 5 lety +3

      C++ is a mix of high level Java like programming mixed with the possibility of using pure C anytime you desire. That is what makes it so powerful.