[llvm] [SimplifyLibCalls] fdim constant fold (PR #109235)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 7 21:02:40 PDT 2024


================
@@ -0,0 +1,118 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define double @fdim_double() {
+; CHECK-LABEL: define double @fdim_double() {
+; CHECK-NEXT:    ret double 2.500000e+00
+;
+  %dim = call double @fdim(double 10.5, double 8.0)
+  ret double %dim
+}
+
+define double @fdim_double1() {
+; CHECK-LABEL: define double @fdim_double1() {
+; CHECK-NEXT:    ret double 0.000000e+00
+;
+  %dim = call double @fdim(double 7.0, double 8.0)
+  ret double %dim
+}
+
+define float @fdim_float() {
+; CHECK-LABEL: define float @fdim_float() {
+; CHECK-NEXT:    ret float 0.000000e+00
+;
+  %dim = call float @fdimf(float 1.500000e+00, float 8.0)
+  ret float %dim
+}
+
+define float @fdim_float1() {
+; CHECK-LABEL: define float @fdim_float1() {
+; CHECK-NEXT:    ret float 2.000000e+00
+;
+  %dim = call float @fdimf(float 1.000000e+01, float 8.0)
+  ret float %dim
+}
+
+define double @fdim_poison1() {
+; CHECK-LABEL: define double @fdim_poison1() {
+; CHECK-NEXT:    [[DIM:%.*]] = call double @fdim(double poison, double 1.000000e+00)
+; CHECK-NEXT:    ret double [[DIM]]
+;
+  %dim = call double @fdim(double poison, double 1.0)
+  ret double %dim
+}
+
+define double @fdim_poison2() {
+; CHECK-LABEL: define double @fdim_poison2() {
+; CHECK-NEXT:    [[DIM:%.*]] = call double @fdim(double 1.000000e+00, double poison)
+; CHECK-NEXT:    ret double [[DIM]]
+;
+  %dim = call double @fdim(double 1.0, double poison)
+  ret double %dim
+}
+
+define double @fdim_poison3() {
+; CHECK-LABEL: define double @fdim_poison3() {
+; CHECK-NEXT:    [[DIM:%.*]] = call double @fdim(double poison, double poison)
+; CHECK-NEXT:    ret double [[DIM]]
+;
+  %dim = call double @fdim(double poison, double poison)
+  ret double %dim
+}
+
+define double @fdim_undef1() {
+; CHECK-LABEL: define double @fdim_undef1() {
+; CHECK-NEXT:    [[DIM:%.*]] = call double @fdim(double undef, double 1.000000e+00)
+; CHECK-NEXT:    ret double [[DIM]]
+;
+  %dim = call double @fdim(double undef, double 1.0)
+  ret double %dim
+}
+
+define double @fdim_undef2() {
+; CHECK-LABEL: define double @fdim_undef2() {
+; CHECK-NEXT:    [[DIM:%.*]] = call double @fdim(double 1.000000e+00, double undef)
+; CHECK-NEXT:    ret double [[DIM]]
+;
+  %dim = call double @fdim(double 1.0, double undef)
+  ret double %dim
+}
+
+define double @fdim_undef3() {
+; CHECK-LABEL: define double @fdim_undef3() {
+; CHECK-NEXT:    [[DIM:%.*]] = call double @fdim(double undef, double undef)
+; CHECK-NEXT:    ret double [[DIM]]
+;
+  %dim = call double @fdim(double undef, double undef)
+  ret double %dim
+}
+
+define double @fdim_inf_ninf(){
+; CHECK-LABEL: define double @fdim_inf_ninf() {
+; CHECK-NEXT:    ret double 0x7FF0000000000000
+;
+  %dim = call double @fdim(double 0x7FF0000000000000, double 0x8000000000000000 )
+  ret double %dim
+}
+
+define double @fdim_inf(){
+; CHECK-LABEL: define double @fdim_inf() {
+; CHECK-NEXT:    [[DIM:%.*]] = call double @fdim(double 0x7FF0000000000000, double 0x7FF0000000000000)
+; CHECK-NEXT:    ret double [[DIM]]
+;
+  %dim = call double @fdim(double 0x7FF0000000000000, double 0x7FF0000000000000)
+  ret double %dim
+}
+
+define double @fdim_nzero(){
+; CHECK-LABEL: define double @fdim_nzero() {
+; CHECK-NEXT:    ret double 0.000000e+00
+;
+  %dim = call double @fdim(double -0.0, double +0.0)
+  ret double %dim
+}
+
+declare double @fdim(double, double) #0
+declare float @fdimf(float, float) #0
+
----------------
braw-lee wrote:

lib calls don't fold for strictfp cases, added test

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


More information about the llvm-commits mailing list