https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82446
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- Created attachment 42311 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42311&action=edit failed patch attempt I tried to address this in split_constant_offset, better canonicalizing trees there. While it handles the case in the original PR it regresses some others, for example gcc.dg/vect/pr69783.c because it canonicalizes before folding, possibly messing up canonicalization that happened to be ok before. So the solution is probably to add a canonicalize_tree function that does just this (without folding, just swapping operands in-place -- requiring tree unsharing before if it is possibly shared). Ideally we'd have a expr hash on each tree_exp that swap_tree_operands () could use so we'd properly canonicalize already during folding (conveniently tree_exp _does_ have 4 bytes of unused padding...). buildN could compute this for us as well. Anyway, a separate function looks more feasible at the moment, we can call that from dr_innermost analysis (there's already some kind of weird canonicalization function).