[llvm] bb02bf7 - [Support] Refactor getN1Bits so it does not work around any g++ bug (#78933)

via llvm-commits llvm-commits at lists.llvm.org
Sun May 26 14:25:06 PDT 2024


Author: AtariDreams
Date: 2024-05-26T17:25:02-04:00
New Revision: bb02bf78946a1833ea081a763f69b4f0304dd276

URL: https://github.com/llvm/llvm-project/commit/bb02bf78946a1833ea081a763f69b4f0304dd276
DIFF: https://github.com/llvm/llvm-project/commit/bb02bf78946a1833ea081a763f69b4f0304dd276.diff

LOG: [Support] Refactor getN1Bits so it does not work around any g++ bug (#78933)

This also folds better than the previous version as well.

Proof:
https://alive2.llvm.org/ce/z/6uwy95

Added: 
    

Modified: 
    llvm/include/llvm/Support/Discriminator.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/Discriminator.h b/llvm/include/llvm/Support/Discriminator.h
index fa78cf3045de3..c0912bead389c 100644
--- a/llvm/include/llvm/Support/Discriminator.h
+++ b/llvm/include/llvm/Support/Discriminator.h
@@ -121,12 +121,9 @@ static inline unsigned getBaseFSBitEnd() {
 }
 
 // Set bits in range of [0 .. n] to 1. Used in FS Discriminators.
-static inline unsigned getN1Bits(int N) {
-  // Work around the g++ bug that folding "(1U << (N + 1)) - 1" to 0.
-  if (N == 31)
-    return 0xFFFFFFFF;
+static inline unsigned getN1Bits(unsigned N) {
   assert((N < 32) && "N is invalid");
-  return (1U << (N + 1)) - 1;
+  return 0xFFFFFFFF >> (31 - N);
 }
 
 } // namespace llvm


        


More information about the llvm-commits mailing list