[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
Wed Oct 9 08:21:46 PDT 2024


================
@@ -0,0 +1,113 @@
+; 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() {
+; CHECK-LABEL: define double @logb_zero() {
+; CHECK-NEXT:    [[R:%.*]] = call double @logb(double 0.000000e+00)
+; CHECK-NEXT:    ret double [[R]]
+;
+  %r = call double @logb(double 0.000000e+00)
+  ret double %r
+}
+
+define float @logbf_neg_zero() {
+; CHECK-LABEL: define float @logbf_neg_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_neg_zero() {
+; CHECK-LABEL: define double @logb_neg_zero() {
+; CHECK-NEXT:    [[R:%.*]] = call double @logb(double -0.000000e+00)
+; CHECK-NEXT:    ret double [[R]]
+;
+  %r = call double @logb(double -0.000000e+00)
+  ret double %r
+}
+
+define float @logbf_inf() {
+; CHECK-LABEL: define float @logbf_inf() {
+; CHECK-NEXT:    [[R:%.*]] = call float @logbf(float 0x7FF0000000000000)
+; CHECK-NEXT:    ret float [[R]]
+;
+  %r = call float @logbf(float 0x7FF0000000000000)
+  ret float %r
+}
+
+define double @logb_inf() {
+; CHECK-LABEL: define double @logb_inf() {
+; CHECK-NEXT:    [[R:%.*]] = call double @logb(double 0x7FF0000000000000)
+; CHECK-NEXT:    ret double [[R]]
+;
+  %r = call double @logb(double 0x7FF0000000000000)
+  ret double %r
+}
+
+define float @logbf_nan() {
+; CHECK-LABEL: define float @logbf_nan() {
+; CHECK-NEXT:    [[R:%.*]] = call float @logbf(float 0x7FF8000000000000)
+; CHECK-NEXT:    ret float [[R]]
+;
+  %r = call float @logbf(float 0x7FF8000000000000)
+  ret float %r
+}
+
+define double @logb_nan() {
+; CHECK-LABEL: define double @logb_nan() {
+; CHECK-NEXT:    [[R:%.*]] = call double @logb(double 0x7FF8000000000000)
+; CHECK-NEXT:    ret double [[R]]
+;
+  %r = call double @logb(double 0x7FF8000000000000)
+  ret double %r
+}
+
+define float @logbf_poison() {
+; CHECK-LABEL: define float @logbf_poison() {
+; CHECK-NEXT:    [[R:%.*]] = call float @logbf(float poison)
+; CHECK-NEXT:    ret float [[R]]
+;
+  %r = call float @logbf(float poison)
+  ret float %r
+}
+
+define double @logb_poison() {
+; CHECK-LABEL: define double @logb_poison() {
+; CHECK-NEXT:    [[R:%.*]] = call double @logb(double poison)
+; CHECK-NEXT:    ret double [[R]]
+;
+  %r = call double @logb(double poison)
+  ret double %r
+}
+
----------------
c8ef wrote:

Thank you for your guidance! However, in this case, the non-finite argument is blocked by code in L2234 even before we reach the constant folding part for the `logb` function.

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


More information about the llvm-commits mailing list