Reassociate chains of
extend(X) | (extend(Y) | Z) --> (extend(X) | extend(Y)) | Z
which will then get optimized to --> extend(X | Y) | Z
Allows performing operations with a higher vector factor when vectorized.
https://alive2.llvm.org/ce/z/ha4JJC
It's not clear to me why this swap is necessary. Do you have a test case where a logic binop has a cast as operand 0 and a binop as operand 1? Complexity-based canonicalization is supposed to prevent that. See InstCombinerImpl::SimplifyAssociativeOrCommutative().