https://gcc.gnu.org/bugzilla/show_bug.cgi?id=23471
--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> --- The case a*a has been handled for a while, both in fold-const.c (tree_binary_nonnegative_warnv_p) and in VRP. However, the case a*a*a*a*a*a is not handled. In the .optimized dump at -O3, we still have: b_3 = a_2(D) * a_2(D); b_4 = a_2(D) * b_3; b_5 = a_2(D) * b_4; b_6 = a_2(D) * b_5; b_7 = a_2(D) * b_6; If reassoc or some similar pass had turned it into the following, the optimization would probably work: b_3 = a_2(D) * a_2(D); b_4 = a_2(D) * b_3; b_7 = b_4 * b_4; Not sure how often this would be useful though.