[PATCH] D150422: [ConstantFolding] fold integers whose bitwidth is greater than 64.

Kohei Asano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 16 19:09:30 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0d67d9aedade: [ConstantFolding] fold integer bitwidth is greater than 63, and not multiple of… (authored by khei4).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150422/new/

https://reviews.llvm.org/D150422

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


Index: llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
+++ llvm/test/Transforms/InstSimplify/ConstProp/loads.ll
@@ -412,3 +412,12 @@
   %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
+}
Index: llvm/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/lib/Analysis/ConstantFolding.cpp
+++ llvm/lib/Analysis/ConstantFolding.cpp
@@ -429,18 +429,16 @@
     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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150422.522880.patch
Type: text/x-patch
Size: 1445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230517/a48fecf2/attachment.bin>


More information about the llvm-commits mailing list