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.


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.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D149006: [llvm][... Sviatoslav Osipov via Phabricator via cfe-commits

Reply via email to