[PATCH] D149006: [llvm][Support] Replace `%` operator with `&` in `Align::isAligned(...)`
Sviatoslav Osipov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 22 13:52:00 PDT 2023
Stoorx created this revision.
Herald added a project: All.
Stoorx requested review of this revision.
Herald added a project: LLVM.
Since the function `Align::value()` ALWAYS returns power of 2,
it is easier to check reminder by conjunction with mask, which is `(Pow2Value - 1)`.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149006
Files:
llvm/include/llvm/Support/Alignment.h
Index: llvm/include/llvm/Support/Alignment.h
===================================================================
--- llvm/include/llvm/Support/Alignment.h
+++ llvm/include/llvm/Support/Alignment.h
@@ -143,7 +143,7 @@
/// Checks that SizeInBytes is a multiple of the alignment.
inline bool isAligned(Align Lhs, uint64_t SizeInBytes) {
- return SizeInBytes % Lhs.value() == 0;
+ return !(SizeInBytes & (Lhs.value() - 1));
}
/// Checks that Addr is a multiple of the alignment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149006.516103.patch
Type: text/x-patch
Size: 485 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230422/4ca0a07b/attachment.bin>
More information about the cfe-commits
mailing list