[llvm] 0d67d9a - [ConstantFolding] fold integer bitwidth is greater than 63, and not multiple of 8 variables

via llvm-commits llvm-commits at lists.llvm.org
Tue May 16 19:09:25 PDT 2023


Author: khei4
Date: 2023-05-17T11:09:18+09:00
New Revision: 0d67d9aedade0eacfe296a1415de4aa720147bf4

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

LOG: [ConstantFolding] fold integer bitwidth is greater than 63, and not multiple of 8 variables
Differential Revision: https://reviews.llvm.org/D150422

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp
    llvm/test/Transforms/InstSimplify/ConstProp/loads.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 7a4ea7415ba19..0f5b7270c5364 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -429,18 +429,16 @@ bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset, unsigned char *CurPtr,
     return true;
 
   if (auto *CI = dyn_cast<ConstantInt>(C)) {
-    if (CI->getBitWidth() > 64 ||
-        (CI->getBitWidth() & 7) != 0)
+    if ((CI->getBitWidth() & 7) != 0)
       return false;
-
-    uint64_t Val = CI->getZExtValue();
+    const APInt &Val = CI->getValue();
     unsigned IntBytes = unsigned(CI->getBitWidth()/8);
 
     for (unsigned i = 0; i != BytesLeft && ByteOffset != IntBytes; ++i) {
-      int n = ByteOffset;
+      unsigned n = ByteOffset;
       if (!DL.isLittleEndian())
         n = IntBytes - n - 1;
-      CurPtr[i] = (unsigned char)(Val >> (n * 8));
+      CurPtr[i] = Val.extractBits(8, n * 8).getZExtValue();
       ++ByteOffset;
     }
     return true;

diff  --git a/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll b/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
index 9b6fc6a09de8c..3bc301743a183 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
@@ -412,3 +412,12 @@ define i8 @load_i8_from_i1() {
   %v = load i8, ptr @g_i1
   ret i8 %v
 }
+
+ at global128 = internal constant i128 1125899906842625
+define i128 @load-128bit(){
+; CHECK-LABEL: @load-128bit(
+; CHECK-NEXT:    ret i128 1125899906842625
+;
+  %1 = load i128, ptr @global128, align 4
+  ret i128 %1
+}


        


More information about the llvm-commits mailing list