[llvm] [APInt] remove getClearedMemory and improve slow initialization (PR #106945)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 2 10:12:46 PDT 2024


================
@@ -74,11 +66,14 @@ inline static unsigned getDigit(char cdigit, uint8_t radix) {
 
 
 void APInt::initSlowCase(uint64_t val, bool isSigned) {
-  U.pVal = getClearedMemory(getNumWords());
-  U.pVal[0] = val;
-  if (isSigned && int64_t(val) < 0)
-    for (unsigned i = 1; i < getNumWords(); ++i)
-      U.pVal[i] = WORDTYPE_MAX;
+  if (isSigned && int64_t(val) < 0) {
+    U.pVal = new WordType[getNumWords()];
+    U.pVal[0] = val;
+    memset(&U.pVal[1], 0xFF, sizeof(WordType) * (getNumWords() - 1));
+  } else {
+    U.pVal = new WordType[getNumWords()]();
+    U.pVal[0] = val;
+  }
   clearUnusedBits();
----------------
topperc wrote:

Wouldn't they already be 0 from the default initialization?

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


More information about the llvm-commits mailing list