This is an archive of the discontinued LLVM Phabricator instance.

Fix invariant fdiv hoisting in LICM
ClosedPublic

Authored by rampitec on Jun 21 2018, 11:07 AM.

Details

Summary

FDiv is replaced with multiplication by reciprocal and invariant
reciprocal is hoisted out of the loop, while multiplication remains
even if invariant.

Switch checks for all invariant operands and only invariant
denominator to fix the issue.

Diff Detail

Repository
rL LLVM

Event Timeline

rampitec created this revision.Jun 21 2018, 11:07 AM
rampitec edited reviewers, added: vit9696, arsenm; removed: reames.Jun 22 2018, 10:25 AM
vit9696 accepted this revision.Jun 22 2018, 7:37 PM

Hello,

The proposed change seems right to me in both senses:

  • moving the invariant out of the loop (obvious);
  • not making a reciprocal here, as it may add an extra overhead for non-constant divisors.

The only case I could see this behaving worse is when the loop is not supposed to be executed, but the operations will still get speculatively hoisted. To my view this is uncommon and kind of contradicts the assumption of the LICM pass that loops do get executed more than once. It could have been nice to see some benchmarks on real projects, but I expect the inner arithmetics to be normally collapsed by other passes and defeat any change effects except in some special code, which this change supposedly optimises for, so it is not worth it.

Accepted.

Best regards,
Vit

This revision is now accepted and ready to land.Jun 22 2018, 7:37 PM
This revision was automatically updated to reflect the committed changes.