https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95018
--- Comment #24 from rguenther at suse dot de <rguenther at suse dot de> --- On Tue, 12 May 2020, tkoenig at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95018 > > --- Comment #21 from Thomas Koenig <tkoenig at gcc dot gnu.org> --- > (In reply to Richard Biener from comment #19) > > Is libgfortran built with -O2 -funroll-loops or with -O3 (IIRC -O3?). > > Just plain -O2 (for size reasons), with matmul as an exception > where we add -funroll-loops and other optoins. > > > so what's the speciality on POWER? Code growth should trigger with -O3 > > only. > > Given we have only a guessed profile (and that does not detect the inner > > loop as completely cold) we're allowing growth then. GCC has no idea the > > outer loop iterates more than the inner. > > As a test, I changed the condition of the loop in question to > > @@ -88,7 +88,7 @@ internal_pack_r4 (gfc_array_r4 * source) > count[0]++; > /* Advance to the next source element. */ > index_type n = 0; > - while (count[n] == extent[n]) > + while (unlikely (count[n] == extent[n])) > { > /* When we get to the end of a dimension, reset it and increment > the next dimension. */ > > which then results in > > while (__builtin_expect(!!(count[n] == extent[n]), 0)) > > and the loop is still completely peeled on POWER at -O2, which > I do not understand. We end up with a 90% vs. 10% probability: ;; succ: 13 [10.0% (guessed)] count:4740826 (estimated locally) (TRUE_VALUE,EXECUTABLE) ;; 15 [90.0% (guessed)] count:42667438 (estimated locally) (FALSE_VALUE,EXECUTABLE) ... ;; basic block 13, loop depth 2, count 4740826 (estimated locally), maybe hot which is still maybe hot :/ There is now __builtin_expect_with_probability, but I wonder why we end up with a maybe-hot count regardless of the __builtin_expect. Using __builtin_expect_with_probability (!!(count[n] == extent[n]), 0, 1) makes it assumed to be never executed but as soon as I use __builtin_expect_with_probability basic block counts all end up zero!? Honza?
