[PATCH] D69023: [Alignment][NFC] Optimize alignTo

Guillaume Chatelet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 16 02:32:07 PDT 2019


gchatelet added inline comments.


================
Comment at: llvm/include/llvm/Support/Alignment.h:174
+  // multiple functions gets inlined.
+  return (Size + value - 1) & -value;
 }
----------------
courbet wrote:
> IIUC, `-value` is just the same as `~(value - 1)`. but only works if the representation two's complement. C++ does not guarantee two's complement. What about using  `~(value - 1)` instead ?
> 
> https://godbolt.org/z/8KJBV3
Good catch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69023/new/

https://reviews.llvm.org/D69023





More information about the llvm-commits mailing list