ocaml-flambda / flambda-backend

The Flambda backend project for OCaml
92 stars 65 forks source link

Code generation does not use information such as commutativity #2288

Open xclerc opened 4 months ago

xclerc commented 4 months ago

The following code (assuming the operators are redefined for unboxed floats):

let f ~(s: float#) (t : float#) =
  t + t * s

generates the following:

movapd xmm2,xmm1
mulsd  xmm2,xmm0
addsd  xmm1,xmm2

while we would like:

mulsd   xmm0, xmm1
addsd   xmm0, xmm1
xclerc commented 4 months ago

The issue could probably be solved by a bunch of peephole rules, but that sounds quite fragile. It might be better to fix the issue at selection.