logoalt Hacker News

mgaunardyesterday at 2:39 PM13 repliesview on HN

[flagged]


Replies

zipy124yesterday at 3:05 PM

To those who don't know about compiler optimisation, the replacement with a closed form is rather suprising I'd say, especially if someone with Matt Godbolt's experience of all people is saying it is surprising.

Also this series is targeted towards more of a beginner audience to compilers, thus its likely to be suprising to the audience, even if not to you.

show 2 replies
f1shyyesterday at 4:54 PM

Yeah. Pretty basic. Just 14k LOC

https://github.com/llvm/llvm-project/blob/release/21.x/llvm/...

show 1 reply
nebezbyesterday at 4:46 PM

https://www.npopov.com/2023/10/03/LLVM-Scalar-evolution.html

“basic and essential” are interesting ways to describe the field of compiler optimization research.

Are you suggesting that the discovery and implementation of SCEV in LLVM is basic and essential? Or that summing integers in a range is basic and essential?

show 1 reply
ramraj07yesterday at 3:04 PM

Im curious what exactly you ask here. I consider myself to be a decent engineer (for practical purposes) but without a CS degree, and I might likely have not passed that question.

I know compilers can do some crazy optimizations but wouldn't have guessed it'll transform something from O(n) to O(1). Having said that, I dont still feel this has too much relevance to my actual job for the most part. Such performance knowledge seems to be very abstracted away from actual programming by database systems, or managed offerings like spark and snowflake, that unless you intend to work on these systems this knowledge isn't that useful (being aware they happen can be though, for sure).

show 2 replies
phhyesterday at 4:33 PM

Since GCC is lacking such an essential optimization, you should consider have one of your junior interviewee contribute this basic optimization mainline.

yeaskuyesterday at 3:21 PM

For Matt, the creator of compiler explorer, those are surprises.

For you are essentials.

You and the juniors you hire must have a deeper knoledge than him.

show 1 reply
hypeateiyesterday at 3:37 PM

What type of positions are you interviewing for? Software development is a big tent and I don't think this would be pertinent in a web dev interview, for example.

bayesnetyesterday at 2:58 PM

To provide the solution to the second part of the question, there is no closed-form solution. Since floating point math is not associative, there’s no O(1) optimization that can be applied that preserves the exact output of the O(n) loop.

show 3 replies
f1shyyesterday at 4:36 PM

I’m pretty sure making an algorithm that converts loops to close forms (I’m sure it detects much more than just a summation) is a little bit complicated.

Maybe you have much more experience than Mr Godbolt in compiliers.

xandriusyesterday at 3:24 PM

Nothing is surprising once you know the answer. It takes some mental gymnastics to put yourself in someone else's shoes before they discovered it and thus making it less "basic".

rramadassyesterday at 5:19 PM

Everyone knows the Gauss Summation formula for sum of n integers i.e. n*(n+1)/2 but it is just nice to see it in GCC vs. Clang.