This is an archive of the discontinued LLVM Phabricator instance.

[BypassSlowDivision] Improve our handling of divisions by constants
ClosedPublic

Authored by sanjoy on Sep 25 2017, 6:04 PM.

Details

Summary

Don't bail out on constant divisors for divisions that can be narrowed without
introducing control flow . This gives us a 32 bit multiply instead of an
emulated 64 bit multiply in the generated PTX assembly.

Diff Detail

Repository
rL LLVM

Event Timeline

sanjoy created this revision.Sep 25 2017, 6:04 PM
jlebar added inline comments.Sep 25 2017, 11:17 PM
lib/Transforms/Utils/BypassSlowDivision.cpp
359 ↗(On Diff #116626)

The divisor also stays a constant in the other two cases, so is this really the thing that makes us want to do this transformation but not the other ones when the divisor is a constant?

sanjoy added inline comments.Sep 26 2017, 10:08 AM
lib/Transforms/Utils/BypassSlowDivision.cpp
359 ↗(On Diff #116626)

The way I worked this out in my head is that, for the optimization to be worth it, the perf improvement from doing a shorter op must be more than the perf regression due to control flow. When the op is divide the assumption is that this tradeoff is worth it, but when the op is multiply (division by constant) this tradeoff is not worth it.

However, if we can narrow the op (divide or multiply) without any control flow then there is no tradeoff -- we should always narrow the op.

sanjoy updated this revision to Diff 116714.Sep 26 2017, 2:44 PM
  • update comments
jlebar accepted this revision.Sep 26 2017, 2:48 PM
This revision is now accepted and ready to land.Sep 26 2017, 2:48 PM
Harbormaster completed remote builds in B10607: Diff 116714.
This revision was automatically updated to reflect the committed changes.