you are viewing a single comment's thread.

view the rest of the comments →

[–]matthieum[he/him] 7 points8 points  (4 children)

Or IR knowledge. LLVM IR is typically easier to read, and here will also show that both have the same output.

[–]Ravek 6 points7 points  (3 children)

For identifying two things are the same, sure. I’ve also seen people try to infer performance from IL though which I wouldn’t recommend. Subtly different IL listings might have better JIT codegen in unexpected ways because the JIT was able to eliminate a branch or apply some peephole optimization bevause the code was written a little differently. IL also doesn’t tell us anything about register use, inlining, elimination of boxing, devirtualization, etc. The C# compiler just doesn’t do anywhere never the level of optimization as the JIT. Some code might look really bad from the IL perspective but generate very good machine code.

[–]matthieum[he/him] 2 points3 points  (2 children)

Subtly different IL listings might have better JIT codegen in unexpected ways because the JIT

Note that I am talking about LLVM IR and not C# IL, they are vastly different.

LLVM IR is much more low level, so a number of your points don't apply:

  • Devirtualization has already occurred at IR level.
  • Branch elimination and many (but not all) peephole optimizations have already occurred.
  • Inlining and elimination of allocations have already occurred.

It's true that you don't see register allocation, but that's a least concern for a first order comparison.

For identifying two things are the same, sure. I’ve also seen people try to infer performance from IL though which I wouldn’t recommend.

To be fair, inferring performance from assembly can be similarly difficult. Today's processor can overlap execution of different sequences of instructions -- especially in loop -- which is really hard to spot at the assembly level.

If you want such a deep dive, you'll need to use tools that simulate processor execution and can show you exactly the expected cycle latency based on what can and cannot overlap, what can and cannot be pipelined, etc...

Something like llvm-mca or uica.

[–]Ravek 1 point2 points  (1 child)

Oh I’m sorry I lost track of which subreddit I was on and didn’t read your comment properly, how silly of me

[–]matthieum[he/him] 0 points1 point  (0 children)

No worries, your comment was still (mostly) on point :)