[llvm] [ConstantFold] Fold `logb` and `logbf` when the input parameter is a constant value. (PR #111232)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 00:53:05 PDT 2024


================
@@ -0,0 +1,59 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define float @logbf_const() {
+; CHECK-LABEL: define float @logbf_const() {
+; CHECK-NEXT:    [[R:%.*]] = call float @logbf(float 7.000000e+00)
+; CHECK-NEXT:    ret float 2.000000e+00
+;
+  %r = call float @logbf(float 7.000000e+00)
+  ret float %r
+}
+
+define double @logb_const() {
+; CHECK-LABEL: define double @logb_const() {
+; CHECK-NEXT:    [[R:%.*]] = call double @logb(double -7.000000e+00)
+; CHECK-NEXT:    ret double 2.000000e+00
+;
+  %r = call double @logb(double -7.000000e+00)
+  ret double %r
+}
+
+define float @logbf_zero() {
+; CHECK-LABEL: define float @logbf_zero() {
+; CHECK-NEXT:    [[R:%.*]] = call float @logbf(float 0.000000e+00)
+; CHECK-NEXT:    ret float [[R]]
+;
+  %r = call float @logbf(float 0.000000e+00)
+  ret float %r
+}
+
+define double @logb_zero() {
----------------
c8ef wrote:

I'm a bit confused because the current annotation for these functions doesn't include `readnone`. Can you please provide more details to help me understand better?

https://github.com/llvm/llvm-project/blob/173841cc56a12410e6ca7e4a37151d7057c6d20f/llvm/test/Transforms/InferFunctionAttrs/annotate.ll#L646-L650

https://github.com/llvm/llvm-project/pull/111232


More information about the llvm-commits mailing list