[ConstantFolding] fold integer bitwidth is greater than 63, and not multiple of 8...
authorkhei4 <kk.asano.luxy@gmail.com>
Fri, 12 May 2023 04:32:10 +0000 (13:32 +0900)
committerkhei4 <kk.asano.luxy@gmail.com>
Wed, 17 May 2023 02:09:18 +0000 (11:09 +0900)
Differential Revision: https://reviews.llvm.org/D150422

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

index 7a4ea74..0f5b727 100644 (file)
@@ -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;
index 9b6fc6a..3bc3017 100644 (file)
@@ -412,3 +412,12 @@ define i8 @load_i8_from_i1() {
   %v = load i8, ptr @g_i1
   ret i8 %v
 }
+
+@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
+}