Noticed a couple of issues with the sequence and folding of mul (add x, c1), c2 -> (add (mul x, c2), c1*c2).
- In some cases, the result of c1*c2 cannot be represented as an immediate without materialising into a register. In this case, it would be better not to perform this reordering of the add instruction.
- In the bitcast case the constant c1 and c2 are marked as opaque and cannot be folded, resulting in a second mul instruction.
I have a fix that is a WIP that prevents this transformation in the case that 1. The value of c1*c2 cannot be represented as an immediate without a register, or 2. if either of the constants are opaque. Sadly this generates regressions on other targets that I am still investigating...
NOTE: not tagged as [RISCV] as I can demonstrate this on other targets, and might be worth adding here.