This is a new version of http://reviews.llvm.org/D16833 as mgrang has no more time to work on the feature.
This patch substantially differ from the previous version. The original patch applied the transformation if:
if (Op1C->getValueAPF().isFinite())
I don't think this is the correct way of checking we're in finite-mode only. Instead, checked that the function has the attributes no-nans-fp-math and no-infs-fp-math both set to true. I hope I wasn't entirely wrong in my analysis. In any case, comments welcome.
Also, this adds a test (which wasn't included in the original revision).
cc:ing Steve Canon so that he can confirm/deny if this makes sense from a mathematical point of view.