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

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 25 23:50:10 PST 2024


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

>From 371355ee80dc7f353cf5223b7d7c99d9b2c8ac8f Mon Sep 17 00:00:00 2001
From: Rose <83477269+AtariDreams at users.noreply.github.com>
Date: Sun, 21 Jan 2024 23:56:22 -0500
Subject: [PATCH] [Support] Refactor getN1Bits so it does not work around any
 g++ bug

This also folds better than the previous version as well.
---
 llvm/include/llvm/Support/Discriminator.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/llvm/include/llvm/Support/Discriminator.h b/llvm/include/llvm/Support/Discriminator.h
index fa78cf3045de35..c0912bead389ca 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