[PATCH] D150422: [ConstantFolding] fold integers whose bitwidth is greater than 63.
Kohei Asano via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun May 14 22:59:43 PDT 2023
khei4 updated this revision to Diff 522049.
khei4 added a comment.
remove obsolete test changes
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150422/new/
https://reviews.llvm.org/D150422
Files:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstCombine/constant-fold.ll
Index: llvm/test/Transforms/InstCombine/constant-fold.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/constant-fold.ll
@@ -0,0 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+ at global128 = internal constant i128 1125899906842625
+ at global125 = internal constant i125 1125899906842625
+define i128 @load-128bit(){
+; CHECK-LABEL: define i128 @load-128bit() {
+; CHECK-NEXT: ret i128 1125899906842625
+;
+ %1 = load i128, ptr @global128, align 4
+ ret i128 %1
+}
+
+; TODO: Current ReadDataFromGlobal assumes only byte-sized integer
+define i125 @load-125bit(){
+; CHECK-LABEL: define i125 @load-125bit() {
+; CHECK-NEXT: ret i125 1125899906842625
+;
+ %1 = load i125, ptr @global125, align 4
+ ret i125 %1
+}
Index: llvm/lib/Analysis/ConstantFolding.cpp
===================================================================
--- llvm/lib/Analysis/ConstantFolding.cpp
+++ llvm/lib/Analysis/ConstantFolding.cpp
@@ -429,18 +429,17 @@
return true;
if (auto *CI = dyn_cast<ConstantInt>(C)) {
- if (CI->getBitWidth() > 64 ||
- (CI->getBitWidth() & 7) != 0)
+ // TODO: Adjust non-byte-sized integer
+ if ((CI->getBitWidth() & 7) != 0)
return false;
-
- uint64_t Val = CI->getZExtValue();
+ 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.522049.patch
Type: text/x-patch
Size: 1857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230515/39a5fd52/attachment.bin>
More information about the llvm-commits
mailing list