This is an archive of the discontinued LLVM Phabricator instance.

[llvm][Support] Replace `%` operator with `&` in `Align::isAligned(...)`
AbandonedPublic

Authored by Stoorx on Apr 22 2023, 1:51 PM.

Details

Reviewers
fhahn
phosek
Summary

Since the function Align::value() ALWAYS returns power of 2,
it is easier to check reminder by conjunction with mask, which is (Pow2Value - 1).

Diff Detail

Event Timeline

Stoorx created this revision.Apr 22 2023, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2023, 1:51 PM
Stoorx requested review of this revision.Apr 22 2023, 1:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2023, 1:51 PM
fhahn added a comment.Apr 28 2023, 2:32 AM

it is easier to check reminder by conjunction with mask, which is (Pow2Value - 1).

Hmm, easier in what respect? Isn't the original code more straight-forward?

easier in what respect?

I mean, easier for CPU :-)

The division operation reasonably seems to be more complex than bitwise AND. And since this function is pretty hot it can save a bit of performance.
(Actually that's just my assumption. I did not make benchmark really.)

Side thought: I suspect some advanced CPUs can optimize such kind of divisions by powers of 2 by themselves.

Stoorx abandoned this revision.May 2 2023, 2:35 AM