Lovely. GCC 15 has a regression whereby -O2 now aggressively unrolls loops via vectorization, producing 4-5x the code size.
What is the point of having -O2 not include -funroll-loops (the main important difference vs -O3) if vectoriation is just going to do the exact same unrolling?? 🤬
Cross-posted from IRC:
What bothers me most about this is that there's an unspoken contract about -O levels that the compiler folks broke:
-Os means "I want this small af, I don't care if it's slow"
-O2 means "this is normal code that's not really a bottleneck, but I don't want it to be stupidly slow"
-O3 means "this is AAA gamer dude code, make it as fast as possible, I don't care what it costs"
And they went and make -O2 start doing -O3 stuff. 🤦
@dalias No love for -O1? :(
@dalias Er, I have a different understanding of the contract....
-Oz means "I want this small af, I don't care if it's slow"
-Os means "I care more about small than fast, but I do care about both. Also, this is normal code, don't be too fancy about it."
-O2 means "I care more about fast than small, but I do care about both. Also, this is normal code, don't be too fancy about it."
-O3 means "I care _much_ more about fast than small, and be as fancy as you need to in order to achieve this"
@chandlerc I'd say that's pretty close to what I said, just worded differently and maybe with slightly different boundaries. In either version, having -O2 do aggressive vectorized unrolling is not appropriate.
@chandlerc Lack of unrolling except possibly in the case where it barely/doesn't increase size (because the loop body repetitions are smaller than the loop control logic) has always been a staple of -O2.
@dalias I think LLVM still does some unrolling and vectorization FWIW, but w/ different (much lower) thresholds for size expansion. But this is a very dim, fuzzy memory, so maybe wrong or changed...
I personally like the threshold difference between 2 and 3 more than a unroll-vs-not difference.
On the simple fixed-iteration-count loop I'm testing, GCC 14 and earlier and GCC 15 with -fno-tree-vectorize produce a tiny loop working on general purpose registers as intended.
GCC 15 without suppressing vectorization unrolls the entire thing in vector operations, and produces code that's the same number of instructions and larger code size than just -funroll-loops would do with general purpose registers.