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

via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 21 20:57:23 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: AtariDreams (AtariDreams)

<details>
<summary>Changes</summary>

This also folds better than the previous version as well.

---
Full diff: https://github.com/llvm/llvm-project/pull/78933.diff


1 Files Affected:

- (modified) llvm/include/llvm/Support/Discriminator.h (+2-5) 


``````````diff
diff --git a/llvm/include/llvm/Support/Discriminator.h b/llvm/include/llvm/Support/Discriminator.h
index fa78cf3045de35..e2d2a5bceee4b9 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 0xFFFFFFFFU >> (31 - N);
 }
 
 } // namespace llvm

``````````

</details>


https://github.com/llvm/llvm-project/pull/78933


More information about the llvm-commits mailing list