Canonicalizing negative constants out of expressions causes significant instruction count increase (not all of which is cleaned up by instcombine due to ordering of expressions)
The following patch tries to factorize more combinations of FAdd/FSub instructions when unsafeAlgebra is set. This reduces the regression in codegen instructions from the above patch.
Some examples -
Here op* is restricted to FAdd/FSub.
-> Transform (A op1 B) op2 C -> A op3 (B op4 C) if (B op4 C) factorizes
Eg. (A + X*C1) + X * C2 -> A + X* (C1 + C2)
-> Transform A op1 (B op2 C) -> (A op3 B) op4 C) if (A op3 B) factorizes
Eg. (A + X*C1) - X*C2 -> A + X *(C1-C2)
-> Transform ( A op1 B) op2 C -> (A op3 C) op4 B if (A op3 C) factorizes
Eg. (X * C1 - B) + X * C2 -> X * (C1 - C2) - B
-> Transform A op1 (B op2 C) -> (A op3 C) op4 B
Eg. X * C1 - (B + X * C2) -> X * (C1 - C2) - B
I'll add test cases post feedback.
Please use hasOneUse instead.