A generalization like this was suggested in D119754, but I'm proposing to move the constant up rather than down.
If these operations ever graduate to become real instructions rather than intrinsics, then this would not conflict with the reassociate pass because it has the same transform in its set of tricks for binop instructions.
The line between the passes on these kinds of folds is blurry, but this doesn't appear to have much cost and gives us the expected wins from repeated folds as seen in the last pair of test diffs.
I'd move the first check into the first if, because it doesn't match the comment on this one.