[PATCH] D128653: [PowerPC] Fix the check for scalar MASS conversion

2022-06-27 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei created this revision.
masoud.ataei added reviewers: bmahjour, renenkel, rzurob, w2yehia.
masoud.ataei added a project: PowerPC.
Herald added subscribers: shchenz, kbarton, hiraditya, nemanjai.
Herald added a project: All.
masoud.ataei requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Proposing to move the check for scalar MASS conversion from constructor 
of `PPCTargetLowering` to the `lowerLibCallBase` function which decides 
about the lowering.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128653

Files:
  clang/test/CodeGen/lower-mass-end-to-end.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h

Index: llvm/lib/Target/PowerPC/PPCISelLowering.h
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.h
+++ llvm/lib/Target/PowerPC/PPCISelLowering.h
@@ -1293,6 +1293,7 @@
 SelectionDAG &DAG) const;
 bool isLowringToMASSFiniteSafe(SDValue Op) const;
 bool isLowringToMASSSafe(SDValue Op) const;
+bool isScalarMASSConversionEnabled() const;
 SDValue lowerLibCallBase(const char *LibCallDoubleName,
  const char *LibCallFloatName,
  const char *LibCallDoubleNameFinite,
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -392,8 +392,7 @@
 
   // MASS transformation for LLVM intrinsics with replicating fast-math flag
   // to be consistent to PPCGenScalarMASSEntries pass
-  if (TM.getOptLevel() == CodeGenOpt::Aggressive &&
-  TM.Options.PPCGenScalarMASSEntries) {
+  if (TM.getOptLevel() == CodeGenOpt::Aggressive) {
 setOperationAction(ISD::FSIN , MVT::f64, Custom);
 setOperationAction(ISD::FCOS , MVT::f64, Custom);
 setOperationAction(ISD::FPOW , MVT::f64, Custom);
@@ -17886,13 +17885,17 @@
   return Op.getNode()->getFlags().hasApproximateFuncs();
 }
 
+bool PPCTargetLowering::isScalarMASSConversionEnabled() const {
+  return getTargetMachine().Options.PPCGenScalarMASSEntries;
+}
+
 SDValue PPCTargetLowering::lowerLibCallBase(const char *LibCallDoubleName,
 const char *LibCallFloatName,
 const char *LibCallDoubleNameFinite,
 const char *LibCallFloatNameFinite,
 SDValue Op,
 SelectionDAG &DAG) const {
-  if (!isLowringToMASSSafe(Op))
+  if (!isScalarMASSConversionEnabled() || !isLowringToMASSSafe(Op))
 return SDValue();
 
   if (!isLowringToMASSFiniteSafe(Op))
Index: clang/test/CodeGen/lower-mass-end-to-end.c
===
--- /dev/null
+++ clang/test/CodeGen/lower-mass-end-to-end.c
@@ -0,0 +1,114 @@
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-FAST
+
+extern double sin(double a);
+extern double cos(double a);
+extern double pow(double a, double b);
+extern double log(double a);
+extern double log10(double a);
+extern double exp(double a);
+extern float sinf(float a);
+extern float cosf(float a);
+extern float powf(float a, float b);
+extern float logf(float a);
+extern float log10f(float a);
+extern float expf(float a);
+
+double sin_f64(double a) {
+// CHECK-LABEL: sin_f64
+// CHECK-FAST: __xl_sin_finite
+// CHECK-AFN: __xl_sin
+// CHECK: blr
+  return sin(a);
+}
+
+double cos_f64(double a) {
+// CHECK-LABEL: cos_f64
+// CHECK-FAST: __xl_cos_finite
+// CHECK-AFN: __xl_cos
+// CHECK: blr
+  return cos(a);
+}
+
+double pow_f64(double a, double b) {
+// CHECK-LABEL: pow_f64
+// CHECK-FAST: __xl_pow_finite
+// CHECK-AFN: __xl_pow
+// CHECK: blr
+  return pow(a, b);
+}
+
+double log_f64(double a) {
+// CHECK-LABEL: log_f64
+// CHECK-FAST: __xl_log_finite
+// CHECK-AFN: __xl_log
+// CHECK: blr
+  return log(a);
+}
+
+double log10_f64(double a) {
+// CHECK-LABEL: log10_f64
+// CHECK-FAST: __xl_log10_finite
+// CHECK-AFN: __xl_log10
+// CHECK: blr
+  return log10(a);
+}
+
+double exp_f64(double a) {
+// CHECK-LABEL: exp_f64
+// CHECK-FAST: __xl_exp_finite
+// CHECK-AFN: __xl_exp
+// CHECK: blr
+  return exp(a);
+}
+
+float sin_f32(

[PATCH] D128653: [PowerPC] Fix the check for scalar MASS conversion

2022-06-27 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 440334.
masoud.ataei added a comment.

Add more tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128653

Files:
  clang/test/CodeGen/lower-mass-end-to-end.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h

Index: llvm/lib/Target/PowerPC/PPCISelLowering.h
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.h
+++ llvm/lib/Target/PowerPC/PPCISelLowering.h
@@ -1293,6 +1293,7 @@
 SelectionDAG &DAG) const;
 bool isLowringToMASSFiniteSafe(SDValue Op) const;
 bool isLowringToMASSSafe(SDValue Op) const;
+bool isScalarMASSConversionEnabled() const;
 SDValue lowerLibCallBase(const char *LibCallDoubleName,
  const char *LibCallFloatName,
  const char *LibCallDoubleNameFinite,
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -392,8 +392,7 @@
 
   // MASS transformation for LLVM intrinsics with replicating fast-math flag
   // to be consistent to PPCGenScalarMASSEntries pass
-  if (TM.getOptLevel() == CodeGenOpt::Aggressive &&
-  TM.Options.PPCGenScalarMASSEntries) {
+  if (TM.getOptLevel() == CodeGenOpt::Aggressive) {
 setOperationAction(ISD::FSIN , MVT::f64, Custom);
 setOperationAction(ISD::FCOS , MVT::f64, Custom);
 setOperationAction(ISD::FPOW , MVT::f64, Custom);
@@ -17886,13 +17885,17 @@
   return Op.getNode()->getFlags().hasApproximateFuncs();
 }
 
+bool PPCTargetLowering::isScalarMASSConversionEnabled() const {
+  return getTargetMachine().Options.PPCGenScalarMASSEntries;
+}
+
 SDValue PPCTargetLowering::lowerLibCallBase(const char *LibCallDoubleName,
 const char *LibCallFloatName,
 const char *LibCallDoubleNameFinite,
 const char *LibCallFloatNameFinite,
 SDValue Op,
 SelectionDAG &DAG) const {
-  if (!isLowringToMASSSafe(Op))
+  if (!isScalarMASSConversionEnabled() || !isLowringToMASSSafe(Op))
 return SDValue();
 
   if (!isLowringToMASSFiniteSafe(Op))
Index: clang/test/CodeGen/lower-mass-end-to-end.c
===
--- /dev/null
+++ clang/test/CodeGen/lower-mass-end-to-end.c
@@ -0,0 +1,147 @@
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST
+
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NOMASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NOMASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NOMASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NOMASS-FAST
+
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NOMASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NOMASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NOMASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NOMASS-FAST
+
+extern double sin(double a);
+extern double cos(double a);
+extern double pow(double a, double b);
+extern double log(double a);
+extern double log10(double a);
+extern double exp(double a);
+extern float sinf(float a);
+extern float cosf(float a);
+extern float powf(float a, float b);
+extern float logf(float a);
+extern float log10f(float a);
+extern float ex

[PATCH] D128653: [PowerPC] Fix the check for scalar MASS conversion

2022-06-28 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 440625.
masoud.ataei added a comment.

Test updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128653

Files:
  clang/test/CodeGen/lower-mass-end-to-end.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h

Index: llvm/lib/Target/PowerPC/PPCISelLowering.h
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.h
+++ llvm/lib/Target/PowerPC/PPCISelLowering.h
@@ -1293,6 +1293,7 @@
 SelectionDAG &DAG) const;
 bool isLowringToMASSFiniteSafe(SDValue Op) const;
 bool isLowringToMASSSafe(SDValue Op) const;
+bool isScalarMASSConversionEnabled() const;
 SDValue lowerLibCallBase(const char *LibCallDoubleName,
  const char *LibCallFloatName,
  const char *LibCallDoubleNameFinite,
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -392,8 +392,7 @@
 
   // MASS transformation for LLVM intrinsics with replicating fast-math flag
   // to be consistent to PPCGenScalarMASSEntries pass
-  if (TM.getOptLevel() == CodeGenOpt::Aggressive &&
-  TM.Options.PPCGenScalarMASSEntries) {
+  if (TM.getOptLevel() == CodeGenOpt::Aggressive) {
 setOperationAction(ISD::FSIN , MVT::f64, Custom);
 setOperationAction(ISD::FCOS , MVT::f64, Custom);
 setOperationAction(ISD::FPOW , MVT::f64, Custom);
@@ -17886,13 +17885,17 @@
   return Op.getNode()->getFlags().hasApproximateFuncs();
 }
 
+bool PPCTargetLowering::isScalarMASSConversionEnabled() const {
+  return getTargetMachine().Options.PPCGenScalarMASSEntries;
+}
+
 SDValue PPCTargetLowering::lowerLibCallBase(const char *LibCallDoubleName,
 const char *LibCallFloatName,
 const char *LibCallDoubleNameFinite,
 const char *LibCallFloatNameFinite,
 SDValue Op,
 SelectionDAG &DAG) const {
-  if (!isLowringToMASSSafe(Op))
+  if (!isScalarMASSConversionEnabled() || !isLowringToMASSSafe(Op))
 return SDValue();
 
   if (!isLowringToMASSFiniteSafe(Op))
Index: clang/test/CodeGen/lower-mass-end-to-end.c
===
--- /dev/null
+++ clang/test/CodeGen/lower-mass-end-to-end.c
@@ -0,0 +1,147 @@
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST
+
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+
+extern double sin(double a);
+extern double cos(double a);
+extern double pow(double a, double b);
+extern double log(double a);
+extern double log10(double a);
+extern double exp(double a);
+extern float sinf(float a);
+extern float cosf(float a);
+extern float powf(float a, float b);
+extern float logf(float a);
+extern float log10f(float a);
+extern fl

[PATCH] D128653: [PowerPC] Fix the check for scalar MASS conversion

2022-06-29 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 441170.
masoud.ataei added a comment.

Update the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128653

Files:
  clang/test/CodeGen/lower-mass-end-to-end.c
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h

Index: llvm/lib/Target/PowerPC/PPCISelLowering.h
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.h
+++ llvm/lib/Target/PowerPC/PPCISelLowering.h
@@ -1293,6 +1293,7 @@
 SelectionDAG &DAG) const;
 bool isLowringToMASSFiniteSafe(SDValue Op) const;
 bool isLowringToMASSSafe(SDValue Op) const;
+bool isScalarMASSConversionEnabled() const;
 SDValue lowerLibCallBase(const char *LibCallDoubleName,
  const char *LibCallFloatName,
  const char *LibCallDoubleNameFinite,
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -392,8 +392,7 @@
 
   // MASS transformation for LLVM intrinsics with replicating fast-math flag
   // to be consistent to PPCGenScalarMASSEntries pass
-  if (TM.getOptLevel() == CodeGenOpt::Aggressive &&
-  TM.Options.PPCGenScalarMASSEntries) {
+  if (TM.getOptLevel() == CodeGenOpt::Aggressive) {
 setOperationAction(ISD::FSIN , MVT::f64, Custom);
 setOperationAction(ISD::FCOS , MVT::f64, Custom);
 setOperationAction(ISD::FPOW , MVT::f64, Custom);
@@ -17886,13 +17885,17 @@
   return Op.getNode()->getFlags().hasApproximateFuncs();
 }
 
+bool PPCTargetLowering::isScalarMASSConversionEnabled() const {
+  return getTargetMachine().Options.PPCGenScalarMASSEntries;
+}
+
 SDValue PPCTargetLowering::lowerLibCallBase(const char *LibCallDoubleName,
 const char *LibCallFloatName,
 const char *LibCallDoubleNameFinite,
 const char *LibCallFloatNameFinite,
 SDValue Op,
 SelectionDAG &DAG) const {
-  if (!isLowringToMASSSafe(Op))
+  if (!isScalarMASSConversionEnabled() || !isLowringToMASSSafe(Op))
 return SDValue();
 
   if (!isLowringToMASSFiniteSafe(Op))
Index: clang/test/CodeGen/lower-mass-end-to-end.c
===
--- /dev/null
+++ clang/test/CodeGen/lower-mass-end-to-end.c
@@ -0,0 +1,147 @@
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-MASS-FAST
+
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -O3 -fapprox-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass=false -Ofast --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc64le-unknown-linux-gnu -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -O3 -fno-approx-func --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-AFN
+// RUN: %clang -mllvm -enable-ppc-gen-scalar-mass -fno-fast-math --target=powerpc-ibm-aix-xcoff -S %s -o -| FileCheck %s -check-prefix=CHECK-NO-MASS-FAST
+
+extern double sin(double a);
+extern double cos(double a);
+extern double pow(double a, double b);
+extern double log(double a);
+extern double log10(double a);
+extern double exp(double a);
+extern float sinf(float a);
+extern float cosf(float a);
+extern float powf(float a, float b);
+extern float logf(float a);
+extern float log10f(float a);
+extern 

[PATCH] D128653: [PowerPC] Fix the check for scalar MASS conversion

2022-07-06 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added a comment.

Just took it down temporarily. -- Looking at it...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128653

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128653: [PowerPC] Fix the check for scalar MASS conversion

2022-07-06 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added a comment.

In D128653#3633704 , @lenary wrote:

> You likely need `// REQUIRES: powerpc-registered-target` in the top of the 
> test, as `-enable-ppc-gen-scalar-mass` is only present if the PowerPC target 
> has been compiled into LLVM.

Thanks, I was looking for that. -- re-committing...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128653

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101759: [PowerPC] Scalar IBM MASS library conversion pass

2021-07-16 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 359385.
masoud.ataei added a comment.

Removed clang changes from this PR.
Removed extra option for MASS pass.
Now MASS pass is active with -O3 and approx-func option.

Adding another PR for clang changes on approx-func option.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101759

Files:
  llvm/include/llvm/Analysis/ScalarFuncs.def
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/Target/PowerPC/CMakeLists.txt
  llvm/lib/Target/PowerPC/PPC.h
  llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/test/CodeGen/PowerPC/lower-intrinsics-afn-mass.ll
  llvm/test/CodeGen/PowerPC/lower-intrinsics-fast-mass.ll
  llvm/test/CodeGen/PowerPC/lower-intrinsics-mass-aix.ll
  llvm/test/CodeGen/PowerPC/lower-intrinsics-nofast-mass.ll
  llvm/test/CodeGen/PowerPC/lower-scalar-mass-afn.ll
  llvm/test/CodeGen/PowerPC/lower-scalar-mass-fast.ll
  llvm/test/CodeGen/PowerPC/pow-025-075-intrinsic-scalar-mass-afn.ll
  llvm/test/CodeGen/PowerPC/pow-025-075-intrinsic-scalar-mass-fast.ll
  llvm/test/CodeGen/PowerPC/pow-025-075-nointrinsic-scalar-mass-fast.ll

Index: llvm/test/CodeGen/PowerPC/pow-025-075-nointrinsic-scalar-mass-fast.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/pow-025-075-nointrinsic-scalar-mass-fast.ll
@@ -0,0 +1,456 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -O3 -enable-approx-func-fp-math -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck --check-prefix=CHECK-LNX %s
+; RUN: llc -verify-machineinstrs -O3 -enable-approx-func-fp-math -mtriple=powerpc-ibm-aix-xcoff < %s | FileCheck --check-prefix=CHECK-AIX %s
+
+declare float @powf (float, float);
+declare double @pow (double, double);
+declare float @__powf_finite (float, float);
+declare double @__pow_finite (double, double);
+
+; fast-math powf with 0.25
+define float @powf_f32_fast025(float %a) #1 {
+;
+; CHECK-LNX-LABEL: powf_f32_fast025:
+; CHECK-LNX:   # %bb.0: # %entry
+; CHECK-LNX-NEXT:mflr 0
+; CHECK-LNX-NEXT:std 0, 16(1)
+; CHECK-LNX-NEXT:stdu 1, -32(1)
+; CHECK-LNX-NEXT:.cfi_def_cfa_offset 32
+; CHECK-LNX-NEXT:.cfi_offset lr, 16
+; CHECK-LNX-NEXT:addis 3, 2, .LCPI0_0@toc@ha
+; CHECK-LNX-NEXT:lfs 2, .LCPI0_0@toc@l(3)
+; CHECK-LNX-NEXT:bl __xl_powf_finite
+; CHECK-LNX-NEXT:nop
+; CHECK-LNX-NEXT:addi 1, 1, 32
+; CHECK-LNX-NEXT:ld 0, 16(1)
+; CHECK-LNX-NEXT:mtlr 0
+; CHECK-LNX-NEXT:blr
+;
+; CHECK-AIX-LABEL: powf_f32_fast025:
+; CHECK-AIX:   # %bb.0: # %entry
+; CHECK-AIX-NEXT:mflr 0
+; CHECK-AIX-NEXT:stw 0, 8(1)
+; CHECK-AIX-NEXT:stwu 1, -64(1)
+; CHECK-AIX-NEXT:lwz 3, L..C0(2) # %const.0
+; CHECK-AIX-NEXT:lfs 2, 0(3)
+; CHECK-AIX-NEXT:bl .__xl_powf_finite[PR]
+; CHECK-AIX-NEXT:nop
+; CHECK-AIX-NEXT:addi 1, 1, 64
+; CHECK-AIX-NEXT:lwz 0, 8(1)
+; CHECK-AIX-NEXT:mtlr 0
+; CHECK-AIX-NEXT:blr
+entry:
+  %call = tail call nnan ninf afn nsz float @powf(float %a, float 2.50e-01)
+  ret float %call
+}
+
+; fast-math pow with 0.25
+define double @pow_f64_fast025(double %a) #1 {
+;
+; CHECK-LNX-LABEL: pow_f64_fast025:
+; CHECK-LNX:   # %bb.0: # %entry
+; CHECK-LNX-NEXT:mflr 0
+; CHECK-LNX-NEXT:std 0, 16(1)
+; CHECK-LNX-NEXT:stdu 1, -32(1)
+; CHECK-LNX-NEXT:.cfi_def_cfa_offset 32
+; CHECK-LNX-NEXT:.cfi_offset lr, 16
+; CHECK-LNX-NEXT:addis 3, 2, .LCPI1_0@toc@ha
+; CHECK-LNX-NEXT:lfs 2, .LCPI1_0@toc@l(3)
+; CHECK-LNX-NEXT:bl __xl_pow_finite
+; CHECK-LNX-NEXT:nop
+; CHECK-LNX-NEXT:addi 1, 1, 32
+; CHECK-LNX-NEXT:ld 0, 16(1)
+; CHECK-LNX-NEXT:mtlr 0
+; CHECK-LNX-NEXT:blr
+;
+; CHECK-AIX-LABEL: pow_f64_fast025:
+; CHECK-AIX:   # %bb.0: # %entry
+; CHECK-AIX-NEXT:mflr 0
+; CHECK-AIX-NEXT:stw 0, 8(1)
+; CHECK-AIX-NEXT:stwu 1, -64(1)
+; CHECK-AIX-NEXT:lwz 3, L..C1(2) # %const.0
+; CHECK-AIX-NEXT:lfs 2, 0(3)
+; CHECK-AIX-NEXT:bl .__xl_pow_finite[PR]
+; CHECK-AIX-NEXT:nop
+; CHECK-AIX-NEXT:addi 1, 1, 64
+; CHECK-AIX-NEXT:lwz 0, 8(1)
+; CHECK-AIX-NEXT:mtlr 0
+; CHECK-AIX-NEXT:blr
+entry:
+  %call = tail call nnan ninf afn nsz double @pow(double %a, double 2.50e-01)
+  ret double %call
+}
+
+; fast-math powf with 0.75
+define float @powf_f32_fast075(float %a) #1 {
+;
+; CHECK-LNX-LABEL: powf_f32_fast075:
+; CHECK-LNX:   # %bb.0: # %entry
+; CHECK-LNX-NEXT:mflr 0
+; CHECK-LNX-NEXT:std 0, 16(1)
+; CHECK-LNX-NEXT:stdu 1, -32(1)
+; CHECK-LNX-NEXT:.cfi_def_cfa_offset 32
+; CHECK-LNX-NEXT:.cfi_offset lr, 16
+; CHECK-LNX-NEXT:addis 3, 2, .LCPI2_0@toc@ha
+; CHECK-LNX-NEXT:lfs 2, .LCPI2_0@toc@l(3)

[PATCH] D101759: [PowerPC] Scalar IBM MASS library conversion pass

2021-07-16 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei marked 9 inline comments as done.
masoud.ataei added inline comments.



Comment at: llvm/lib/Target/PowerPC/PPCISelLowering.cpp:1370
+  // to be consistent to PPCGenScalarMASSEntries pass
+  if (TM.Options.PPCGenScalarMASSEntries && TM.Options.ApproxFuncFPMath) {
+if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath &&

bmahjour wrote:
> if someone compiles with -Ofast without any extra options, would 
> `TM.Options.ApproxFuncFPMath` be true here?
In clang changes, I had `Options.ApproxFuncFPMath = LangOpts.ApproxFunc;` in 
`clang/lib/CodeGen/BackendUtil.cpp`. That was responsible to update this TM 
option based on the clang approximate func option. And clang approximate func 
option will be set with -Ofast. 

Then, the answer for your question is yes. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101759

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106191: [clang] Option control afn flag

2021-07-16 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei created this revision.
masoud.ataei added reviewers: bmahjour, Whitney, nemanjai, shchenz.
masoud.ataei added projects: clang, LLVM.
Herald added subscribers: ormris, dang.
masoud.ataei requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits.

Proposing an clang option to control afn flag.

This change is proposed as a support for: https://reviews.llvm.org/D101759


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106191

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/afn-flag-test.c
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/Target/TargetOptions.h

Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -115,7 +115,7 @@
 TargetOptions()
 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
   NoTrappingFPMath(true), NoSignedZerosFPMath(false),
-  EnableAIXExtendedAltivecABI(false),
+  ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
   HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
   GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
   EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
@@ -172,6 +172,12 @@
 /// argument or result as insignificant.
 unsigned NoSignedZerosFPMath : 1;
 
+/// ApproxFuncFPMath - This flag is enabled when the
+/// -enable-approx-func-fp-math is specified on the command line. This
+/// specifies that optimizations are allowed to substitute math functions
+/// with approximate calculations
+unsigned ApproxFuncFPMath : 1;
+
 /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
 /// specified. The code generator is then able to use both volatile and
 /// nonvolitle vector regisers. When false, the code generator only uses
Index: llvm/include/llvm/CodeGen/CommandFlags.h
===
--- llvm/include/llvm/CodeGen/CommandFlags.h
+++ llvm/include/llvm/CodeGen/CommandFlags.h
@@ -63,6 +63,8 @@
 
 bool getEnableNoSignedZerosFPMath();
 
+bool getEnableApproxFuncFPMath();
+
 bool getEnableNoTrappingFPMath();
 
 DenormalMode::DenormalModeKind getDenormalFPMath();
Index: clang/test/CodeGen/afn-flag-test.c
===
--- /dev/null
+++ clang/test/CodeGen/afn-flag-test.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fapprox-func  %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-AFN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-NO-AFN %s
+
+extern double exp(double);
+double afn_option_test(double x) {
+  return exp(x);
+  // CHECK-LABEL:  define{{.*}} double @afn_option_test(double %x) #0 {
+
+  // CHECK-AFN:  %{{.*}} = call afn double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-AFN:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+
+  // CHECK-NO-AFN:   %{{.*}} = call double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-NO-AFN-NOT:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2616,6 +2616,7 @@
   // LLVM flags based on the final state.
   bool HonorINFs = true;
   bool HonorNaNs = true;
+  bool ApproxFunc = false;
   // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes.
   bool MathErrno = TC.IsMathErrnoDefault();
   bool AssociativeMath = false;
@@ -2720,6 +2721,8 @@
 case options::OPT_fno_honor_infinities: HonorINFs = false;break;
 case options::OPT_fhonor_nans:  HonorNaNs = true; break;
 case options::OPT_fno_honor_nans:   HonorNaNs = false;break;
+case options::OPT_fapprox_func: ApproxFunc = true;break;
+case options::OPT_fno_approx_func:  ApproxFunc = false;   break;
 case options::OPT_fmath_errno:  MathErrno = true; break;
 case options::OPT_fno_math_errno:   MathErrno = false;break;
 case options::OPT_fassociative_math:AssociativeMath = true;   break;
@@ -2915,6 +2918,9 @@
   if (!HonorNaNs)
 CmdArgs.push_back("-menable-no-nans");
 
+  if (ApproxFunc)
+CmdArgs.push_back("-fapprox-func");
+
   if (MathErrno)
 CmdArgs.push_back("-fmath-errno");
 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1814,6 +1814,8 @@
   FuncAttrs.addAttribute("no-infs-fp-math", "true");
 if (LangOpts.NoHonorNaNs)

[PATCH] D106191: [clang] Option control afn flag

2021-07-16 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 359454.
masoud.ataei added a comment.

Remove extra function deceleration.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/afn-flag-test.c
  llvm/include/llvm/Target/TargetOptions.h

Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -115,7 +115,7 @@
 TargetOptions()
 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
   NoTrappingFPMath(true), NoSignedZerosFPMath(false),
-  EnableAIXExtendedAltivecABI(false),
+  ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
   HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
   GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
   EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
@@ -172,6 +172,12 @@
 /// argument or result as insignificant.
 unsigned NoSignedZerosFPMath : 1;
 
+/// ApproxFuncFPMath - This flag is enabled when the
+/// -enable-approx-func-fp-math is specified on the command line. This
+/// specifies that optimizations are allowed to substitute math functions
+/// with approximate calculations
+unsigned ApproxFuncFPMath : 1;
+
 /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
 /// specified. The code generator is then able to use both volatile and
 /// nonvolitle vector regisers. When false, the code generator only uses
Index: clang/test/CodeGen/afn-flag-test.c
===
--- /dev/null
+++ clang/test/CodeGen/afn-flag-test.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fapprox-func  %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-AFN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-NO-AFN %s
+
+extern double exp(double);
+double afn_option_test(double x) {
+  return exp(x);
+  // CHECK-LABEL:  define{{.*}} double @afn_option_test(double %x) #0 {
+
+  // CHECK-AFN:  %{{.*}} = call afn double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-AFN:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+
+  // CHECK-NO-AFN:   %{{.*}} = call double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-NO-AFN-NOT:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2616,6 +2616,7 @@
   // LLVM flags based on the final state.
   bool HonorINFs = true;
   bool HonorNaNs = true;
+  bool ApproxFunc = false;
   // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes.
   bool MathErrno = TC.IsMathErrnoDefault();
   bool AssociativeMath = false;
@@ -2720,6 +2721,8 @@
 case options::OPT_fno_honor_infinities: HonorINFs = false;break;
 case options::OPT_fhonor_nans:  HonorNaNs = true; break;
 case options::OPT_fno_honor_nans:   HonorNaNs = false;break;
+case options::OPT_fapprox_func: ApproxFunc = true;break;
+case options::OPT_fno_approx_func:  ApproxFunc = false;   break;
 case options::OPT_fmath_errno:  MathErrno = true; break;
 case options::OPT_fno_math_errno:   MathErrno = false;break;
 case options::OPT_fassociative_math:AssociativeMath = true;   break;
@@ -2915,6 +2918,9 @@
   if (!HonorNaNs)
 CmdArgs.push_back("-menable-no-nans");
 
+  if (ApproxFunc)
+CmdArgs.push_back("-fapprox-func");
+
   if (MathErrno)
 CmdArgs.push_back("-fmath-errno");
 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1814,6 +1814,8 @@
   FuncAttrs.addAttribute("no-infs-fp-math", "true");
 if (LangOpts.NoHonorNaNs)
   FuncAttrs.addAttribute("no-nans-fp-math", "true");
+if (LangOpts.ApproxFunc)
+  FuncAttrs.addAttribute("approx-func-fp-math", "true");
 if (LangOpts.UnsafeFPMath)
   FuncAttrs.addAttribute("unsafe-fp-math", "true");
 if (CodeGenOpts.SoftFloat)
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -534,6 +534,7 @@
   Options.NoNaNsFPMath = LangOpts.NoHonorNaNs;
   Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
   Options.UnsafeFPMath = LangOpts.UnsafeFPMath;
+  Options.ApproxFuncFPMath = L

[PATCH] D106191: [clang] Option control afn flag

2021-09-28 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei marked 4 inline comments as done.
masoud.ataei added a comment.

Sorry that it took me so long to reply reviews. Thank you for reviewing this 
patch.




Comment at: clang/include/clang/Driver/Options.td:1732-1733
   NegFlag>;
-def fapprox_func : Flag<["-"], "fapprox-func">, Group, 
Flags<[CC1Option, NoDriverOption]>,
-  MarshallingInfoFlag>, 
ImpliedByAnyOf<[menable_unsafe_fp_math.KeyPath]>;
 defm finite_math_only : BoolFOption<"finite-math-only",

bmahjour wrote:
> So this option already exists and seems to behave the way we want it to. Does 
> anyone know why it was made `NoDriverOption`?
> 
> ```
> > cat fp.c
> #include 
> void foo(float *f1, float *f2)
> {
>   *f1 = sin(*f2) + *f1;
> }
> > clang -c fp.c -S -emit-llvm -mllvm -disable-llvm-optzns -O3 -Xclang 
> > -fapprox-func && grep afn fp.ll
>   %call = call afn double @sin(double %conv) #2
>   %add = fadd afn double %call, %conv1
> ```
> 
> Could we just expose it as a supported option and call it done. ie make it 
> more like `fhonor_nans` below but without introducing a new function 
> attribute:
> 
> ```def fapprox_func : Flag<["-"], "fapprox-func">, Group;```
> 
> so that instead of having `-Xclang -fapprox-func ` in the command above we 
> could just have `-fapprox-func `?
With the change that I proposed for `approx_func` option, we don't need to pass 
it with `-Xclang`. So, in your example, we can simply remove `-Xclang` and it 
will work the same:
```
> clang -c fp.c -S -emit-llvm -mllvm -disable-llvm-optzns -O3 -fapprox-func && 
> grep afn fp.ll
  %call = call afn double @sin(double %conv) #2
  %add = fadd afn double %call, %conv1
```
(even no need for ` -mllvm -disable-llvm-optzns -O3`)

Example for `-fapprox-func` and `-fno-approx-func`:
```
$ clang -c fp.c -S -emit-llvm -fapprox-func && grep afn fp.ll
  %call = call afn double @sin(double %conv) #2
  %add = fadd afn double %call, %conv1
$ clang -c fp.c -S -emit-llvm -fno-approx-func && grep afn fp.ll
$
```



Comment at: clang/lib/CodeGen/CGCall.cpp:1818
+if (LangOpts.ApproxFunc)
+  FuncAttrs.addAttribute("approx-func-fp-math", "true");
 if (LangOpts.UnsafeFPMath)

Regarding the attributes discussion below, here is place that attributes are 
added. 



Comment at: clang/test/CodeGen/afn-flag-test.c:10
+  // CHECK-AFN:  %{{.*}} = call afn double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-AFN:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+

bmahjour wrote:
> can we avoid these attributes?
I understand that attributes are less desirable now in LLVM. But all other 
options for fast-math flags (`-fhonor-nans`, `-fhonor_infinities`, ...) add the 
attributes too. So, to be consistent with others I added this attribute too. 

Example: This will add `"no-nans-fp-math"="true"` attribute along with `nnan` 
flag. 
```
$ clang -c fp.c -S -emit-llvm -fno-honor-nans
```




Comment at: clang/test/CodeGen/afn-flag-test.c:13
+  // CHECK-NO-AFN:   %{{.*}} = call double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-NO-AFN-NOT:  attributes #0 ={{.*}} "approx-func-fp-math"="true" 
{{.*}}
+}

bmahjour wrote:
> avoid attributes.
Same as above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114564: Fix the use of -fno-approx-func along with -Ofast or -ffast-math

2021-11-24 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei created this revision.
masoud.ataei added reviewers: andrew.w.kaylor, aaron.ballman, erichkeane, 
bmahjour.
masoud.ataei added a project: clang.
masoud.ataei requested review of this revision.
Herald added a subscriber: cfe-commits.

Fining the bug number Bug 52565: https://bugs.llvm.org/show_bug.cgi?id=52565


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D114564

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/fast-math.c
  clang/test/Preprocessor/aarch64-target-features.c
  clang/test/Preprocessor/arm-target-features.c

Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -267,7 +267,7 @@
 // CHECK-DEFS:#define __ARM_SIZEOF_WCHAR_T 4
 
 // RUN: %clang -target arm-none-linux-gnu -fno-math-errno -fno-signed-zeros\
-// RUN:-fno-trapping-math -fassociative-math -freciprocal-math\
+// RUN:-fno-trapping-math -fassociative-math -freciprocal-math -fapprox-func\
 // RUN:-x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s
 // RUN: %clang -target arm-none-linux-gnu -ffast-math -x c -E -dM %s -o -\
 // RUN:| FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s
Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -115,7 +115,7 @@
 // CHECK-CRC32: __ARM_FEATURE_CRC32 1
 
 // RUN: %clang -target aarch64-none-linux-gnu -fno-math-errno -fno-signed-zeros\
-// RUN:-fno-trapping-math -fassociative-math -freciprocal-math\
+// RUN:-fno-trapping-math -fassociative-math -freciprocal-math -fapprox-func\
 // RUN:-x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
 // RUN: %clang -target aarch64-none-linux-gnu -ffast-math -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
 // RUN: %clang -target arm64-none-linux-gnu -ffast-math -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
Index: clang/test/Driver/fast-math.c
===
--- clang/test/Driver/fast-math.c
+++ clang/test/Driver/fast-math.c
@@ -130,14 +130,14 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
 //
 // RUN: %clang -### -fno-math-errno -fassociative-math -freciprocal-math \
-// RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
+// RUN: -fno-signed-zeros -fno-trapping-math -fapprox-func -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
 // CHECK-UNSAFE-MATH: "-cc1"
 // CHECK-UNSAFE-MATH: "-menable-unsafe-fp-math"
 // CHECK-UNSAFE-MATH: "-mreassociate"
 //
 // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \
-// RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
+// RUN: -fno-signed-zeros -fno-trapping-math -fapprox-func -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-UNSAFE-MATH %s
 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-cc1"
 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-menable-unsafe-fp-math"
@@ -178,7 +178,7 @@
 // RUN: -fno-math-errno -ffp-contract=fast -fno-rounding-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
 // RUN: %clang -### -fno-honor-infinities -fno-honor-nans -fno-math-errno \
-// RUN: -fassociative-math -freciprocal-math -fno-signed-zeros \
+// RUN: -fassociative-math -freciprocal-math -fno-signed-zeros -fapprox-func \
 // RUN: -fno-trapping-math -ffp-contract=fast -fno-rounding-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
 // CHECK-FAST-MATH: "-cc1"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2873,6 +2873,7 @@
   AssociativeMath = true;
   ReciprocalMath = true;
   SignedZeros = false;
+  ApproxFunc = true;
   TrappingMath = false;
   FPExceptionBehavior = "";
   break;
@@ -2899,6 +2900,7 @@
   MathErrno = false;
   AssociativeMath = true;
   ReciprocalMath = true;
+  ApproxFunc = true;
   SignedZeros = false;
   TrappingMath = false;
   RoundingFPMath = false;
@@ -2914,6 +2916,7 @@
   MathErrno = TC.IsMathErrnoDefault();
   AssociativeMath = false;
   ReciprocalMath = false;
+  ApproxFunc = false;
   SignedZeros = true;
   // -fno_fast_math restores default denormal and fpcontract handling
   DenormalFPMath = DefaultDenormalFPMath;
@@ -2965,7 +2968,7 @@
 CmdArgs.push_back("-fmath-errno");
 
   if (!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros &&
-  !TrappingMath)
+  ApproxFunc && !TrappingMath)
 CmdArgs.push_bac

[PATCH] D114564: Fix the use of -fno-approx-func along with -Ofast or -ffast-math

2021-11-25 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 389820.
masoud.ataei edited the summary of this revision.
masoud.ataei added a comment.

Updated the test combining -ffast-math and -fno-approx-func options.
@andrew.w.kaylor I hope you don't mind that I put those tests on 
`clang/test/Driver/fast-math.c` instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114564

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/fast-math.c
  clang/test/Preprocessor/aarch64-target-features.c
  clang/test/Preprocessor/arm-target-features.c

Index: clang/test/Preprocessor/arm-target-features.c
===
--- clang/test/Preprocessor/arm-target-features.c
+++ clang/test/Preprocessor/arm-target-features.c
@@ -267,7 +267,7 @@
 // CHECK-DEFS:#define __ARM_SIZEOF_WCHAR_T 4
 
 // RUN: %clang -target arm-none-linux-gnu -fno-math-errno -fno-signed-zeros\
-// RUN:-fno-trapping-math -fassociative-math -freciprocal-math\
+// RUN:-fno-trapping-math -fassociative-math -freciprocal-math -fapprox-func\
 // RUN:-x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s
 // RUN: %clang -target arm-none-linux-gnu -ffast-math -x c -E -dM %s -o -\
 // RUN:| FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s
Index: clang/test/Preprocessor/aarch64-target-features.c
===
--- clang/test/Preprocessor/aarch64-target-features.c
+++ clang/test/Preprocessor/aarch64-target-features.c
@@ -115,7 +115,7 @@
 // CHECK-CRC32: __ARM_FEATURE_CRC32 1
 
 // RUN: %clang -target aarch64-none-linux-gnu -fno-math-errno -fno-signed-zeros\
-// RUN:-fno-trapping-math -fassociative-math -freciprocal-math\
+// RUN:-fno-trapping-math -fassociative-math -freciprocal-math -fapprox-func\
 // RUN:-x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
 // RUN: %clang -target aarch64-none-linux-gnu -ffast-math -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
 // RUN: %clang -target arm64-none-linux-gnu -ffast-math -x c -E -dM %s -o - | FileCheck --check-prefix=CHECK-FASTMATH %s
Index: clang/test/Driver/fast-math.c
===
--- clang/test/Driver/fast-math.c
+++ clang/test/Driver/fast-math.c
@@ -70,6 +70,23 @@
 // CHECK-NO-NANS-NO-FAST-MATH: "-cc1"
 // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans"
 //
+// RUN: %clang -### -ffast-math -fno-approx-func -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH-NO-APPROX-FUNC %s
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-cc1"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-menable-no-infs"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-menable-no-nans"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-fno-signed-zeros"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-mreassociate"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-freciprocal-math"
+// CHECK-FAST-MATH-NO-APPROX-FUNC: "-ffp-contract=fast"
+// CHECK-FAST-MATH-NO-APPROX-FUNC-NOT: "-ffast-math"
+// CHECK-FAST-MATH-NO-APPROX-FUNC-NOT: "-fapprox-func"
+//
+// RUN: %clang -### -fno-approx-func -ffast-math -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-APPROX-FUNC-FAST-MATH %s
+// CHECK-NO-APPROX-FUNC-FAST-MATH: "-cc1"
+// CHECK-NO-APPROX-FUNC-FAST-MATH: "-ffast-math"
+//
 // RUN: %clang -### -fapprox-func -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-APPROX-FUNC %s
 // CHECK-APPROX-FUNC: "-cc1"
@@ -130,14 +147,14 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NO-MATH-ERRNO %s
 //
 // RUN: %clang -### -fno-math-errno -fassociative-math -freciprocal-math \
-// RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
+// RUN: -fno-signed-zeros -fno-trapping-math -fapprox-func -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-UNSAFE-MATH %s
 // CHECK-UNSAFE-MATH: "-cc1"
 // CHECK-UNSAFE-MATH: "-menable-unsafe-fp-math"
 // CHECK-UNSAFE-MATH: "-mreassociate"
 //
 // RUN: %clang -### -fno-fast-math -fno-math-errno -fassociative-math -freciprocal-math \
-// RUN: -fno-signed-zeros -fno-trapping-math -c %s 2>&1 \
+// RUN: -fno-signed-zeros -fno-trapping-math -fapprox-func -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-FAST-MATH-UNSAFE-MATH %s
 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-cc1"
 // CHECK-NO-FAST-MATH-UNSAFE-MATH: "-menable-unsafe-fp-math"
@@ -178,7 +195,7 @@
 // RUN: -fno-math-errno -ffp-contract=fast -fno-rounding-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MATH %s
 // RUN: %clang -### -fno-honor-infinities -fno-honor-nans -fno-math-errno \
-// RUN: -fassociative-math -freciprocal-math -fno-signed-zeros \
+// RUN: -fassociative-math -freciprocal-math -fno-signed-zeros -fapprox-func \
 // RUN: -fno-trapping-math -ffp-contract=fast -fno-rounding-math -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-FAST-MAT

[PATCH] D114564: Fix the use of -fno-approx-func along with -Ofast or -ffast-math

2021-11-25 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei marked 2 inline comments as done.
masoud.ataei added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2760
 case options::OPT_fno_honor_nans:   HonorNaNs = false;break;
 case options::OPT_fapprox_func: ApproxFunc = true;break;
 case options::OPT_fno_approx_func:  ApproxFunc = false;   break;

andrew.w.kaylor wrote:
> Should this also imply "MathErrno = false"?
I don't think setting ApproxFunc to true should imply "MathErrno = false". 

Let say someone have a math library that compute approximate result for none 
special input/output but returns NaN, INF and errno correctly otherwise. That 
is actually can be fairly common, because performance in the none special cases 
are much more important that the special ones. So returning errno in the 
special outputs theoretically should not effect the performance on the main 
path. Therefore, I think compiler should not assume anything about MathErrno 
value based on ApproxFunc value.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2762
 case options::OPT_fno_approx_func:  ApproxFunc = false;   break;
 case options::OPT_fmath_errno:  MathErrno = true; break;
 case options::OPT_fno_math_errno:   MathErrno = false;break;

andrew.w.kaylor wrote:
> Should this conflict with -fapprox-func?
Same as above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114564

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138109: [clang] Fix -fp-model={strict|precise} to disable -fapprox-func

2022-11-16 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei accepted this revision.
masoud.ataei added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138109

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101759: [PowerPC] Scalar IBM MASS library conversion pass

2022-01-28 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei marked 7 inline comments as done.
masoud.ataei added inline comments.



Comment at: llvm/lib/Target/PowerPC/PPCISelLowering.cpp:386
+  if (TM.getOptLevel() == CodeGenOpt::Aggressive){
+setOperationAction(ISD::FSIN , MVT::f64, Custom);
+setOperationAction(ISD::FCOS , MVT::f64, Custom);

bmahjour wrote:
> what about tan, acos, and the others?
These are the list of math functions that llvm creates intrinsic call for them. 
There is no llvm intrinsic for tan, acos and other math functions which (exist 
in MASS and) are not in this list. 



Comment at: llvm/test/CodeGen/PowerPC/lower-intrinsics-afn-mass.ll:148
+
+attributes #1 = { "approx-func-fp-math"="true" }

bmahjour wrote:
> All the calls have `afn`why do we need this attribute? 
Removed



Comment at: llvm/test/CodeGen/PowerPC/lower-intrinsics-fast-mass.ll:148
+
+attributes #1 = { "no-infs-fp-math"="true" "no-nans-fp-math"="true" 
"no-signed-zeros-fp-math"="true" "approx-func-fp-math"="true" }

bmahjour wrote:
> do we need this attribute? Can we remove it or have separate tests for 
> functions with attributes?
Removed



Comment at: llvm/test/CodeGen/PowerPC/lower-intrinsics-mass-aix.ll:1
+; RUN: llc -O3 -mtriple=powerpc-ibm-aix-xcoff < %s | FileCheck %s
+

bmahjour wrote:
> We don't really need a separate aix file. Can we just add a run line with the 
> aix triple to `llvm/test/CodeGen/PowerPC/lower-intrinsics-nofast-mass.ll`?
Done



Comment at: llvm/test/CodeGen/PowerPC/lower-scalar-mass-fast.ll:796
+; Without nnan ninf afn nsz flags on the call instruction
+define float @acosf_f32_nofast(float %a) {
+; CHECK-LABEL: acosf_f32_nofast

bmahjour wrote:
> shouldn't the tests starting from here move to a different file? This test 
> file is called  ...mass-fast.ll so one would expect it only contains tests 
> with fast-math flag on.
Done



Comment at: 
llvm/test/CodeGen/PowerPC/pow-025-075-intrinsic-scalar-mass-fast.ll:246
+; CHECK-LNX-NEXT:lfs 2, .LCPI4_0@toc@l(3)
+; CHECK-LNX-NEXT:bl __xl_powf_finite
+; CHECK-LNX-NEXT:nop

bmahjour wrote:
> How come pow -> sqrt conversion didn't happen here? 
Honestly, I am not sure why the conversion is not happening in this case. But 
without this patch we will get `powf` call (the conversion is not happening 
again). So this is a separate issue that someone needs to look at independent 
of this patch.



Comment at: 
llvm/test/CodeGen/PowerPC/pow-025-075-nointrinsic-scalar-mass-fast.ll:22
+; CHECK-LNX-NEXT:lfs 2, .LCPI0_0@toc@l(3)
+; CHECK-LNX-NEXT:bl __xl_powf_finite
+; CHECK-LNX-NEXT:nop

bmahjour wrote:
> so pow->sqrt translation never happens for non-intrinsic `pow`. Is that 
> expected? If so, are we planning to recognize these patterns inside 
> PPCGenScalarMASSEntries in the future and do the translation as part of that 
> transform?
Correct, pow->sqrt translation is not happening for none intrinsic cases. It is 
the case independent of this patch. I guess the reason is DAGCombiner only 
apply this optimization on llvm intrinsics. This is an issue that either we 
need to handle it in DAGCombiner (same as intrinsic one) or in MASS pass. I 
feel DAGCombiner is a better option and I think this is also a separate issue. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101759

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101759: [PowerPC] Scalar IBM MASS library conversion pass

2022-01-28 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added a comment.

Ready for another round of review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101759

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101759: [PowerPC] Scalar IBM MASS library conversion pass

2022-01-07 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added inline comments.



Comment at: llvm/include/llvm/Analysis/ScalarFuncs.def:19
+TLI_DEFINE_SCALAR_MASS_FUNC("acosf", "__xl_acosf")
+TLI_DEFINE_SCALAR_MASS_FUNC("__acosf_finite", "__xl_acosf")
+TLI_DEFINE_SCALAR_MASS_FUNC("acos", "__xl_acos")

efriedma wrote:
> Do "__acosf_finite" etc. actually exist on AIX?  I thought they only existed 
> on glibc, and the glibc functions are all deprecated.
> 
> I think I'd prefer to track this information in TargetLibraryInfo, like we do 
> for the vector functions, so we can more easily generalize this mechanism in 
> the future.
Some machines still have the old glibc, so I kept them for compatibility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101759

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114564: Fix the use of -fno-approx-func along with -Ofast or -ffast-math

2022-01-11 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added a comment.

A gentle reminder for reviewers. -- This patch will fix the bug reported here: 
https://bugs.llvm.org/show_bug.cgi?id=52565


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114564

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114564: Fix the use of -fno-approx-func along with -Ofast or -ffast-math

2021-12-07 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added a comment.

Gentle reminder for reviewers. -- This PR is ready for review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114564

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D114564: Fix the use of -fno-approx-func along with -Ofast or -ffast-math

2021-12-09 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2760
 case options::OPT_fno_honor_nans:   HonorNaNs = false;break;
 case options::OPT_fapprox_func: ApproxFunc = true;break;
 case options::OPT_fno_approx_func:  ApproxFunc = false;   break;

masoud.ataei wrote:
> andrew.w.kaylor wrote:
> > Should this also imply "MathErrno = false"?
> I don't think setting ApproxFunc to true should imply "MathErrno = false". 
> 
> Let say someone have a math library that compute approximate result for none 
> special input/output but returns NaN, INF and errno correctly otherwise. That 
> is actually can be fairly common, because performance in the none special 
> cases are much more important that the special ones. So returning errno in 
> the special outputs theoretically should not effect the performance on the 
> main path. Therefore, I think compiler should not assume anything about 
> MathErrno value based on ApproxFunc value.
I am not sure what I was suggesting in my last comment is correct or not. Can 
one of the more experienced reviewers confirm?
The question is: Should "ApproxFunc=ture" implies "MathErrno=false"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114564

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106191: [clang] Option control afn flag

2021-10-06 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added a comment.

Reminder for reviewers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106191: [clang] Option control afn flag

2021-10-07 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 377904.
masoud.ataei added a comment.

Description and driver test are added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/afn-flag-test.c
  clang/test/Driver/fast-math.c
  llvm/include/llvm/Target/TargetOptions.h

Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -126,7 +126,7 @@
 TargetOptions()
 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
   NoTrappingFPMath(true), NoSignedZerosFPMath(false),
-  EnableAIXExtendedAltivecABI(false),
+  ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
   HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
   GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
   EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
@@ -183,6 +183,12 @@
 /// argument or result as insignificant.
 unsigned NoSignedZerosFPMath : 1;
 
+/// ApproxFuncFPMath - This flag is enabled when the
+/// -enable-approx-func-fp-math is specified on the command line. This
+/// specifies that optimizations are allowed to substitute math functions
+/// with approximate calculations
+unsigned ApproxFuncFPMath : 1;
+
 /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
 /// specified. The code generator is then able to use both volatile and
 /// nonvolitle vector registers. When false, the code generator only uses
Index: clang/test/Driver/fast-math.c
===
--- clang/test/Driver/fast-math.c
+++ clang/test/Driver/fast-math.c
@@ -70,6 +70,11 @@
 // CHECK-NO-NANS-NO-FAST-MATH: "-cc1"
 // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans"
 //
+// RUN: %clang -### -fapprox-func -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-APPROX-FUNC %s
+// CHECK-APPROX-FUNC: "-cc1"
+// CHECK-APPROX-FUNC: "-fapprox-func"
+//
 // RUN: %clang -### -fmath-errno -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
 // CHECK-MATH-ERRNO: "-cc1"
Index: clang/test/CodeGen/afn-flag-test.c
===
--- /dev/null
+++ clang/test/CodeGen/afn-flag-test.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fapprox-func  %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-AFN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-NO-AFN %s
+
+extern double exp(double);
+double afn_option_test(double x) {
+  return exp(x);
+  // CHECK-LABEL:  define{{.*}} double @afn_option_test(double %x) #0 {
+
+  // CHECK-AFN:  %{{.*}} = call afn double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-AFN:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+
+  // CHECK-NO-AFN:   %{{.*}} = call double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-NO-AFN-NOT:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2618,6 +2618,7 @@
   // LLVM flags based on the final state.
   bool HonorINFs = true;
   bool HonorNaNs = true;
+  bool ApproxFunc = false;
   // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes.
   bool MathErrno = TC.IsMathErrnoDefault();
   bool AssociativeMath = false;
@@ -2722,6 +2723,8 @@
 case options::OPT_fno_honor_infinities: HonorINFs = false;break;
 case options::OPT_fhonor_nans:  HonorNaNs = true; break;
 case options::OPT_fno_honor_nans:   HonorNaNs = false;break;
+case options::OPT_fapprox_func: ApproxFunc = true;break;
+case options::OPT_fno_approx_func:  ApproxFunc = false;   break;
 case options::OPT_fmath_errno:  MathErrno = true; break;
 case options::OPT_fno_math_errno:   MathErrno = false;break;
 case options::OPT_fassociative_math:AssociativeMath = true;   break;
@@ -2917,6 +2920,9 @@
   if (!HonorNaNs)
 CmdArgs.push_back("-menable-no-nans");
 
+  if (ApproxFunc)
+CmdArgs.push_back("-fapprox-func");
+
   if (MathErrno)
 CmdArgs.push_back("-fmath-errno");
 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1828,6 +1828,8 @@
   FuncAttrs.addAttribute("no-infs-fp-math", "true");
 if (LangOpts.NoHonorNaNs)
   FuncAttrs.addAttrib

[PATCH] D106191: [clang] Option control afn flag

2021-10-07 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 377909.
masoud.ataei added a comment.

Update the documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/afn-flag-test.c
  clang/test/Driver/fast-math.c
  llvm/include/llvm/Target/TargetOptions.h

Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -126,7 +126,7 @@
 TargetOptions()
 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
   NoTrappingFPMath(true), NoSignedZerosFPMath(false),
-  EnableAIXExtendedAltivecABI(false),
+  ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
   HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
   GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
   EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
@@ -183,6 +183,12 @@
 /// argument or result as insignificant.
 unsigned NoSignedZerosFPMath : 1;
 
+/// ApproxFuncFPMath - This flag is enabled when the
+/// -enable-approx-func-fp-math is specified on the command line. This
+/// specifies that optimizations are allowed to substitute math functions
+/// with approximate calculations
+unsigned ApproxFuncFPMath : 1;
+
 /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
 /// specified. The code generator is then able to use both volatile and
 /// nonvolitle vector registers. When false, the code generator only uses
Index: clang/test/Driver/fast-math.c
===
--- clang/test/Driver/fast-math.c
+++ clang/test/Driver/fast-math.c
@@ -70,6 +70,11 @@
 // CHECK-NO-NANS-NO-FAST-MATH: "-cc1"
 // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans"
 //
+// RUN: %clang -### -fapprox-func -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-APPROX-FUNC %s
+// CHECK-APPROX-FUNC: "-cc1"
+// CHECK-APPROX-FUNC: "-fapprox-func"
+//
 // RUN: %clang -### -fmath-errno -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
 // CHECK-MATH-ERRNO: "-cc1"
Index: clang/test/CodeGen/afn-flag-test.c
===
--- /dev/null
+++ clang/test/CodeGen/afn-flag-test.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fapprox-func  %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-AFN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-NO-AFN %s
+
+extern double exp(double);
+double afn_option_test(double x) {
+  return exp(x);
+  // CHECK-LABEL:  define{{.*}} double @afn_option_test(double %x) #0 {
+
+  // CHECK-AFN:  %{{.*}} = call afn double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-AFN:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+
+  // CHECK-NO-AFN:   %{{.*}} = call double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-NO-AFN-NOT:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2618,6 +2618,7 @@
   // LLVM flags based on the final state.
   bool HonorINFs = true;
   bool HonorNaNs = true;
+  bool ApproxFunc = false;
   // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes.
   bool MathErrno = TC.IsMathErrnoDefault();
   bool AssociativeMath = false;
@@ -2722,6 +2723,8 @@
 case options::OPT_fno_honor_infinities: HonorINFs = false;break;
 case options::OPT_fhonor_nans:  HonorNaNs = true; break;
 case options::OPT_fno_honor_nans:   HonorNaNs = false;break;
+case options::OPT_fapprox_func: ApproxFunc = true;break;
+case options::OPT_fno_approx_func:  ApproxFunc = false;   break;
 case options::OPT_fmath_errno:  MathErrno = true; break;
 case options::OPT_fno_math_errno:   MathErrno = false;break;
 case options::OPT_fassociative_math:AssociativeMath = true;   break;
@@ -2917,6 +2920,9 @@
   if (!HonorNaNs)
 CmdArgs.push_back("-menable-no-nans");
 
+  if (ApproxFunc)
+CmdArgs.push_back("-fapprox-func");
+
   if (MathErrno)
 CmdArgs.push_back("-fmath-errno");
 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1828,6 +1828,8 @@
   FuncAttrs.addAttribute("no-infs-fp-math", "true");
 if (LangOpts.NoHonorNaNs)
   Fun

[PATCH] D106191: [clang] Option control afn flag

2021-10-07 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added inline comments.



Comment at: clang/docs/UsersManual.rst:1393
+
+   Allow substitution of approximate calculations for functions.
+   Defaults to ``-fno-approx-func``.

erichkeane wrote:
> This seems pretty incomplete to me, I have no idea what it does from this 
> description.  Can you elaborate?
If I didn't miss to say it is about math function calls, then I guess it would 
be more clear. 
```
Allow substitution of approximate calculations for math function calls.
```
This option just adds `afn` fast-math flag to the function calls and in backend 
the math function call can be replaced by an approximate calculation (either 
another math function call or not). 
https://llvm.org/docs/LangRef.html#fast-math-flags


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106191: [clang] Option control afn flag

2021-10-07 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 378005.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/afn-flag-test.c
  clang/test/Driver/fast-math.c
  llvm/include/llvm/Target/TargetOptions.h

Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -126,7 +126,7 @@
 TargetOptions()
 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
   NoTrappingFPMath(true), NoSignedZerosFPMath(false),
-  EnableAIXExtendedAltivecABI(false),
+  ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
   HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
   GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
   EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
@@ -183,6 +183,12 @@
 /// argument or result as insignificant.
 unsigned NoSignedZerosFPMath : 1;
 
+/// ApproxFuncFPMath - This flag is enabled when the
+/// -enable-approx-func-fp-math is specified on the command line. This
+/// specifies that optimizations are allowed to substitute math functions
+/// with approximate calculations
+unsigned ApproxFuncFPMath : 1;
+
 /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
 /// specified. The code generator is then able to use both volatile and
 /// nonvolitle vector registers. When false, the code generator only uses
Index: clang/test/Driver/fast-math.c
===
--- clang/test/Driver/fast-math.c
+++ clang/test/Driver/fast-math.c
@@ -70,6 +70,11 @@
 // CHECK-NO-NANS-NO-FAST-MATH: "-cc1"
 // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans"
 //
+// RUN: %clang -### -fapprox-func -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-APPROX-FUNC %s
+// CHECK-APPROX-FUNC: "-cc1"
+// CHECK-APPROX-FUNC: "-fapprox-func"
+//
 // RUN: %clang -### -fmath-errno -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
 // CHECK-MATH-ERRNO: "-cc1"
Index: clang/test/CodeGen/afn-flag-test.c
===
--- /dev/null
+++ clang/test/CodeGen/afn-flag-test.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fapprox-func  %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-AFN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-NO-AFN %s
+
+extern double exp(double);
+double afn_option_test(double x) {
+  return exp(x);
+  // CHECK-LABEL:  define{{.*}} double @afn_option_test(double %x) #0 {
+
+  // CHECK-AFN:  %{{.*}} = call afn double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-AFN:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+
+  // CHECK-NO-AFN:   %{{.*}} = call double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-NO-AFN-NOT:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2618,6 +2618,7 @@
   // LLVM flags based on the final state.
   bool HonorINFs = true;
   bool HonorNaNs = true;
+  bool ApproxFunc = false;
   // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes.
   bool MathErrno = TC.IsMathErrnoDefault();
   bool AssociativeMath = false;
@@ -2722,6 +2723,8 @@
 case options::OPT_fno_honor_infinities: HonorINFs = false;break;
 case options::OPT_fhonor_nans:  HonorNaNs = true; break;
 case options::OPT_fno_honor_nans:   HonorNaNs = false;break;
+case options::OPT_fapprox_func: ApproxFunc = true;break;
+case options::OPT_fno_approx_func:  ApproxFunc = false;   break;
 case options::OPT_fmath_errno:  MathErrno = true; break;
 case options::OPT_fno_math_errno:   MathErrno = false;break;
 case options::OPT_fassociative_math:AssociativeMath = true;   break;
@@ -2917,6 +2920,9 @@
   if (!HonorNaNs)
 CmdArgs.push_back("-menable-no-nans");
 
+  if (ApproxFunc)
+CmdArgs.push_back("-fapprox-func");
+
   if (MathErrno)
 CmdArgs.push_back("-fmath-errno");
 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1828,6 +1828,8 @@
   FuncAttrs.addAttribute("no-infs-fp-math", "true");
 if (LangOpts.NoHonorNaNs)
   FuncAttrs.addAttribute("no-nans-fp-math", "true");
+if (L

[PATCH] D106191: [clang] Option control afn flag

2021-10-08 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei marked an inline comment as not done.
masoud.ataei added inline comments.



Comment at: clang/docs/UsersManual.rst:1393
+
+   Allow substitution of approximate calculations for functions.
+   Defaults to ``-fno-approx-func``.

erichkeane wrote:
> masoud.ataei wrote:
> > erichkeane wrote:
> > > This seems pretty incomplete to me, I have no idea what it does from this 
> > > description.  Can you elaborate?
> > If I didn't miss to say it is about math function calls, then I guess it 
> > would be more clear. 
> > ```
> > Allow substitution of approximate calculations for math function calls.
> > ```
> > This option just adds `afn` fast-math flag to the function calls and in 
> > backend the math function call can be replaced by an approximate 
> > calculation (either another math function call or not). 
> > https://llvm.org/docs/LangRef.html#fast-math-flags
> allow substitution of approximate calculations for math function with what?  
> I'm not clear as to what this does still.  I'm not sure that I get what the 
> 'afn' documentation means there either.  Typically we'd want the clang 
> frontend flags to be more accurate/descriptive than the LLVM-IR documentation.
This option adds `afn` fast-math flag to function calls in IR. And in the case 
of math function calls (like `log`, `sqrt`, `pow`, ...), `afn` flag allows LLVM 
to substitute the math calls with an "approximate calculation". What an 
approximate calculation is may differ based on which math call it is, what 
other fast-math flags are set, what is the target machine, and other factors.

An approximate calculation can be
 1. sequence of instructions (inlining): for example, inlining sqrt call needs 
`afn` flag to be present in the call.
 2. a substituted math function call (which may be less accurate but faster): 
 this substitution can be 
 (a) for general targets: for example: `pow(x,0.25)` to `sqrt(sqrt(x))`. or
 (b) for a specific target: for example, in the case of PowerPC, we are 
proposing to substitute math calls to MASS library calls 
https://reviews.llvm.org/D101759

Note that, `afn` flag is necessary for these approximate calculation but may 
not be sufficient. Most of them need at lease one or two other fast-math flags 
to be set too. 

I agree the term "approximate calculation" is a very general term. But I guess 
it is needed to describe this general situation. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106191: [clang] Option control afn flag

2021-10-08 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei updated this revision to Diff 378277.
masoud.ataei added a comment.

Update the documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/afn-flag-test.c
  clang/test/Driver/fast-math.c
  llvm/include/llvm/Target/TargetOptions.h

Index: llvm/include/llvm/Target/TargetOptions.h
===
--- llvm/include/llvm/Target/TargetOptions.h
+++ llvm/include/llvm/Target/TargetOptions.h
@@ -126,7 +126,7 @@
 TargetOptions()
 : UnsafeFPMath(false), NoInfsFPMath(false), NoNaNsFPMath(false),
   NoTrappingFPMath(true), NoSignedZerosFPMath(false),
-  EnableAIXExtendedAltivecABI(false),
+  ApproxFuncFPMath(false), EnableAIXExtendedAltivecABI(false),
   HonorSignDependentRoundingFPMathOption(false), NoZerosInBSS(false),
   GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
   EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
@@ -183,6 +183,12 @@
 /// argument or result as insignificant.
 unsigned NoSignedZerosFPMath : 1;
 
+/// ApproxFuncFPMath - This flag is enabled when the
+/// -enable-approx-func-fp-math is specified on the command line. This
+/// specifies that optimizations are allowed to substitute math functions
+/// with approximate calculations
+unsigned ApproxFuncFPMath : 1;
+
 /// EnableAIXExtendedAltivecABI - This flag returns true when -vec-extabi is
 /// specified. The code generator is then able to use both volatile and
 /// nonvolitle vector registers. When false, the code generator only uses
Index: clang/test/Driver/fast-math.c
===
--- clang/test/Driver/fast-math.c
+++ clang/test/Driver/fast-math.c
@@ -70,6 +70,11 @@
 // CHECK-NO-NANS-NO-FAST-MATH: "-cc1"
 // CHECK-NO-NANS-NO-FAST-MATH-NOT: "-menable-no-nans"
 //
+// RUN: %clang -### -fapprox-func -c %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-APPROX-FUNC %s
+// CHECK-APPROX-FUNC: "-cc1"
+// CHECK-APPROX-FUNC: "-fapprox-func"
+//
 // RUN: %clang -### -fmath-errno -c %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MATH-ERRNO %s
 // CHECK-MATH-ERRNO: "-cc1"
Index: clang/test/CodeGen/afn-flag-test.c
===
--- /dev/null
+++ clang/test/CodeGen/afn-flag-test.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fapprox-func  %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-AFN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck --check-prefix=CHECK-NO-AFN %s
+
+extern double exp(double);
+double afn_option_test(double x) {
+  return exp(x);
+  // CHECK-LABEL:  define{{.*}} double @afn_option_test(double %x) #0 {
+
+  // CHECK-AFN:  %{{.*}} = call afn double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-AFN:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+
+  // CHECK-NO-AFN:   %{{.*}} = call double @{{.*}}exp{{.*}}(double %{{.*}})
+  // CHECK-NO-AFN-NOT:  attributes #0 ={{.*}} "approx-func-fp-math"="true" {{.*}}
+}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2618,6 +2618,7 @@
   // LLVM flags based on the final state.
   bool HonorINFs = true;
   bool HonorNaNs = true;
+  bool ApproxFunc = false;
   // -fmath-errno is the default on some platforms, e.g. BSD-derived OSes.
   bool MathErrno = TC.IsMathErrnoDefault();
   bool AssociativeMath = false;
@@ -2722,6 +2723,8 @@
 case options::OPT_fno_honor_infinities: HonorINFs = false;break;
 case options::OPT_fhonor_nans:  HonorNaNs = true; break;
 case options::OPT_fno_honor_nans:   HonorNaNs = false;break;
+case options::OPT_fapprox_func: ApproxFunc = true;break;
+case options::OPT_fno_approx_func:  ApproxFunc = false;   break;
 case options::OPT_fmath_errno:  MathErrno = true; break;
 case options::OPT_fno_math_errno:   MathErrno = false;break;
 case options::OPT_fassociative_math:AssociativeMath = true;   break;
@@ -2917,6 +2920,9 @@
   if (!HonorNaNs)
 CmdArgs.push_back("-menable-no-nans");
 
+  if (ApproxFunc)
+CmdArgs.push_back("-fapprox-func");
+
   if (MathErrno)
 CmdArgs.push_back("-fmath-errno");
 
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1828,6 +1828,8 @@
   FuncAttrs.addAttribute("no-infs-fp-math", "true");
 if (LangOpts.NoHonorNaNs)
   Fun

[PATCH] D106191: [clang] Option control afn flag

2021-08-26 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei added a comment.

In D106191#2966852 , @qiucf wrote:

> Making a new option mapped to another float op flag looks reasonable, but is 
> there any clearer motivation for this? (such as the need for `-Ofast 
> -fno-approx-func`)

This patch https://reviews.llvm.org/D101759 is the real motivation for option 
controlling afn flag. We want to have a way to distinguishes getting `_finite` 
or `non-finite` version of MASS functions. Only with afn flag (on O3 
), we want to get `non-finite` 
version of MASS functions. (finite version need extra fast-math flags.)




Comment at: llvm/include/llvm/Target/TargetOptions.h:179
+/// with approximate calculations
+unsigned ApproxFuncFPMath : 1;
+

qiucf wrote:
> `-enable-no-signed-zeros-fp-math` is an `llc` flag.
> 
> Do we really have `-enable-approx-func-fp-math` for `llc` now?
I am adding and using this option in https://reviews.llvm.org/D101759 patch. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106191

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101759: [PowerPC] Scalar IBM MASS library conversion pass

2021-08-26 Thread Masoud Ataei via Phabricator via cfe-commits
masoud.ataei marked an inline comment as done.
masoud.ataei added a comment.

In D101759#2967250 , @lebedev.ri 
wrote:

> Do we *really* need `-enable-approx-func-fp-math`?
> I'm pretty sure we are moving away from such global options, onto relying 
> only on the per-instruction fast-math flags.

I am handling LLVM intrinsic math functions in PPCISelLowering.cpp, so I need 
to check for `TM.Options.ApproxFuncFPMath`. This is the only place that I think 
I need it. 
Currently, I am updating `TM.Options.ApproxFuncFPMath` in 
`llvm/lib/CodeGen/CommandFlags.cpp` using the global option. Please let me know 
if there is a better way to update `TM.Options.ApproxFuncFPMath` based on the 
local fast-math flag.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101759

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits