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

Kohei Asano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 15 07:03:41 PDT 2023


khei4 added a comment.

@nikic Thank you for the good catches!



================
Comment at: llvm/lib/Analysis/ConstantFolding.cpp:435
       return false;
-
-    uint64_t Val = CI->getZExtValue();
+    APInt Val = CI->getValue();
     unsigned IntBytes = unsigned(CI->getBitWidth()/8);
----------------
nikic wrote:
> 
Thanks! 


================
Comment at: llvm/test/Transforms/InstCombine/constant-fold.ll:2
+; 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
----------------
nikic wrote:
> This test can be moved to InstSimplify (shouldn't need InstCombine). There probably already is some load.ll or so file there.
Thanks! and about following case

```
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
}
```
InstSimplify somehow fold this on the current released opt https://llvm.godbolt.org/z/o5cz6ds99

so by changing the condition slightly, load 128-bit integer as 43-bit integer(I am not so sure why this happens.

```
define i43 @load-43bit(){
; CHECK-LABEL: @load-43bit(
; CHECK-NEXT:    [[TMP1:%.*]] = load i43, ptr @global128, align 4
; CHECK-NEXT:    ret i43 [[TMP1]]
;
  %1 = load i43, ptr @global128, align 4
  ret i43 %1
}
```


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

https://reviews.llvm.org/D150422



More information about the llvm-commits mailing list