Commutativity of std.addf and std.mulf


I am currently implementing an optimization which aims at exploiting the commutativity of certain standard dialect operations, such as std.addf or std.mulf.

However, I noticed that while operations like std.addi or std.muli have the commutative trait attached to them, std.addf and std.mulf don’t have that trait and I was wondering why. Does it have to do with C++ seemingly not enforcing floating point commutativity either, as discussed here? Or is there a different reason?

I tried checking the docs and this discourse, but couldn’t find anything dealing with this in particular. So please feel free to tell me if it’s some trivial reason that I’m not aware of right now.

Thank you in advance!

This seems like an oversight to me. addf/mulf are commutative but not associative.

There are also a ton of missing folds for the standard dialect, e.g. muli x, 4 to shift left by 2.

1 Like