https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120747
--- Comment #21 from Filip Kastl <pheeck at gcc dot gnu.org> --- Created attachment 62292 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62292&action=edit Patch removing stabilization "hacks" from sort_operands_by_rank() So I gave this some more time. I confirmed that the problem is in reassoc and I've pinpointed the two relevant transformations. Let's call them transform A and B[1]. The problem is that reassoc does A and B in r16-1549 and doesn't do them in r16-1550. I thought I'll find that reassoc does some additional problematic transformations in r16-1550. But actually the problem is it decides to not do transformations it was doing before. I've also fiddled with tree-ssa-reassoc.cc:sort_operands_by_rank(). GCC's quicksort used to not be stable. There are "hacks" in this function meant to compensate for that. They are no longer needed. So I've tried removing them in a patch I attach. The patch doesn't help with transforms A and B but it does help with the miscompare. Apparently it changes some other reassoc decisions in a way that in the end gives us smaller numerical error. I hoped to find a concrete bug in reassoc that is causing the numerical error. So far I don't have it. I guess I would have to find out how reassoc makes its decisions which would require a deeper dive into the pass. If someone more experienced (Richi, Andrew, what do you think?) thinks it is worth it, I can do it. I would first take a break from this PR though :). Or perhaps a reasonable conclusion of this PR could be just applying the sort_operands_by_rank() patch. After all, deleting useless code is nice. I've benchmarked the patch and the results look good[2]. What do you think? [1] Transformation A is the FMA transformation from comment 14 and transformation B is a similar one in function inl1120. I've experimented with turning these off using debug counters. [2] I've ran SPEC 2006 and 2017 on Zen5 machine with -Ofast -march=native -flto. 2017 lbm_r actually improved by ~40%! Then there was also a 12% speedup and two 6% slowdowns.
