This is an archive of the discontinued LLVM Phabricator instance.

[FLANG] Change loop versioning to use shift instead of divide
ClosedPublic

Authored by Leporacanthicus on Jun 1 2023, 4:37 AM.

Details

Summary

Despite me being convinced that the use of divide didn't produce any
divide instructions, it does in fact add more instructions than using
a plain shift operation.

This patch simply changes the divide to a shift right, with an
assert to check that the "divisor" is a power of two.

Diff Detail

Event Timeline

Leporacanthicus created this revision.Jun 1 2023, 4:37 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 1 2023, 4:37 AM
Leporacanthicus requested review of this revision.Jun 1 2023, 4:37 AM
flang/lib/Optimizer/Transforms/LoopVersioning.cpp
269

Would it be better to use an if-else to handle the powerOf2 and the other case?

For the types handled now, I think REAL(KIND=10) 80-bit extended precision with explicit normalization bit (15e64m) will not be a power of 2.

tblah accepted this revision.Jun 1 2023, 5:28 AM

Thanks!

This revision is now accepted and ready to land.Jun 1 2023, 5:28 AM
Leporacanthicus added inline comments.Jun 1 2023, 6:33 AM
flang/lib/Optimizer/Transforms/LoopVersioning.cpp
269

It will work for RELA(KIND=10) as is, as those are aligned to 16 bytes, although the actual data is only 10 bytes.

So as far as I can tell, the only reason we'd need non-power of two is if we allow data-types that are not the simple types currently supported.

kiranchandramohan accepted this revision.Jun 1 2023, 6:49 AM

LG.

flang/lib/Optimizer/Transforms/LoopVersioning.cpp
269

OK. Thanks.