r339690 - Test commit

2018-08-14 Thread Kevin P. Neal via cfe-commits
Author: kpn
Date: Tue Aug 14 09:56:25 2018
New Revision: 339690

URL: http://llvm.org/viewvc/llvm-project?rev=339690&view=rev
Log:
Test commit


Modified:
cfe/trunk/lib/Parse/ParseAST.cpp

Modified: cfe/trunk/lib/Parse/ParseAST.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseAST.cpp?rev=339690&r1=339689&r2=339690&view=diff
==
--- cfe/trunk/lib/Parse/ParseAST.cpp (original)
+++ cfe/trunk/lib/Parse/ParseAST.cpp Tue Aug 14 09:56:25 2018
@@ -26,6 +26,7 @@
 #include 
 #include 
 
+
 using namespace clang;
 
 namespace {


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


r339691 - Revert test commit

2018-08-14 Thread Kevin P. Neal via cfe-commits
Author: kpn
Date: Tue Aug 14 09:57:10 2018
New Revision: 339691

URL: http://llvm.org/viewvc/llvm-project?rev=339691&view=rev
Log:
Revert test commit


Modified:
cfe/trunk/lib/Parse/ParseAST.cpp

Modified: cfe/trunk/lib/Parse/ParseAST.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseAST.cpp?rev=339691&r1=339690&r2=339691&view=diff
==
--- cfe/trunk/lib/Parse/ParseAST.cpp (original)
+++ cfe/trunk/lib/Parse/ParseAST.cpp Tue Aug 14 09:57:10 2018
@@ -26,7 +26,6 @@
 #include 
 #include 
 
-
 using namespace clang;
 
 namespace {


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


r339693 - We have in place support for parsing #pragma FENV_ACCESS, but that

2018-08-14 Thread Kevin P. Neal via cfe-commits
Author: kpn
Date: Tue Aug 14 10:06:56 2018
New Revision: 339693

URL: http://llvm.org/viewvc/llvm-project?rev=339693&view=rev
Log:

We have in place support for parsing #pragma FENV_ACCESS, but that 
information is then discarded with a warning to the user that we don't 
support it.

This patch gets us one step closer by getting the info down into the 
AST in most cases.

Reviewed by:rsmith
Differential Revision:  https://reviews.llvm.org/D49865

Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/SemaAttr.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=339693&r1=339692&r2=339693&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Aug 14 10:06:56 2018
@@ -3269,7 +3269,7 @@ private:
 
   // This is only meaningful for operations on floating point types and 0
   // otherwise.
-  unsigned FPFeatures : 2;
+  unsigned FPFeatures : 3;
   SourceLocation OpLoc;
 
   enum { LHS, RHS, END_EXPR };
@@ -3448,6 +3448,12 @@ public:
 return FPOptions(FPFeatures).allowFPContractWithinStatement();
   }
 
+  // Get the FENV_ACCESS status of this operator. Only meaningful for
+  // operations on floating point types.
+  bool isFEnvAccessOn() const {
+return FPOptions(FPFeatures).allowFEnvAccess();
+  }
+
 protected:
   BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy,
  ExprValueKind VK, ExprObjectKind OK,

Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=339693&r1=339692&r2=339693&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Tue Aug 14 10:06:56 2018
@@ -137,6 +137,14 @@ public:
 FPC_Fast
   };
 
+  // TODO: merge FEnvAccessModeKind and FPContractModeKind
+  enum FEnvAccessModeKind {
+FEA_Off,
+
+FEA_On
+  };
+
+
 public:
   /// Set of enabled sanitizers.
   SanitizerSet Sanitize;
@@ -262,14 +270,19 @@ public:
 /// Floating point control options
 class FPOptions {
 public:
-  FPOptions() : fp_contract(LangOptions::FPC_Off) {}
+  FPOptions() : fp_contract(LangOptions::FPC_Off), 
+fenv_access(LangOptions::FEA_Off) {}
 
   // Used for serializing.
   explicit FPOptions(unsigned I)
-  : fp_contract(static_cast(I)) {}
+  : fp_contract(static_cast(I & 3)),
+fenv_access(static_cast((I >> 2) & 1))
+{}
 
   explicit FPOptions(const LangOptions &LangOpts)
-  : fp_contract(LangOpts.getDefaultFPContractMode()) {}
+  : fp_contract(LangOpts.getDefaultFPContractMode()),
+fenv_access(LangOptions::FEA_Off) {}
+  // FIXME: Use getDefaultFEnvAccessMode() when available.
 
   bool allowFPContractWithinStatement() const {
 return fp_contract == LangOptions::FPC_On;
@@ -289,12 +302,24 @@ public:
 
   void setDisallowFPContract() { fp_contract = LangOptions::FPC_Off; }
 
+  bool allowFEnvAccess() const {
+return fenv_access == LangOptions::FEA_On;
+  }
+
+  void setAllowFEnvAccess() {
+fenv_access = LangOptions::FEA_On;
+  }
+
+  void setDisallowFEnvAccess() { fenv_access = LangOptions::FEA_Off; }
+
   /// Used to serialize this.
-  unsigned getInt() const { return fp_contract; }
+  unsigned getInt() const { return fp_contract | (fenv_access << 2); }
 
 private:
-  /// Adjust BinaryOperator::FPFeatures to match the bit-field size of this.
+  /// Adjust BinaryOperator::FPFeatures to match the total bit-field size 
+  /// of these two.
   unsigned fp_contract : 2;
+  unsigned fenv_access : 1;
 };
 
 /// Describes the kind of translation unit being processed.

Modified: cfe/trunk/include/clang/Basic/TokenKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TokenKinds.def?rev=339693&r1=339692&r2=339693&view=diff
==
--- cfe/trunk/include/clang/Basic/TokenKinds.def (original)
+++ cfe/trunk/include/clang/Basic/TokenKinds.def Tue Aug 14 10:06:56 2018
@@ -780,6 +780,11 @@ ANNOTATION(pragma_redefine_extname)
 // handles them.
 ANNOTATION(pragma_fp_contract)
 
+// Annotation for #pragma STDC FENV_ACCESS
+// The lexer produces these so that they only take effect when the parser
+// handles them.
+ANNOTATION(pragma_fenv_access)
+
 // Annotation for #pragma pointers_to_members...
 // The lexer produces these so that they only take effect when the parser
 // handles them.

Modified:

[clang] 15a1780 - [PowerPC] Replace subtract-from-zero float in version with fneg in PowerPC special fma compiler builtins

2020-06-03 Thread Kevin P. Neal via cfe-commits

Author: Andrew Wock
Date: 2020-06-03T09:45:27-04:00
New Revision: 15a1780a10e3ba4573b8c1e02e24d3f0a785e199

URL: 
https://github.com/llvm/llvm-project/commit/15a1780a10e3ba4573b8c1e02e24d3f0a785e199
DIFF: 
https://github.com/llvm/llvm-project/commit/15a1780a10e3ba4573b8c1e02e24d3f0a785e199.diff

LOG: [PowerPC] Replace subtract-from-zero float in version with fneg in PowerPC 
special fma compiler builtins

This is a re-revert with a corrected test.

This patch adds a test for the PowerPC fma compiler builtins, some variations
of which negate inputs and outputs. The code to generate IR for these
builtins was untested before this patch.

Originally, the code used the outdated method of subtracting floating point
values from -0.0 as floating point negation. This patch remedies that.

Patch by: Drew Wock 
Differential Revision: https://reviews.llvm.org/D76949

Added: 
clang/test/CodeGen/builtins-ppc-fma.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-ppc-vsx.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 13c24a5d2686..948d31312bd8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -14056,7 +14056,6 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType);
 llvm::Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
 switch (BuiltinID) {
   case PPC::BI__builtin_vsx_xvmaddadp:
@@ -14064,17 +14063,14 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 return Builder.CreateCall(F, {X, Y, Z});
   case PPC::BI__builtin_vsx_xvnmaddadp:
   case PPC::BI__builtin_vsx_xvnmaddasp:
-return Builder.CreateFSub(Zero,
-  Builder.CreateCall(F, {X, Y, Z}), "sub");
+return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, Z}), "neg");
   case PPC::BI__builtin_vsx_xvmsubadp:
   case PPC::BI__builtin_vsx_xvmsubasp:
-return Builder.CreateCall(F,
-  {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
+return Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")});
   case PPC::BI__builtin_vsx_xvnmsubadp:
   case PPC::BI__builtin_vsx_xvnmsubasp:
-Value *FsubRes =
-  Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
-return Builder.CreateFSub(Zero, FsubRes, "sub");
+return Builder.CreateFNeg(
+Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")}), 
"neg");
 }
 llvm_unreachable("Unknown FMA operation");
 return nullptr; // Suppress no-return warning

diff  --git a/clang/test/CodeGen/builtins-ppc-fma.c 
b/clang/test/CodeGen/builtins-ppc-fma.c
new file mode 100644
index ..3f124e8c8299
--- /dev/null
+++ b/clang/test/CodeGen/builtins-ppc-fma.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple powerpc64le-gnu-linux \
+// RUN: -target-feature +altivec -Wall -Wno-unused -Werror -emit-llvm %s -o - 
| FileCheck  \
+// RUN: %s
+
+typedef __attribute__((vector_size(4 * sizeof(float float vec_float;
+typedef __attribute__((vector_size(2 * sizeof(double double vec_double;
+
+volatile vec_double vd;
+volatile vec_float vf;
+
+void test_fma(void) {
+  vf = __builtin_vsx_xvmaddasp(vf, vf, vf);
+  // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> %{{.*}})
+
+  vd = __builtin_vsx_xvmaddadp(vd, vd, vd);
+  // CHECK: @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x 
double> %{{.*}})
+
+  vf = __builtin_vsx_xvnmaddasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] = call <4 x float> @llvm.fma.v4f32(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
+  // CHECK: fneg <4 x float> [[RESULT]]
+
+  vd = __builtin_vsx_xvnmaddadp(vd, vd, vd);
+  // CHECK: [[RESULT:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
+  // CHECK: fneg <2 x double> [[RESULT]]
+
+  vf = __builtin_vsx_xvmsubasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <4 x float> %{{.*}}
+  // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> [[RESULT]])
+
+  vd = __builtin_vsx_xvmsubadp(vd, vd, vd);
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <2 x double> %{{.*}}
+  // CHECK: <2 x double> @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x double> 
%{{.*}}, <2 x double> [[RESULT]])
+
+  vf = __builtin_vsx_xvnmsubasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <4 x float> %{{.*}}
+  // CHECK: [[RESULT2:%[^ ]+]] = call <4 x float> @llvm.fma.v4f32(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> [[RESULT]])
+  // CHECK: fneg <4 x float> [[RESULT2]]
+
+  vd = __builtin_vsx_xvnms

[clang] ba87430 - [PowerPC] Replace subtract-from-zero float in version with fneg in PowerPC special fma compiler builtins

2020-04-03 Thread Kevin P. Neal via cfe-commits

Author: Andrew Wock
Date: 2020-04-03T14:59:33-04:00
New Revision: ba87430cadb2d5d0ee8e4b75101d7abcf6b321bf

URL: 
https://github.com/llvm/llvm-project/commit/ba87430cadb2d5d0ee8e4b75101d7abcf6b321bf
DIFF: 
https://github.com/llvm/llvm-project/commit/ba87430cadb2d5d0ee8e4b75101d7abcf6b321bf.diff

LOG: [PowerPC] Replace subtract-from-zero float in version with fneg in PowerPC 
special fma compiler builtins

This patch adds a test for the PowerPC fma compiler builtins, some variations
of which negate inputs and outputs. The code to generate IR for these
builtins was untested before this patch.

Originally, the code used the outdated method of subtracting floating point
values from -0.0 as floating point negation. This patch remedies that.

Patch by: Drew Wock 
Differential Revision: https://reviews.llvm.org/D76949

Added: 
clang/test/CodeGen/builtins-ppc-fma.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 880fe0e271f5..3545ccda5d4d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -13214,25 +13214,24 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType);
 llvm::Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
 switch (BuiltinID) {
   case PPC::BI__builtin_vsx_xvmaddadp:
   case PPC::BI__builtin_vsx_xvmaddasp:
 return Builder.CreateCall(F, {X, Y, Z});
+
   case PPC::BI__builtin_vsx_xvnmaddadp:
   case PPC::BI__builtin_vsx_xvnmaddasp:
-return Builder.CreateFSub(Zero,
-  Builder.CreateCall(F, {X, Y, Z}), "sub");
+return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, Z}), "neg");
+
   case PPC::BI__builtin_vsx_xvmsubadp:
   case PPC::BI__builtin_vsx_xvmsubasp:
-return Builder.CreateCall(F,
-  {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
+return Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")});
+
   case PPC::BI__builtin_vsx_xvnmsubadp:
   case PPC::BI__builtin_vsx_xvnmsubasp:
-Value *FsubRes =
-  Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
-return Builder.CreateFSub(Zero, FsubRes, "sub");
+return Builder.CreateFNeg(
+Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")}), 
"neg");
 }
 llvm_unreachable("Unknown FMA operation");
 return nullptr; // Suppress no-return warning

diff  --git a/clang/test/CodeGen/builtins-ppc-fma.c 
b/clang/test/CodeGen/builtins-ppc-fma.c
new file mode 100644
index ..3a628f7613b5
--- /dev/null
+++ b/clang/test/CodeGen/builtins-ppc-fma.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple powerpc64le-gnu-linux \
+// RUN: -target-feature +altivec -Wall -Wno-unused -Werror -emit-llvm %s -o - 
| FileCheck  \
+// RUN: %s
+
+typedef __attribute__((vector_size(4 * sizeof(float float vec_float;
+typedef __attribute__((vector_size(2 * sizeof(double double vec_double;
+
+volatile vec_double vd;
+volatile vec_float vf;
+
+void test_fma(void) {
+  vf = __builtin_vsx_xvmaddasp(vf, vf, vf);
+  // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> %{{.*}})
+
+  vd = __builtin_vsx_xvmaddadp(vd, vd, vd);
+  // CHECK: @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x 
double> %{{.*}})
+
+  vf = __builtin_vsx_xvnmaddasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] = call <4 x float> @llvm.fma.v4f32(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
+  // CHECK: fneg <4 x float> [[RESULT]]
+
+  vd = __builtin_vsx_xvnmaddadp(vd, vd, vd);
+  // CHECK: [[RESULT:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
+  // CHECK: fneg <2 x double> [[RESULT]]
+
+  vf = __builtin_vsx_xvmsubasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] fneg <4 x float> %{{.*}}
+  // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> [[RESULT]])
+
+  vd = __builtin_vsx_xvmsubadp(vd, vd, vd);
+  // CHECK: fneg <2 x double> [[RESULT]]
+  // CHECK: [[RESULT:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
+
+  vf = __builtin_vsx_xvnmsubasp(vf, vf, vf);
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <4 x float> %{{.*}}
+  // CHECK: [[RESULT2:%[^ ]+]] = call <4 x float> @llvm.fma.v2f64(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> [[RESULT]])
+  // CHECK: fneg <4 x float> [[RESULT2]]
+
+  vd = __builtin_vsx_xvnmsubadp(vd, vd, vd);
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <2 x double> %{{.*}}
+  // CHECK: [[RESULT2:%[^ ]+]] = call <2 x

[clang] d7a0516 - Fix typo in test.

2020-04-03 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-04-03T15:23:49-04:00
New Revision: d7a0516ddcfe373bb780d6fc19d76fe74ecc0061

URL: 
https://github.com/llvm/llvm-project/commit/d7a0516ddcfe373bb780d6fc19d76fe74ecc0061
DIFF: 
https://github.com/llvm/llvm-project/commit/d7a0516ddcfe373bb780d6fc19d76fe74ecc0061.diff

LOG: Fix typo in test.

Differential Revision: https://reviews.llvm.org/D76949

Added: 


Modified: 
clang/test/CodeGen/builtins-ppc-fma.c

Removed: 




diff  --git a/clang/test/CodeGen/builtins-ppc-fma.c 
b/clang/test/CodeGen/builtins-ppc-fma.c
index 3a628f7613b5..e91b45b0daa7 100644
--- a/clang/test/CodeGen/builtins-ppc-fma.c
+++ b/clang/test/CodeGen/builtins-ppc-fma.c
@@ -24,7 +24,7 @@ void test_fma(void) {
   // CHECK: fneg <2 x double> [[RESULT]]
 
   vf = __builtin_vsx_xvmsubasp(vf, vf, vf);
-  // CHECK: [[RESULT:%[^ ]+]] fneg <4 x float> %{{.*}}
+  // CHECK: [[RESULT:%[^ ]+]] = fneg <4 x float> %{{.*}}
   // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> [[RESULT]])
 
   vd = __builtin_vsx_xvmsubadp(vd, vd, vd);



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


[clang] 9f1c35d - Revert "[PowerPC] Replace subtract-from-zero float in version with fneg in PowerPC special fma compiler builtins"

2020-04-03 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-04-03T15:47:19-04:00
New Revision: 9f1c35d8b14f026b7bc4b21b9eecafbbb42c42a2

URL: 
https://github.com/llvm/llvm-project/commit/9f1c35d8b14f026b7bc4b21b9eecafbbb42c42a2
DIFF: 
https://github.com/llvm/llvm-project/commit/9f1c35d8b14f026b7bc4b21b9eecafbbb42c42a2.diff

LOG: Revert "[PowerPC] Replace subtract-from-zero float in version with fneg in 
PowerPC special fma compiler builtins"

The new test case causes bot failures.

This reverts commit ba87430cadb2d5d0ee8e4b75101d7abcf6b321bf.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 
clang/test/CodeGen/builtins-ppc-fma.c



diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3545ccda5d4d..880fe0e271f5 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -13214,24 +13214,25 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
+Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType);
 llvm::Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
 switch (BuiltinID) {
   case PPC::BI__builtin_vsx_xvmaddadp:
   case PPC::BI__builtin_vsx_xvmaddasp:
 return Builder.CreateCall(F, {X, Y, Z});
-
   case PPC::BI__builtin_vsx_xvnmaddadp:
   case PPC::BI__builtin_vsx_xvnmaddasp:
-return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, Z}), "neg");
-
+return Builder.CreateFSub(Zero,
+  Builder.CreateCall(F, {X, Y, Z}), "sub");
   case PPC::BI__builtin_vsx_xvmsubadp:
   case PPC::BI__builtin_vsx_xvmsubasp:
-return Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")});
-
+return Builder.CreateCall(F,
+  {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
   case PPC::BI__builtin_vsx_xvnmsubadp:
   case PPC::BI__builtin_vsx_xvnmsubasp:
-return Builder.CreateFNeg(
-Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")}), 
"neg");
+Value *FsubRes =
+  Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
+return Builder.CreateFSub(Zero, FsubRes, "sub");
 }
 llvm_unreachable("Unknown FMA operation");
 return nullptr; // Suppress no-return warning

diff  --git a/clang/test/CodeGen/builtins-ppc-fma.c 
b/clang/test/CodeGen/builtins-ppc-fma.c
deleted file mode 100644
index e91b45b0daa7..
--- a/clang/test/CodeGen/builtins-ppc-fma.c
+++ /dev/null
@@ -1,43 +0,0 @@
-// RUN: %clang_cc1 -triple powerpc64le-gnu-linux \
-// RUN: -target-feature +altivec -Wall -Wno-unused -Werror -emit-llvm %s -o - 
| FileCheck  \
-// RUN: %s
-
-typedef __attribute__((vector_size(4 * sizeof(float float vec_float;
-typedef __attribute__((vector_size(2 * sizeof(double double vec_double;
-
-volatile vec_double vd;
-volatile vec_float vf;
-
-void test_fma(void) {
-  vf = __builtin_vsx_xvmaddasp(vf, vf, vf);
-  // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> %{{.*}})
-
-  vd = __builtin_vsx_xvmaddadp(vd, vd, vd);
-  // CHECK: @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x 
double> %{{.*}})
-
-  vf = __builtin_vsx_xvnmaddasp(vf, vf, vf);
-  // CHECK: [[RESULT:%[^ ]+]] = call <4 x float> @llvm.fma.v4f32(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
-  // CHECK: fneg <4 x float> [[RESULT]]
-
-  vd = __builtin_vsx_xvnmaddadp(vd, vd, vd);
-  // CHECK: [[RESULT:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
-  // CHECK: fneg <2 x double> [[RESULT]]
-
-  vf = __builtin_vsx_xvmsubasp(vf, vf, vf);
-  // CHECK: [[RESULT:%[^ ]+]] = fneg <4 x float> %{{.*}}
-  // CHECK: @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x 
float> [[RESULT]])
-
-  vd = __builtin_vsx_xvmsubadp(vd, vd, vd);
-  // CHECK: fneg <2 x double> [[RESULT]]
-  // CHECK: [[RESULT:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x double> 
%{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
-
-  vf = __builtin_vsx_xvnmsubasp(vf, vf, vf);
-  // CHECK: [[RESULT:%[^ ]+]] = fneg <4 x float> %{{.*}}
-  // CHECK: [[RESULT2:%[^ ]+]] = call <4 x float> @llvm.fma.v2f64(<4 x float> 
%{{.*}}, <4 x float> %{{.*}}, <4 x float> [[RESULT]])
-  // CHECK: fneg <4 x float> [[RESULT2]]
-
-  vd = __builtin_vsx_xvnmsubadp(vd, vd, vd);
-  // CHECK: [[RESULT:%[^ ]+]] = fneg <2 x double> %{{.*}}
-  // CHECK: [[RESULT2:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x 
double> %{{.*}}, <2 x double> %{{.*}}, <2 x double> [[RESULT]])
-  // CHECK: fneg <2 x double> [[RESULT2]]
-}



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

[clang] 39d2ae0 - [FPEnv][Clang][Driver] Disable constrained floating point on targets lacking support.

2020-07-06 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-07-06T13:32:49-04:00
New Revision: 39d2ae0afb2312a15e4d15a0855b35b4e1c49fc4

URL: 
https://github.com/llvm/llvm-project/commit/39d2ae0afb2312a15e4d15a0855b35b4e1c49fc4
DIFF: 
https://github.com/llvm/llvm-project/commit/39d2ae0afb2312a15e4d15a0855b35b4e1c49fc4.diff

LOG: [FPEnv][Clang][Driver] Disable constrained floating point on targets 
lacking support.

We currently have strict floating point/constrained floating point enabled
for all targets. Constrained SDAG nodes get converted to the regular ones
before reaching the target layer. In theory this should be fine.

However, the changes are exposed to users through multiple clang options
already in use in the field, and the changes are _completely_ _untested_
on almost all of our targets. Bugs have already been found, like
"https://bugs.llvm.org/show_bug.cgi?id=45274";.

This patch disables constrained floating point options in clang everywhere
except X86 and SystemZ. A warning will be printed when this happens.

Differential Revision: https://reviews.llvm.org/D80952

Added: 
clang/test/CodeGen/fp-strictfp.cpp

Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/SystemZ.h
clang/lib/Basic/Targets/X86.h
clang/lib/Frontend/CompilerInstance.cpp
clang/test/CodeGen/aarch64-neon-misc-constrained.c
clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
clang/test/CodeGen/arm-neon-directed-rounding-constrained.c
clang/test/CodeGen/arm64-vrnd-constrained.c
clang/test/CodeGen/builtins-ppc-fpconstrained.c

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 83c13e0dbbe0..db334a7899c4 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -37,6 +37,12 @@ def note_fe_backend_plugin: Note<"%0">, BackendInfo;
 def warn_fe_override_module : Warning<
 "overriding the module target triple with %0">,
 InGroup>;
+def warn_fe_backend_unsupported_fp_rounding : Warning<
+"overriding currently unsupported rounding mode on this target">,
+InGroup;
+def warn_fe_backend_unsupported_fp_exceptions : Warning<
+"overriding currently unsupported use of floating point exceptions "
+"on this target">, InGroup;
 
 def remark_fe_backend_optimization_remark : Remark<"%0">, BackendInfo,
 InGroup;

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 37e0b77e79ed..ff07608c81e4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -107,6 +107,7 @@ def DoublePromotion : DiagGroup<"double-promotion">;
 def EnumTooLarge : DiagGroup<"enum-too-large">;
 def UnsupportedNan : DiagGroup<"unsupported-nan">;
 def UnsupportedAbs : DiagGroup<"unsupported-abs">;
+def UnsupportedFPOpt : DiagGroup<"unsupported-floating-point-opt">;
 def UnsupportedCB : DiagGroup<"unsupported-cb">;
 def UnsupportedGPOpt : DiagGroup<"unsupported-gpopt">;
 def UnsupportedTargetOpt : DiagGroup<"unsupported-target-opt">;

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 140f55ff66b1..2ee3b1659630 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -192,6 +192,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   bool HasFloat128;
   bool HasFloat16;
   bool HasBFloat16;
+  bool HasStrictFP;
 
   unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
   unsigned short SimdDefaultAlign;
@@ -577,6 +578,9 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   /// Determine whether the _BFloat16 type is supported on this target.
   virtual bool hasBFloat16Type() const { return HasBFloat16; }
 
+  /// Determine whether constrained floating point is supported on this target.
+  virtual bool hasStrictFP() const { return HasStrictFP; }
+
   /// Return the alignment that is suitable for storing any
   /// object with a fundamental alignment requirement.
   unsigned getSuitableAlign() const { return SuitableAlign; }

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 7f360b715da9..eccdc21d724a 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -37,6 +37,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), 
Triple(T) {
   HasFloat128 = false;
   HasFloat16 = false;
   HasBFloat16 = false;
+  HasStrictFP = false;
   PointerWidth = PointerAlign = 32;
   BoolWidth = BoolAlign = 8;
   IntWidth = IntAlign = 32;

diff  --git a/clang/lib/Basic/T

[clang] bfdafa3 - [FPEnv][Clang][Driver] Failing tests are now expected failures.

2020-07-06 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-07-06T14:20:49-04:00
New Revision: bfdafa32a0fa4b2745627fe57dd253db10ac3fcf

URL: 
https://github.com/llvm/llvm-project/commit/bfdafa32a0fa4b2745627fe57dd253db10ac3fcf
DIFF: 
https://github.com/llvm/llvm-project/commit/bfdafa32a0fa4b2745627fe57dd253db10ac3fcf.diff

LOG: [FPEnv][Clang][Driver] Failing tests are now expected failures.

These are now expected failures on PowerPC. They can be reenabled when
PowerPC is ready.

Differential Revision: https://reviews.llvm.org/D80952

Added: 


Modified: 
clang/test/CodeGen/fpconstrained-cmp-double.c
clang/test/CodeGen/fpconstrained-cmp-float.c
clang/test/CodeGen/fpconstrained.c
clang/test/CodeGen/fpconstrained.cpp

Removed: 




diff  --git a/clang/test/CodeGen/fpconstrained-cmp-double.c 
b/clang/test/CodeGen/fpconstrained-cmp-double.c
index 2819970a3fcf..d2744d283c84 100644
--- a/clang/test/CodeGen/fpconstrained-cmp-double.c
+++ b/clang/test/CodeGen/fpconstrained-cmp-double.c
@@ -5,6 +5,9 @@
 // RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=strict -emit-llvm 
-o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=EXCEPT
 // RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=maytrap -emit-llvm 
-o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=MAYTRAP
 
+// Disabled until constrained floating point is completed for PowerPC.
+// XFAIL: *
+
 _Bool QuietEqual(double f1, double f2) {
   // CHECK-LABEL: define {{.*}}i1 @QuietEqual(double %f1, double %f2)
 

diff  --git a/clang/test/CodeGen/fpconstrained-cmp-float.c 
b/clang/test/CodeGen/fpconstrained-cmp-float.c
index 0265fc54c02b..2403e542b929 100644
--- a/clang/test/CodeGen/fpconstrained-cmp-float.c
+++ b/clang/test/CodeGen/fpconstrained-cmp-float.c
@@ -5,6 +5,9 @@
 // RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=strict -emit-llvm 
-o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=EXCEPT
 // RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=maytrap -emit-llvm 
-o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=MAYTRAP
 
+// Disabled until constrained floating point is completed for PowerPC.
+// XFAIL: *
+
 _Bool QuietEqual(float f1, float f2) {
   // CHECK-LABEL: define {{.*}}i1 @QuietEqual(float %f1, float %f2)
 

diff  --git a/clang/test/CodeGen/fpconstrained.c 
b/clang/test/CodeGen/fpconstrained.c
index 902d6b5baf49..e268af46a2de 100644
--- a/clang/test/CodeGen/fpconstrained.c
+++ b/clang/test/CodeGen/fpconstrained.c
@@ -5,6 +5,10 @@
 // RUN: %clang_cc1 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=ignore -emit-llvm -o - %s | FileCheck %s 
-check-prefix=FAST
 // RUN: %clang_cc1 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=strict -emit-llvm -o - %s | FileCheck %s 
-check-prefix=EXCEPT
 // RUN: %clang_cc1 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=maytrap -emit-llvm -o - %s | FileCheck %s 
-check-prefix=MAYTRAP
+
+// Disabled until constrained floating point is completed for PowerPC.
+// XFAIL: *
+
 float f0, f1, f2;
 
 void foo() {

diff  --git a/clang/test/CodeGen/fpconstrained.cpp 
b/clang/test/CodeGen/fpconstrained.cpp
index e914abcc6926..8db68533d37c 100644
--- a/clang/test/CodeGen/fpconstrained.cpp
+++ b/clang/test/CodeGen/fpconstrained.cpp
@@ -5,6 +5,10 @@
 // RUN: %clang_cc1 -x c++ -ffast-math -fexceptions -fcxx-exceptions 
-ffp-contract=fast -ffp-exception-behavior=ignore -emit-llvm -o - %s | 
FileCheck %s -check-prefix=FAST
 // RUN: %clang_cc1 -x c++ -ffast-math -fexceptions -fcxx-exceptions 
-ffp-contract=fast -ffp-exception-behavior=strict -emit-llvm -o - %s | 
FileCheck %s -check-prefix=EXCEPT
 // RUN: %clang_cc1 -x c++ -ffast-math -fexceptions -fcxx-exceptions 
-ffp-contract=fast -ffp-exception-behavior=maytrap -emit-llvm -o - %s | 
FileCheck %s -check-prefix=MAYTRAP
+
+// Disabled until constrained floating point is completed for PowerPC.
+// XFAIL: *
+
 float f0, f1, f2;
 
   template 



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


[clang] 2b35511 - [FPEnv][Clang][Driver] Failing tests are now expected failures only on PowerPC

2020-07-06 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-07-06T14:44:06-04:00
New Revision: 2b35511350454dd22997f129ee529e3fdb129ac2

URL: 
https://github.com/llvm/llvm-project/commit/2b35511350454dd22997f129ee529e3fdb129ac2
DIFF: 
https://github.com/llvm/llvm-project/commit/2b35511350454dd22997f129ee529e3fdb129ac2.diff

LOG: [FPEnv][Clang][Driver] Failing tests are now expected failures only on 
PowerPC

Mark these tests as only failing on PowerPC. Avoids unexpected passes on
other bots.

Fingers crossed.

Differential Revision: https://reviews.llvm.org/D80952

Added: 


Modified: 
clang/test/CodeGen/fpconstrained-cmp-double.c
clang/test/CodeGen/fpconstrained-cmp-float.c
clang/test/CodeGen/fpconstrained.c
clang/test/CodeGen/fpconstrained.cpp

Removed: 




diff  --git a/clang/test/CodeGen/fpconstrained-cmp-double.c 
b/clang/test/CodeGen/fpconstrained-cmp-double.c
index d2744d283c84..7c4d04677842 100644
--- a/clang/test/CodeGen/fpconstrained-cmp-double.c
+++ b/clang/test/CodeGen/fpconstrained-cmp-double.c
@@ -6,7 +6,7 @@
 // RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=maytrap -emit-llvm 
-o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=MAYTRAP
 
 // Disabled until constrained floating point is completed for PowerPC.
-// XFAIL: *
+// XFAIL: powerpc, powerpc64, powerpc64le
 
 _Bool QuietEqual(double f1, double f2) {
   // CHECK-LABEL: define {{.*}}i1 @QuietEqual(double %f1, double %f2)

diff  --git a/clang/test/CodeGen/fpconstrained-cmp-float.c 
b/clang/test/CodeGen/fpconstrained-cmp-float.c
index 2403e542b929..964725080a7e 100644
--- a/clang/test/CodeGen/fpconstrained-cmp-float.c
+++ b/clang/test/CodeGen/fpconstrained-cmp-float.c
@@ -6,7 +6,7 @@
 // RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=maytrap -emit-llvm 
-o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=MAYTRAP
 
 // Disabled until constrained floating point is completed for PowerPC.
-// XFAIL: *
+// XFAIL: powerpc, powerpc64, powerpc64le
 
 _Bool QuietEqual(float f1, float f2) {
   // CHECK-LABEL: define {{.*}}i1 @QuietEqual(float %f1, float %f2)

diff  --git a/clang/test/CodeGen/fpconstrained.c 
b/clang/test/CodeGen/fpconstrained.c
index e268af46a2de..3ce9b6fa1a55 100644
--- a/clang/test/CodeGen/fpconstrained.c
+++ b/clang/test/CodeGen/fpconstrained.c
@@ -7,7 +7,7 @@
 // RUN: %clang_cc1 -ffast-math -ffp-contract=fast 
-ffp-exception-behavior=maytrap -emit-llvm -o - %s | FileCheck %s 
-check-prefix=MAYTRAP
 
 // Disabled until constrained floating point is completed for PowerPC.
-// XFAIL: *
+// XFAIL: powerpc, powerpc64, powerpc664le
 
 float f0, f1, f2;
 

diff  --git a/clang/test/CodeGen/fpconstrained.cpp 
b/clang/test/CodeGen/fpconstrained.cpp
index 8db68533d37c..39634dd96994 100644
--- a/clang/test/CodeGen/fpconstrained.cpp
+++ b/clang/test/CodeGen/fpconstrained.cpp
@@ -7,7 +7,7 @@
 // RUN: %clang_cc1 -x c++ -ffast-math -fexceptions -fcxx-exceptions 
-ffp-contract=fast -ffp-exception-behavior=maytrap -emit-llvm -o - %s | 
FileCheck %s -check-prefix=MAYTRAP
 
 // Disabled until constrained floating point is completed for PowerPC.
-// XFAIL: *
+// XFAIL: powerpc, powerpc64, powerpc64le
 
 float f0, f1, f2;
 



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


[clang] 916e2ca - Revert "[FPEnv][Clang][Driver] Disable constrained floating point on targets lacking support."

2020-07-06 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-07-06T14:57:45-04:00
New Revision: 916e2ca99785d34db73945940923a487efad32ad

URL: 
https://github.com/llvm/llvm-project/commit/916e2ca99785d34db73945940923a487efad32ad
DIFF: 
https://github.com/llvm/llvm-project/commit/916e2ca99785d34db73945940923a487efad32ad.diff

LOG: Revert "[FPEnv][Clang][Driver] Disable constrained floating point on 
targets lacking support."

My mistake, I had a blocking reviewer.

This reverts commit 39d2ae0afb2312a15e4d15a0855b35b4e1c49fc4.
This reverts commit bfdafa32a0fa4b2745627fe57dd253db10ac3fcf.
This reverts commit 2b35511350454dd22997f129ee529e3fdb129ac2.

Differential Revision: https://reviews.llvm.org/D80952

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/SystemZ.h
clang/lib/Basic/Targets/X86.h
clang/lib/Frontend/CompilerInstance.cpp
clang/test/CodeGen/aarch64-neon-misc-constrained.c
clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
clang/test/CodeGen/arm-neon-directed-rounding-constrained.c
clang/test/CodeGen/arm64-vrnd-constrained.c
clang/test/CodeGen/builtins-ppc-fpconstrained.c
clang/test/CodeGen/fpconstrained-cmp-double.c
clang/test/CodeGen/fpconstrained-cmp-float.c
clang/test/CodeGen/fpconstrained.c
clang/test/CodeGen/fpconstrained.cpp

Removed: 
clang/test/CodeGen/fp-strictfp.cpp



diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index db334a7899c4..83c13e0dbbe0 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -37,12 +37,6 @@ def note_fe_backend_plugin: Note<"%0">, BackendInfo;
 def warn_fe_override_module : Warning<
 "overriding the module target triple with %0">,
 InGroup>;
-def warn_fe_backend_unsupported_fp_rounding : Warning<
-"overriding currently unsupported rounding mode on this target">,
-InGroup;
-def warn_fe_backend_unsupported_fp_exceptions : Warning<
-"overriding currently unsupported use of floating point exceptions "
-"on this target">, InGroup;
 
 def remark_fe_backend_optimization_remark : Remark<"%0">, BackendInfo,
 InGroup;

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index ff07608c81e4..37e0b77e79ed 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -107,7 +107,6 @@ def DoublePromotion : DiagGroup<"double-promotion">;
 def EnumTooLarge : DiagGroup<"enum-too-large">;
 def UnsupportedNan : DiagGroup<"unsupported-nan">;
 def UnsupportedAbs : DiagGroup<"unsupported-abs">;
-def UnsupportedFPOpt : DiagGroup<"unsupported-floating-point-opt">;
 def UnsupportedCB : DiagGroup<"unsupported-cb">;
 def UnsupportedGPOpt : DiagGroup<"unsupported-gpopt">;
 def UnsupportedTargetOpt : DiagGroup<"unsupported-target-opt">;

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 2ee3b1659630..140f55ff66b1 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -192,7 +192,6 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   bool HasFloat128;
   bool HasFloat16;
   bool HasBFloat16;
-  bool HasStrictFP;
 
   unsigned char MaxAtomicPromoteWidth, MaxAtomicInlineWidth;
   unsigned short SimdDefaultAlign;
@@ -578,9 +577,6 @@ class TargetInfo : public virtual TransferrableTargetInfo,
   /// Determine whether the _BFloat16 type is supported on this target.
   virtual bool hasBFloat16Type() const { return HasBFloat16; }
 
-  /// Determine whether constrained floating point is supported on this target.
-  virtual bool hasStrictFP() const { return HasStrictFP; }
-
   /// Return the alignment that is suitable for storing any
   /// object with a fundamental alignment requirement.
   unsigned getSuitableAlign() const { return SuitableAlign; }

diff  --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index eccdc21d724a..7f360b715da9 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -37,7 +37,6 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : TargetOpts(), 
Triple(T) {
   HasFloat128 = false;
   HasFloat16 = false;
   HasBFloat16 = false;
-  HasStrictFP = false;
   PointerWidth = PointerAlign = 32;
   BoolWidth = BoolAlign = 8;
   IntWidth = IntAlign = 32;

diff  --git a/clang/lib/Basic/Targets/SystemZ.h 
b/clang/lib/Basic/Targets/SystemZ.h
index d7869e3754a8..134b0313b86a 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -48,7 +48,6 @@ class LLVM_LI

[clang] d4ce862 - Reland "[FPEnv][Clang][Driver] Disable constrained floating point on targets lacking support."

2020-07-10 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-07-10T08:49:45-04:00
New Revision: d4ce862f2aa8b7e4b11462bd72014b08ab9468b3

URL: 
https://github.com/llvm/llvm-project/commit/d4ce862f2aa8b7e4b11462bd72014b08ab9468b3
DIFF: 
https://github.com/llvm/llvm-project/commit/d4ce862f2aa8b7e4b11462bd72014b08ab9468b3.diff

LOG: Reland "[FPEnv][Clang][Driver] Disable constrained floating point on 
targets lacking support."

We currently have strict floating point/constrained floating point enabled
for all targets. Constrained SDAG nodes get converted to the regular ones
before reaching the target layer. In theory this should be fine.

However, the changes are exposed to users through multiple clang options
already in use in the field, and the changes are _completely_ _untested_
on almost all of our targets. Bugs have already been found, like
"https://bugs.llvm.org/show_bug.cgi?id=45274";.

This patch disables constrained floating point options in clang everywhere
except X86 and SystemZ. A warning will be printed when this happens.

Use the new -fexperimental-strict-floating-point flag to force allowing
strict floating point on hosts that aren't already marked as supporting
it (X86 and SystemZ).

Differential Revision: https://reviews.llvm.org/D80952

Added: 
clang/test/CodeGen/fp-strictfp-exp.cpp
clang/test/CodeGen/fp-strictfp.cpp

Modified: 
clang/docs/ClangCommandLineReference.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/TargetInfo.h
clang/include/clang/Driver/Options.td
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/SystemZ.h
clang/lib/Basic/Targets/X86.h
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/aarch64-neon-misc-constrained.c
clang/test/CodeGen/aarch64-neon-scalar-x-indexed-elem-constrained.c
clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics-constrained.c
clang/test/CodeGen/arm-neon-directed-rounding-constrained.c
clang/test/CodeGen/arm64-vrnd-constrained.c
clang/test/CodeGen/builtins-ppc-fpconstrained.c
clang/test/CodeGen/fpconstrained-cmp-double.c
clang/test/CodeGen/fpconstrained-cmp-float.c
clang/test/CodeGen/fpconstrained.c
clang/test/CodeGen/fpconstrained.cpp

Removed: 




diff  --git a/clang/docs/ClangCommandLineReference.rst 
b/clang/docs/ClangCommandLineReference.rst
index 0b56b7ac4206..1613c8e45318 100644
--- a/clang/docs/ClangCommandLineReference.rst
+++ b/clang/docs/ClangCommandLineReference.rst
@@ -818,6 +818,10 @@ Discard value names in LLVM IR
 
 Enables an experimental new pass manager in LLVM.
 
+.. option:: -fexperimental-strict-floating-point
+
+Enables the use of non-default rounding modes and non-default exception 
handling on targets that are not currently ready.
+
 .. option:: -ffine-grained-bitfield-accesses, 
-fno-fine-grained-bitfield-accesses
 
 Use separate accesses for consecutive bitfield runs with legal widths and 
alignments.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index d465e00d4c70..67c0b4203420 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -58,6 +58,8 @@ CODEGENOPT(DisableLLVMPasses , 1, 0) ///< Don't run any LLVM 
IR passes to get
  ///< frontend.
 CODEGENOPT(DisableLifetimeMarkers, 1, 0) ///< Don't emit any lifetime markers
 CODEGENOPT(DisableO0ImplyOptNone , 1, 0) ///< Don't annonate function with 
optnone at O0
+CODEGENOPT(ExperimentalStrictFloatingPoint, 1, 0) ///< Enables the new, 
experimental
+  ///< strict floating point.
 CODEGENOPT(ExperimentalNewPassManager, 1, 0) ///< Enables the new, experimental
  ///< pass manager.
 CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new

diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index ceb24bce5978..b202d2abffa0 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -37,6 +37,12 @@ def note_fe_backend_plugin: Note<"%0">, BackendInfo;
 def warn_fe_override_module : Warning<
 "overriding the module target triple with %0">,
 InGroup>;
+def warn_fe_backend_unsupported_fp_rounding : Warning<
+"overriding currently unsupported rounding mode on this target">,
+InGroup;
+def warn_fe_backend_unsupported_fp_exceptions : Warning<
+"overriding currently unsupported use of floating point exceptions "
+"on this target">, InGroup;
 
 def remark_fe_backend_optimization_remark : Remark<"%0">, Backen

[clang] 523a851 - [FPEnv][Clang][Driver] Disable constrained floating point on targets lacking support."

2020-07-10 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-07-10T10:34:15-04:00
New Revision: 523a8513f8ba4d6b111496c541b9ba9f4d5f0261

URL: 
https://github.com/llvm/llvm-project/commit/523a8513f8ba4d6b111496c541b9ba9f4d5f0261
DIFF: 
https://github.com/llvm/llvm-project/commit/523a8513f8ba4d6b111496c541b9ba9f4d5f0261.diff

LOG: [FPEnv][Clang][Driver] Disable constrained floating point on targets 
lacking support."

Use the new -fexperimental-strict-floating-point flag in more cases to
fix the arm and aarch64 bots.

Differential Revision: https://reviews.llvm.org/D80952

Added: 


Modified: 
clang/test/CodeGen/fpconstrained-cmp-double.c
clang/test/CodeGen/fpconstrained-cmp-float.c

Removed: 




diff  --git a/clang/test/CodeGen/fpconstrained-cmp-double.c 
b/clang/test/CodeGen/fpconstrained-cmp-double.c
index 6f19db2099db..335b7e49b01d 100644
--- a/clang/test/CodeGen/fpconstrained-cmp-double.c
+++ b/clang/test/CodeGen/fpconstrained-cmp-double.c
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -ffp-exception-behavior=ignore -emit-llvm -o - %s | 
FileCheck %s -check-prefix=CHECK -check-prefix=FCMP
 // RUN: %clang_cc1 -ffp-exception-behavior=strict 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=EXCEPT
 // RUN: %clang_cc1 -ffp-exception-behavior=maytrap 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=MAYTRAP
-// RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=ignore -emit-llvm 
-o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=IGNORE
+// RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=ignore 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=IGNORE
 // RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=strict 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=EXCEPT
 // RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=maytrap 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=MAYTRAP
 

diff  --git a/clang/test/CodeGen/fpconstrained-cmp-float.c 
b/clang/test/CodeGen/fpconstrained-cmp-float.c
index bca0cdb7eda4..e9667904122b 100644
--- a/clang/test/CodeGen/fpconstrained-cmp-float.c
+++ b/clang/test/CodeGen/fpconstrained-cmp-float.c
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -ffp-exception-behavior=ignore -emit-llvm -o - %s | 
FileCheck %s -check-prefix=CHECK -check-prefix=FCMP
+// RUN: %clang_cc1 -ffp-exception-behavior=ignore 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=FCMP
 // RUN: %clang_cc1 -ffp-exception-behavior=strict 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=EXCEPT
 // RUN: %clang_cc1 -ffp-exception-behavior=maytrap 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=MAYTRAP
-// RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=ignore -emit-llvm 
-o - %s | FileCheck %s -check-prefix=CHECK -check-prefix=IGNORE
+// RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=ignore 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=IGNORE
 // RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=strict 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=EXCEPT
 // RUN: %clang_cc1 -frounding-math -ffp-exception-behavior=maytrap 
-fexperimental-strict-floating-point -emit-llvm -o - %s | FileCheck %s 
-check-prefix=CHECK -check-prefix=MAYTRAP
 



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


[clang] 15edd7a - [FPEnv] PowerPC-specific builtin constrained FP enablement

2020-06-25 Thread Kevin P. Neal via cfe-commits

Author: Andrew Wock
Date: 2020-06-25T11:42:58-04:00
New Revision: 15edd7aaa7142e5db2a6cf9b81e4514967431824

URL: 
https://github.com/llvm/llvm-project/commit/15edd7aaa7142e5db2a6cf9b81e4514967431824
DIFF: 
https://github.com/llvm/llvm-project/commit/15edd7aaa7142e5db2a6cf9b81e4514967431824.diff

LOG: [FPEnv] PowerPC-specific builtin constrained FP enablement

This change enables PowerPC compiler builtins to generate constrained
floating point operations when clang is indicated to do so.

A couple of possibly unexpected backend divergences between constrained
floating point and regular behavior are highlighted under the test tag
FIXME-CHECK. This may be something for those on the PPC backend to look
at.

Patch by: Drew Wock 

Differential Revision: https://reviews.llvm.org/D82020

Added: 
clang/test/CodeGen/builtins-ppc-fpconstrained.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 89ab1a3c2cb0..c43877e117eb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -14235,9 +14235,14 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
   case PPC::BI__builtin_vsx_xvsqrtdp: {
 llvm::Type *ResultType = ConvertType(E->getType());
 Value *X = EmitScalarExpr(E->getArg(0));
-ID = Intrinsic::sqrt;
-llvm::Function *F = CGM.getIntrinsic(ID, ResultType);
-return Builder.CreateCall(F, X);
+if (Builder.getIsFPConstrained()) {
+  llvm::Function *F = CGM.getIntrinsic(
+  Intrinsic::experimental_constrained_sqrt, ResultType);
+  return Builder.CreateConstrainedFPCall(F, X);
+} else {
+  llvm::Function *F = CGM.getIntrinsic(Intrinsic::sqrt, ResultType);
+  return Builder.CreateCall(F, X);
+}
   }
   // Count leading zeros
   case PPC::BI__builtin_altivec_vclzb:
@@ -14294,21 +14299,32 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 if (BuiltinID == PPC::BI__builtin_vsx_xvrdpim ||
 BuiltinID == PPC::BI__builtin_vsx_xvrspim)
-  ID = Intrinsic::floor;
+  ID = Builder.getIsFPConstrained()
+   ? Intrinsic::experimental_constrained_floor
+   : Intrinsic::floor;
 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpi ||
  BuiltinID == PPC::BI__builtin_vsx_xvrspi)
-  ID = Intrinsic::round;
+  ID = Builder.getIsFPConstrained()
+   ? Intrinsic::experimental_constrained_round
+   : Intrinsic::round;
 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpic ||
  BuiltinID == PPC::BI__builtin_vsx_xvrspic)
-  ID = Intrinsic::nearbyint;
+  ID = Builder.getIsFPConstrained()
+   ? Intrinsic::experimental_constrained_nearbyint
+   : Intrinsic::nearbyint;
 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpip ||
  BuiltinID == PPC::BI__builtin_vsx_xvrspip)
-  ID = Intrinsic::ceil;
+  ID = Builder.getIsFPConstrained()
+   ? Intrinsic::experimental_constrained_ceil
+   : Intrinsic::ceil;
 else if (BuiltinID == PPC::BI__builtin_vsx_xvrdpiz ||
  BuiltinID == PPC::BI__builtin_vsx_xvrspiz)
-  ID = Intrinsic::trunc;
+  ID = Builder.getIsFPConstrained()
+   ? Intrinsic::experimental_constrained_trunc
+   : Intrinsic::trunc;
 llvm::Function *F = CGM.getIntrinsic(ID, ResultType);
-return Builder.CreateCall(F, X);
+return Builder.getIsFPConstrained() ? Builder.CreateConstrainedFPCall(F, X)
+: Builder.CreateCall(F, X);
   }
 
   // Absolute value
@@ -14333,21 +14349,43 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-llvm::Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
+llvm::Function *F;
+if (Builder.getIsFPConstrained())
+  F = CGM.getIntrinsic(Intrinsic::experimental_constrained_fma, 
ResultType);
+else
+  F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
 switch (BuiltinID) {
   case PPC::BI__builtin_vsx_xvmaddadp:
   case PPC::BI__builtin_vsx_xvmaddasp:
-return Builder.CreateCall(F, {X, Y, Z});
+if (Builder.getIsFPConstrained())
+  return Builder.CreateConstrainedFPCall(F, {X, Y, Z});
+else
+  return Builder.CreateCall(F, {X, Y, Z});
   case PPC::BI__builtin_vsx_xvnmaddadp:
   case PPC::BI__builtin_vsx_xvnmaddasp:
-return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, Z}), "neg");
+if (Builder.getIsFPConstrained())
+  return Builder.CreateFNeg(
+  Builder.CreateConstrainedFPCall(F, {X, Y, Z}), "neg");
+else
+  return Builder.Creat

[clang] e91c4b2 - [NFC] Eliminate an unneeded -vv used in test development.

2020-06-26 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-06-26T11:09:16-04:00
New Revision: e91c4b2af2c03ef599623243e625f347e166673d

URL: 
https://github.com/llvm/llvm-project/commit/e91c4b2af2c03ef599623243e625f347e166673d
DIFF: 
https://github.com/llvm/llvm-project/commit/e91c4b2af2c03ef599623243e625f347e166673d.diff

LOG: [NFC] Eliminate an unneeded -vv used in test development.

Added: 


Modified: 
clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c 
b/clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
index 473d3ba53e96..d42fb1e02cad 100644
--- a/clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
+++ b/clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
@@ -12,7 +12,7 @@
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
 // RUN: -ffp-exception-behavior=strict \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone -o - %s \
-// RUN: | FileCheck -vv --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
 
 // REQUIRES: aarch64-registered-target
 



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


[clang] [FPEnv] Add strictfp in some C++ constructors lacking a FunctionDecl. (PR #74883)

2023-12-08 Thread Kevin P. Neal via cfe-commits

https://github.com/kpneal created 
https://github.com/llvm/llvm-project/pull/74883

Some C++ constructors require the strictfp attribute on all function calls but 
don't get it because the comstructor lacks a FunctionDecl. Use the IRBuilder's 
strictfp mode to communicate that the strictfp attribute is required. Note that 
the function calls that were missing the attribute were getting it from the 
IRBuilder but it then was getting lost when CGCall.cpp replaced all the 
attributes for the function call.

Verified with "https://reviews.llvm.org/D146845";.

>From eb43ba5adbf57988fdd5f490a74dc59d72f495e5 Mon Sep 17 00:00:00 2001
From: "Kevin P. Neal" 
Date: Fri, 8 Dec 2023 14:43:50 -0500
Subject: [PATCH] [FPEnv] Add strictfp in some C++ constructors lacking a
 FunctionDecl.

Some C++ constructors require the strictfp attribute on all function calls
but don't get it because the comstructor lacks a FunctionDecl. Use the
IRBuilder's strictfp mode to communicate that the strictfp attribute is
required. Note that the function calls that were missing the attribute
were getting it from the IRBuilder but it then was getting lost when
CGCall.cpp replaced all the attributes for the function call.

Verified with "https://reviews.llvm.org/D146845";.
---
 clang/include/clang/AST/ExprCXX.h|  4 ++
 clang/lib/CodeGen/CGCall.cpp |  8 +++
 clang/lib/CodeGen/CGDeclCXX.cpp  |  5 ++
 clang/test/CodeGen/fp-floatcontrol-class.cpp | 75 ++--
 4 files changed, 88 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 2427801643183..f9269082c3247 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1698,6 +1698,10 @@ class CXXConstructExpr : public Expr {
   SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
   void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
 
+  /// Determine whether the function was declared in source context
+  /// that requires constrained FP intrinsics
+  bool UsesFPIntrin() const { return Constructor->UsesFPIntrin(); }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == CXXConstructExprClass ||
T->getStmtClass() == CXXTemporaryObjectExprClass;
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index a24aeea7ae32b..7d1bb4dc75ab4 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5520,6 +5520,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   CGM.AdjustMemoryAttribute(CalleePtr->getName(), Callee.getAbstractInfo(),
 Attrs);
   }
+  // We may not have a FunctionDecl*, but we still need to support strictfp.
+  if (Builder.getIsFPConstrained()) {
+// All calls within a strictfp function are marked strictfp
+Attrs = Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::StrictFP);
+  }
+
   // Add call-site nomerge attribute if exists.
   if (InNoMergeAttributedStmt)
 Attrs = Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::NoMerge);
@@ -5587,10 +5593,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   !isa_and_nonnull(TargetDecl))
 EmitKCFIOperandBundle(ConcreteCallee, BundleList);
 
+#if 0 // XXX Why is this here? Duplicate!
   if (const FunctionDecl *FD = dyn_cast_or_null(CurFuncDecl))
 if (FD->hasAttr())
   // All calls within a strictfp function are marked strictfp
   Attrs = Attrs.addFnAttribute(getLLVMContext(), 
llvm::Attribute::StrictFP);
+#endif
 
   AssumeAlignedAttrEmitter AssumeAlignedAttrEmitter(*this, TargetDecl);
   Attrs = AssumeAlignedAttrEmitter.TryEmitAsCallSiteAttribute(Attrs);
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index e08a1e5f42df2..5700b7fcb49d3 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -1012,6 +1012,11 @@ void 
CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
 
   CurEHLocation = D->getBeginLoc();
 
+  if (const auto *CE = dyn_cast(D->getInit())) {
+if (CE->UsesFPIntrin())
+  Builder.setIsFPConstrained(true);
+  }
+
   StartFunction(GlobalDecl(D, DynamicInitKind::Initializer),
 getContext().VoidTy, Fn, getTypes().arrangeNullaryFunction(),
 FunctionArgList());
diff --git a/clang/test/CodeGen/fp-floatcontrol-class.cpp 
b/clang/test/CodeGen/fp-floatcontrol-class.cpp
index 83a27cb206eb8..c9953119fd3a2 100644
--- a/clang/test/CodeGen/fp-floatcontrol-class.cpp
+++ b/clang/test/CodeGen/fp-floatcontrol-class.cpp
@@ -1,3 +1,4 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --include-generated-funcs --version 4
 // RUN: %clang_cc1 -ffp-contract=on -triple x86_64-linux-gnu -emit-llvm -o - 
%s | FileCheck %s
 // Verify that float_control does not pertain to initializer expressions
 
@@ -6,14 +7,80 @@ float 

[clang] [clang] Additional FP classification functions (PR #69041)

2023-10-30 Thread Kevin P. Neal via cfe-commits

https://github.com/kpneal approved this pull request.

The rest LGTM.

https://github.com/llvm/llvm-project/pull/69041
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FPEnv] Add strictfp in some C++ constructors lacking a FunctionDecl. (PR #74883)

2023-12-14 Thread Kevin P. Neal via cfe-commits

https://github.com/kpneal updated 
https://github.com/llvm/llvm-project/pull/74883

>From eb43ba5adbf57988fdd5f490a74dc59d72f495e5 Mon Sep 17 00:00:00 2001
From: "Kevin P. Neal" 
Date: Fri, 8 Dec 2023 14:43:50 -0500
Subject: [PATCH 1/3] [FPEnv] Add strictfp in some C++ constructors lacking a
 FunctionDecl.

Some C++ constructors require the strictfp attribute on all function calls
but don't get it because the comstructor lacks a FunctionDecl. Use the
IRBuilder's strictfp mode to communicate that the strictfp attribute is
required. Note that the function calls that were missing the attribute
were getting it from the IRBuilder but it then was getting lost when
CGCall.cpp replaced all the attributes for the function call.

Verified with "https://reviews.llvm.org/D146845";.
---
 clang/include/clang/AST/ExprCXX.h|  4 ++
 clang/lib/CodeGen/CGCall.cpp |  8 +++
 clang/lib/CodeGen/CGDeclCXX.cpp  |  5 ++
 clang/test/CodeGen/fp-floatcontrol-class.cpp | 75 ++--
 4 files changed, 88 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 24278016431837..f9269082c32475 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1698,6 +1698,10 @@ class CXXConstructExpr : public Expr {
   SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
   void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
 
+  /// Determine whether the function was declared in source context
+  /// that requires constrained FP intrinsics
+  bool UsesFPIntrin() const { return Constructor->UsesFPIntrin(); }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == CXXConstructExprClass ||
T->getStmtClass() == CXXTemporaryObjectExprClass;
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index a24aeea7ae32bf..7d1bb4dc75ab45 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5520,6 +5520,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   CGM.AdjustMemoryAttribute(CalleePtr->getName(), Callee.getAbstractInfo(),
 Attrs);
   }
+  // We may not have a FunctionDecl*, but we still need to support strictfp.
+  if (Builder.getIsFPConstrained()) {
+// All calls within a strictfp function are marked strictfp
+Attrs = Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::StrictFP);
+  }
+
   // Add call-site nomerge attribute if exists.
   if (InNoMergeAttributedStmt)
 Attrs = Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::NoMerge);
@@ -5587,10 +5593,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   !isa_and_nonnull(TargetDecl))
 EmitKCFIOperandBundle(ConcreteCallee, BundleList);
 
+#if 0 // XXX Why is this here? Duplicate!
   if (const FunctionDecl *FD = dyn_cast_or_null(CurFuncDecl))
 if (FD->hasAttr())
   // All calls within a strictfp function are marked strictfp
   Attrs = Attrs.addFnAttribute(getLLVMContext(), 
llvm::Attribute::StrictFP);
+#endif
 
   AssumeAlignedAttrEmitter AssumeAlignedAttrEmitter(*this, TargetDecl);
   Attrs = AssumeAlignedAttrEmitter.TryEmitAsCallSiteAttribute(Attrs);
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index e08a1e5f42df20..5700b7fcb49d32 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -1012,6 +1012,11 @@ void 
CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
 
   CurEHLocation = D->getBeginLoc();
 
+  if (const auto *CE = dyn_cast(D->getInit())) {
+if (CE->UsesFPIntrin())
+  Builder.setIsFPConstrained(true);
+  }
+
   StartFunction(GlobalDecl(D, DynamicInitKind::Initializer),
 getContext().VoidTy, Fn, getTypes().arrangeNullaryFunction(),
 FunctionArgList());
diff --git a/clang/test/CodeGen/fp-floatcontrol-class.cpp 
b/clang/test/CodeGen/fp-floatcontrol-class.cpp
index 83a27cb206eb82..c9953119fd3a22 100644
--- a/clang/test/CodeGen/fp-floatcontrol-class.cpp
+++ b/clang/test/CodeGen/fp-floatcontrol-class.cpp
@@ -1,3 +1,4 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --include-generated-funcs --version 4
 // RUN: %clang_cc1 -ffp-contract=on -triple x86_64-linux-gnu -emit-llvm -o - 
%s | FileCheck %s
 // Verify that float_control does not pertain to initializer expressions
 
@@ -6,14 +7,80 @@ float z();
 #pragma float_control(except, on)
 class ON {
   float w = 2 + y() * z();
-  // CHECK-LABEL: define {{.*}} @_ZN2ONC2Ev{{.*}}
-  // CHECK: llvm.experimental.constrained.fmul{{.*}}tonearest{{.*}}strict
 };
 ON on;
 #pragma float_control(except, off)
 class OFF {
   float w = 2 + y() * z();
-  // CHECK-LABEL: define {{.*}} @_ZN3OFFC2Ev{{.*}}
-  // CHECK-NOT: llvm.experimental.constrained.fmul{{.*}}tonearest{{.*}}strict
 };
 OFF off;
+// CHECK-LABEL: define in

[clang] [FPEnv] Add strictfp in some C++ constructors lacking a FunctionDecl. (PR #74883)

2023-12-14 Thread Kevin P. Neal via cfe-commits


@@ -5587,10 +5593,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   !isa_and_nonnull(TargetDecl))
 EmitKCFIOperandBundle(ConcreteCallee, BundleList);
 
+#if 0 // XXX Why is this here? Duplicate!
   if (const FunctionDecl *FD = dyn_cast_or_null(CurFuncDecl))
 if (FD->hasAttr())
   // All calls within a strictfp function are marked strictfp
   Attrs = Attrs.addFnAttribute(getLLVMContext(), 
llvm::Attribute::StrictFP);
+#endif

kpneal wrote:

Done.

https://github.com/llvm/llvm-project/pull/74883
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FPEnv] Add strictfp in some C++ constructors lacking a FunctionDecl. (PR #74883)

2023-12-14 Thread Kevin P. Neal via cfe-commits


@@ -6,14 +7,80 @@ float z();
 #pragma float_control(except, on)
 class ON {
   float w = 2 + y() * z();
-  // CHECK-LABEL: define {{.*}} @_ZN2ONC2Ev{{.*}}
-  // CHECK: llvm.experimental.constrained.fmul{{.*}}tonearest{{.*}}strict
 };
 ON on;
 #pragma float_control(except, off)
 class OFF {
   float w = 2 + y() * z();
-  // CHECK-LABEL: define {{.*}} @_ZN3OFFC2Ev{{.*}}
-  // CHECK-NOT: llvm.experimental.constrained.fmul{{.*}}tonearest{{.*}}strict
 };
 OFF off;
+// CHECK-LABEL: define internal void @__cxx_global_var_init(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] section ".text.startup" {

kpneal wrote:

I missed the argument to update_cc_test_checks.py that includes the attribute 
comments. Fixed. Is the new comment about checking for strictfp sufficient? Or 
do I need to include a mention of the documentation in the LangRef?

https://github.com/llvm/llvm-project/pull/74883
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FPEnv] Add strictfp in some C++ constructors lacking a FunctionDecl. (PR #74883)

2024-03-08 Thread Kevin P. Neal via cfe-commits

https://github.com/kpneal closed https://github.com/llvm/llvm-project/pull/74883
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FPEnv] Add strictfp in some C++ constructors lacking a FunctionDecl. (PR #74883)

2024-03-08 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

OK, I'll head in the direction you've pointed. Thanks for your time!

https://github.com/llvm/llvm-project/pull/74883
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [FPEnv] Add strictfp in some C++ constructors lacking a FunctionDecl. (PR #74883)

2024-01-16 Thread Kevin P. Neal via cfe-commits

https://github.com/kpneal updated 
https://github.com/llvm/llvm-project/pull/74883

>From eb43ba5adbf57988fdd5f490a74dc59d72f495e5 Mon Sep 17 00:00:00 2001
From: "Kevin P. Neal" 
Date: Fri, 8 Dec 2023 14:43:50 -0500
Subject: [PATCH 1/5] [FPEnv] Add strictfp in some C++ constructors lacking a
 FunctionDecl.

Some C++ constructors require the strictfp attribute on all function calls
but don't get it because the comstructor lacks a FunctionDecl. Use the
IRBuilder's strictfp mode to communicate that the strictfp attribute is
required. Note that the function calls that were missing the attribute
were getting it from the IRBuilder but it then was getting lost when
CGCall.cpp replaced all the attributes for the function call.

Verified with "https://reviews.llvm.org/D146845";.
---
 clang/include/clang/AST/ExprCXX.h|  4 ++
 clang/lib/CodeGen/CGCall.cpp |  8 +++
 clang/lib/CodeGen/CGDeclCXX.cpp  |  5 ++
 clang/test/CodeGen/fp-floatcontrol-class.cpp | 75 ++--
 4 files changed, 88 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 24278016431837..f9269082c32475 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1698,6 +1698,10 @@ class CXXConstructExpr : public Expr {
   SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; }
   void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; }
 
+  /// Determine whether the function was declared in source context
+  /// that requires constrained FP intrinsics
+  bool UsesFPIntrin() const { return Constructor->UsesFPIntrin(); }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == CXXConstructExprClass ||
T->getStmtClass() == CXXTemporaryObjectExprClass;
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index a24aeea7ae32bf..7d1bb4dc75ab45 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5520,6 +5520,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   CGM.AdjustMemoryAttribute(CalleePtr->getName(), Callee.getAbstractInfo(),
 Attrs);
   }
+  // We may not have a FunctionDecl*, but we still need to support strictfp.
+  if (Builder.getIsFPConstrained()) {
+// All calls within a strictfp function are marked strictfp
+Attrs = Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::StrictFP);
+  }
+
   // Add call-site nomerge attribute if exists.
   if (InNoMergeAttributedStmt)
 Attrs = Attrs.addFnAttribute(getLLVMContext(), llvm::Attribute::NoMerge);
@@ -5587,10 +5593,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   !isa_and_nonnull(TargetDecl))
 EmitKCFIOperandBundle(ConcreteCallee, BundleList);
 
+#if 0 // XXX Why is this here? Duplicate!
   if (const FunctionDecl *FD = dyn_cast_or_null(CurFuncDecl))
 if (FD->hasAttr())
   // All calls within a strictfp function are marked strictfp
   Attrs = Attrs.addFnAttribute(getLLVMContext(), 
llvm::Attribute::StrictFP);
+#endif
 
   AssumeAlignedAttrEmitter AssumeAlignedAttrEmitter(*this, TargetDecl);
   Attrs = AssumeAlignedAttrEmitter.TryEmitAsCallSiteAttribute(Attrs);
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index e08a1e5f42df20..5700b7fcb49d32 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -1012,6 +1012,11 @@ void 
CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
 
   CurEHLocation = D->getBeginLoc();
 
+  if (const auto *CE = dyn_cast(D->getInit())) {
+if (CE->UsesFPIntrin())
+  Builder.setIsFPConstrained(true);
+  }
+
   StartFunction(GlobalDecl(D, DynamicInitKind::Initializer),
 getContext().VoidTy, Fn, getTypes().arrangeNullaryFunction(),
 FunctionArgList());
diff --git a/clang/test/CodeGen/fp-floatcontrol-class.cpp 
b/clang/test/CodeGen/fp-floatcontrol-class.cpp
index 83a27cb206eb82..c9953119fd3a22 100644
--- a/clang/test/CodeGen/fp-floatcontrol-class.cpp
+++ b/clang/test/CodeGen/fp-floatcontrol-class.cpp
@@ -1,3 +1,4 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --include-generated-funcs --version 4
 // RUN: %clang_cc1 -ffp-contract=on -triple x86_64-linux-gnu -emit-llvm -o - 
%s | FileCheck %s
 // Verify that float_control does not pertain to initializer expressions
 
@@ -6,14 +7,80 @@ float z();
 #pragma float_control(except, on)
 class ON {
   float w = 2 + y() * z();
-  // CHECK-LABEL: define {{.*}} @_ZN2ONC2Ev{{.*}}
-  // CHECK: llvm.experimental.constrained.fmul{{.*}}tonearest{{.*}}strict
 };
 ON on;
 #pragma float_control(except, off)
 class OFF {
   float w = 2 + y() * z();
-  // CHECK-LABEL: define {{.*}} @_ZN3OFFC2Ev{{.*}}
-  // CHECK-NOT: llvm.experimental.constrained.fmul{{.*}}tonearest{{.*}}strict
 };
 OFF off;
+// CHECK-LABEL: define in

[clang] 89d6c28 - [SystemZ] Use FNeg in s390x clang builtins

2020-01-02 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-01-02T12:14:43-05:00
New Revision: 89d6c288ba5adb20d92142e9425f7ab79b8f159e

URL: 
https://github.com/llvm/llvm-project/commit/89d6c288ba5adb20d92142e9425f7ab79b8f159e
DIFF: 
https://github.com/llvm/llvm-project/commit/89d6c288ba5adb20d92142e9425f7ab79b8f159e.diff

LOG: [SystemZ] Use FNeg in s390x clang builtins

The s390x builtins are still using FSub instead of FNeg. Correct that.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-systemz-vector.c
clang/test/CodeGen/builtins-systemz-vector2.c
clang/test/CodeGen/builtins-systemz-zvector.c
clang/test/CodeGen/builtins-systemz-zvector2.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index be02004bf54b..12517709573a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -13292,9 +13292,8 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned 
BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType);
 Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
-return Builder.CreateCall(F, {X, Y, Builder.CreateFSub(Zero, Z, "sub")});
+return Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")});
   }
   case SystemZ::BI__builtin_s390_vfnmasb:
   case SystemZ::BI__builtin_s390_vfnmadb: {
@@ -13302,9 +13301,8 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned 
BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType);
 Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
-return Builder.CreateFSub(Zero, Builder.CreateCall(F, {X, Y, Z}), "sub");
+return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, Z}), "neg");
   }
   case SystemZ::BI__builtin_s390_vfnmssb:
   case SystemZ::BI__builtin_s390_vfnmsdb: {
@@ -13312,10 +13310,9 @@ Value 
*CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType);
 Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
-Value *NegZ = Builder.CreateFSub(Zero, Z, "sub");
-return Builder.CreateFSub(Zero, Builder.CreateCall(F, {X, Y, NegZ}));
+Value *NegZ = Builder.CreateFNeg(Z, "neg");
+return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, NegZ}));
   }
   case SystemZ::BI__builtin_s390_vflpsb:
   case SystemZ::BI__builtin_s390_vflpdb: {
@@ -13328,9 +13325,8 @@ Value *CodeGenFunction::EmitSystemZBuiltinExpr(unsigned 
BuiltinID,
   case SystemZ::BI__builtin_s390_vflndb: {
 llvm::Type *ResultType = ConvertType(E->getType());
 Value *X = EmitScalarExpr(E->getArg(0));
-Value *Zero = llvm::ConstantFP::getZeroValueForNegation(ResultType);
 Function *F = CGM.getIntrinsic(Intrinsic::fabs, ResultType);
-return Builder.CreateFSub(Zero, Builder.CreateCall(F, X), "sub");
+return Builder.CreateFNeg(Builder.CreateCall(F, X), "neg");
   }
   case SystemZ::BI__builtin_s390_vfisb:
   case SystemZ::BI__builtin_s390_vfidb: {

diff  --git a/clang/test/CodeGen/builtins-systemz-vector.c 
b/clang/test/CodeGen/builtins-systemz-vector.c
index 85cdc30aa54c..116bd8fa492a 100644
--- a/clang/test/CodeGen/builtins-systemz-vector.c
+++ b/clang/test/CodeGen/builtins-systemz-vector.c
@@ -584,14 +584,14 @@ void test_float(void) {
   vd = __builtin_s390_vfmadb(vd, vd, vd);
   // CHECK: call <2 x double> @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x 
double> %{{.*}}, <2 x double> %{{.*}})
   vd = __builtin_s390_vfmsdb(vd, vd, vd);
-  // CHECK: [[NEG:%[^ ]+]] = fsub <2 x double> , %{{.*}}
+  // CHECK: [[NEG:%[^ ]+]] = fneg <2 x double> %{{.*}}
   // CHECK: call <2 x double> @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x 
double> %{{.*}}, <2 x double> [[NEG]])
 
   vd = __builtin_s390_vflpdb(vd);
   // CHECK: call <2 x double> @llvm.fabs.v2f64(<2 x double> %{{.*}})
   vd = __builtin_s390_vflndb(vd);
   // CHECK: [[ABS:%[^ ]+]] = call <2 x double> @llvm.fabs.v2f64(<2 x double> 
%{{.*}})
-  // CHECK: fsub <2 x double> , 
[[ABS]]
+  // CHECK: fneg <2 x double> [[ABS]]
 
   vd = __builtin_s390_vfidb(vd, 0, 0);
   // CHECK: call <2 x double> @llvm.rint.v2f64(<2 x double> %{{.*}})

diff  --git a/clang/test/CodeGen/builtins-systemz-vector2.c 
b/clang/test/CodeGen/builtins-systemz-vector2.c
index a17cdf0a5ae6..0a9906002f2b 100644
--- a/clang/test/CodeGen/builtins-systemz-vector2.c
+++ b/clang/test/CodeGen/builtins-systemz-vector2.c
@@ -64,11 +64,11 @@ void test_float(void) {
 
   vd = __builtin_s390_vfnmadb(vd,

[clang] acd4950 - [FPEnv] Correct constrained metadata in fp16-ops-strict.c

2020-12-08 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-12-08T10:18:32-05:00
New Revision: acd4950d4f1e4ef5375a8a894a5b359caf7e844b

URL: 
https://github.com/llvm/llvm-project/commit/acd4950d4f1e4ef5375a8a894a5b359caf7e844b
DIFF: 
https://github.com/llvm/llvm-project/commit/acd4950d4f1e4ef5375a8a894a5b359caf7e844b.diff

LOG: [FPEnv] Correct constrained metadata in fp16-ops-strict.c

This test shows we're in some cases not getting strictfp information from
the AST. Correct that.

Differential Revision: https://reviews.llvm.org/D92596

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGen/fp16-ops-strictfp.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 4210e810acb7..973cefd831e6 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2550,6 +2550,7 @@ ScalarExprEmitter::EmitScalarPrePostIncDec(const 
UnaryOperator *E, LValue LV,
   } else if (type->isRealFloatingType()) {
 // Add the inc/dec to the real part.
 llvm::Value *amt;
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 
 if (type->isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
   // Another special case: half FP increment should be done via float
@@ -3001,6 +3002,7 @@ LValue ScalarExprEmitter::EmitCompoundAssignLValue(
   else
 OpInfo.LHS = EmitLoadOfLValue(LHSLV, E->getExprLoc());
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, OpInfo.FPFeatures);
   SourceLocation Loc = E->getExprLoc();
   OpInfo.LHS =
   EmitScalarConversion(OpInfo.LHS, LHSTy, E->getComputationLHSType(), Loc);

diff  --git a/clang/test/CodeGen/fp16-ops-strictfp.c 
b/clang/test/CodeGen/fp16-ops-strictfp.c
index fd50d56a852c..d81febad0c36 100644
--- a/clang/test/CodeGen/fp16-ops-strictfp.c
+++ b/clang/test/CodeGen/fp16-ops-strictfp.c
@@ -11,7 +11,6 @@
 //
 // Test that the constrained intrinsics are picking up the exception
 // metadata from the AST instead of the global default from the command line.
-// FIXME: All cases of "fpexcept.maytrap" in this test are wrong.
 
 #pragma float_control(except, on)
 
@@ -62,31 +61,31 @@ void foo(void) {
   // NOTNATIVE: store {{.*}} half {{.*}}, half*
   h1 = +h1;
 
-  // NATIVE-HALF: call half @llvm.experimental.constrained.fadd.f16(half 
%{{.*}}, half 0xH3C00, metadata !"round.tonearest", metadata 
!"fpexcept.maytrap")
-  // NOTNATIVE: call float @llvm.experimental.constrained.fpext.f32.f16(half 
%{{.*}}, metadata !"fpexcept.maytrap")
-  // NOTNATIVE: call float @llvm.experimental.constrained.fadd.f32(float 
%{{.*}}, float {{.*}}, metadata !"round.tonearest", metadata 
!"fpexcept.maytrap")
-  // NOTNATIVE: call half @llvm.experimental.constrained.fptrunc.f16.f32(float 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.maytrap")
+  // NATIVE-HALF: call half @llvm.experimental.constrained.fadd.f16(half 
%{{.*}}, half 0xH3C00, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  // NOTNATIVE: call float @llvm.experimental.constrained.fpext.f32.f16(half 
%{{.*}}, metadata !"fpexcept.strict")
+  // NOTNATIVE: call float @llvm.experimental.constrained.fadd.f32(float 
%{{.*}}, float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  // NOTNATIVE: call half @llvm.experimental.constrained.fptrunc.f16.f32(float 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
   // CHECK: store {{.*}} half {{.*}}, half*
   h1++;
 
-  // NATIVE-HALF: call half @llvm.experimental.constrained.fadd.f16(half 
%{{.*}}, half 0xH3C00, metadata !"round.tonearest", metadata 
!"fpexcept.maytrap")
-  // NOTNATIVE: call float @llvm.experimental.constrained.fpext.f32.f16(half 
%{{.*}}, metadata !"fpexcept.maytrap")
-  // NOTNATIVE: call float @llvm.experimental.constrained.fadd.f32(float 
%{{.*}}, float {{.*}}, metadata !"round.tonearest", metadata 
!"fpexcept.maytrap")
-  // NOTNATIVE: call half @llvm.experimental.constrained.fptrunc.f16.f32(float 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.maytrap")
+  // NATIVE-HALF: call half @llvm.experimental.constrained.fadd.f16(half 
%{{.*}}, half 0xH3C00, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  // NOTNATIVE: call float @llvm.experimental.constrained.fpext.f32.f16(half 
%{{.*}}, metadata !"fpexcept.strict")
+  // NOTNATIVE: call float @llvm.experimental.constrained.fadd.f32(float 
%{{.*}}, float {{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  // NOTNATIVE: call half @llvm.experimental.constrained.fptrunc.f16.f32(float 
%{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
   // CHECK: store {{.*}} half {{.*}}, half*
   ++h1;
 
-  // NATIVE-HALF: call half @llvm.experimental.constrained.fadd.f16(half 
%{{.*}}, half 0xHBC00, metadata !"round.tonearest", metadata 
!"fpexcept.maytrap")
-  // NOTNATIVE: call float @llvm.experimental.constrained.fpext.f32.f16(half 
%{{.*}}, meta

[clang] 67a1ffd - [FPEnv] Teach the IRBuilder about invoke's correct use of the strictfp attribute.

2020-12-15 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-12-15T12:38:10-05:00
New Revision: 67a1ffd88ac08526bb6cfc7b3f607e6668ba1c70

URL: 
https://github.com/llvm/llvm-project/commit/67a1ffd88ac08526bb6cfc7b3f607e6668ba1c70
DIFF: 
https://github.com/llvm/llvm-project/commit/67a1ffd88ac08526bb6cfc7b3f607e6668ba1c70.diff

LOG: [FPEnv] Teach the IRBuilder about invoke's correct use of the strictfp 
attribute.

Similar to D69312, and documented in D69839, the IRBuilder needs to add
the strictfp attribute to invoke instructions when constrained floating
point is enabled.

Differential Revision: https://reviews.llvm.org/D93134

Added: 
clang/test/CodeGen/exceptions-strictfp.c

Modified: 
llvm/include/llvm/IR/IRBuilder.h

Removed: 




diff  --git a/clang/test/CodeGen/exceptions-strictfp.c 
b/clang/test/CodeGen/exceptions-strictfp.c
new file mode 100644
index ..f1c279908e45
--- /dev/null
+++ b/clang/test/CodeGen/exceptions-strictfp.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple armv7-apple-unknown -ffp-exception-behavior=strict 
-fexperimental-strict-floating-point -emit-llvm -o - %s -fexceptions 
-fsjlj-exceptions -fblocks | FileCheck %s
+
+// Verify strictfp attributes on invoke calls (and therefore also on
+// function definitions).
+
+// rdar://problem/8621849
+void test1() {
+  extern void test1_helper(void (^)(int));
+
+  // CHECK: define arm_aapcscc void @test1() [[STRICTFP0:#[0-9]+]] personality 
i8* bitcast (i32 (...)* @__gcc_personality_sj0 to i8*)
+
+  __block int x = 10;
+
+  // CHECK: invoke arm_aapcscc void @test1_helper({{.*}}) [[STRICTFP1:#[0-9]+]]
+  test1_helper(^(int v) { x = v; });
+
+  // CHECK:  landingpad { i8*, i32 }
+  // CHECK-NEXT:   cleanup
+}
+
+void test2_helper();
+void test2() {
+  // CHECK: define arm_aapcscc void @test2() [[STRICTFP0]] personality i8* 
bitcast (i32 (...)* @__gcc_personality_sj0 to i8*) {
+  __block int x = 10;
+  ^{ (void)x; };
+
+  // CHECK: invoke arm_aapcscc void @test2_helper({{.*}}) [[STRICTFP1:#[0-9]+]]
+  test2_helper(5, 6, 7);
+
+  // CHECK:  landingpad { i8*, i32 }
+  // CHECK-NEXT:   cleanup
+}
+void test2_helper(int x, int y) {
+}
+
+// CHECK: attributes [[STRICTFP0]] = { {{.*}}strictfp{{.*}} }
+// CHECK: attributes [[STRICTFP1]] = { strictfp }

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index c2b3446d159f..6010f1a706a3 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -301,7 +301,7 @@ class IRBuilderBase {
 }
   }
 
-  void setConstrainedFPCallAttr(CallInst *I) {
+  void setConstrainedFPCallAttr(CallBase *I) {
 I->addAttribute(AttributeList::FunctionIndex, Attribute::StrictFP);
   }
 
@@ -1023,16 +1023,21 @@ class IRBuilderBase {
ArrayRef Args,
ArrayRef OpBundles,
const Twine &Name = "") {
-return Insert(
-InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, 
OpBundles),
-Name);
+InvokeInst *II =
+InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, 
OpBundles);
+if (IsFPConstrained)
+  setConstrainedFPCallAttr(II);
+return Insert(II, Name);
   }
   InvokeInst *CreateInvoke(FunctionType *Ty, Value *Callee,
BasicBlock *NormalDest, BasicBlock *UnwindDest,
ArrayRef Args = None,
const Twine &Name = "") {
-return Insert(InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args),
-  Name);
+InvokeInst *II =
+InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args);
+if (IsFPConstrained)
+  setConstrainedFPCallAttr(II);
+return Insert(II, Name);
   }
 
   InvokeInst *CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest,



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


[clang] 2ec5973 - Revert "[FPEnv] Teach the IRBuilder about invoke's correct use of the strictfp attribute."

2020-12-15 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-12-15T12:58:47-05:00
New Revision: 2ec5973fddb07e66ae0df7d0aac2cda55387b0bd

URL: 
https://github.com/llvm/llvm-project/commit/2ec5973fddb07e66ae0df7d0aac2cda55387b0bd
DIFF: 
https://github.com/llvm/llvm-project/commit/2ec5973fddb07e66ae0df7d0aac2cda55387b0bd.diff

LOG: Revert "[FPEnv] Teach the IRBuilder about invoke's correct use of the 
strictfp attribute."

The test is busted on some hosts that aren't the one I'm using.

This reverts commit 67a1ffd88ac08526bb6cfc7b3f607e6668ba1c70.

Added: 


Modified: 
llvm/include/llvm/IR/IRBuilder.h

Removed: 
clang/test/CodeGen/exceptions-strictfp.c



diff  --git a/clang/test/CodeGen/exceptions-strictfp.c 
b/clang/test/CodeGen/exceptions-strictfp.c
deleted file mode 100644
index f1c279908e45..
--- a/clang/test/CodeGen/exceptions-strictfp.c
+++ /dev/null
@@ -1,37 +0,0 @@
-// RUN: %clang_cc1 -triple armv7-apple-unknown -ffp-exception-behavior=strict 
-fexperimental-strict-floating-point -emit-llvm -o - %s -fexceptions 
-fsjlj-exceptions -fblocks | FileCheck %s
-
-// Verify strictfp attributes on invoke calls (and therefore also on
-// function definitions).
-
-// rdar://problem/8621849
-void test1() {
-  extern void test1_helper(void (^)(int));
-
-  // CHECK: define arm_aapcscc void @test1() [[STRICTFP0:#[0-9]+]] personality 
i8* bitcast (i32 (...)* @__gcc_personality_sj0 to i8*)
-
-  __block int x = 10;
-
-  // CHECK: invoke arm_aapcscc void @test1_helper({{.*}}) [[STRICTFP1:#[0-9]+]]
-  test1_helper(^(int v) { x = v; });
-
-  // CHECK:  landingpad { i8*, i32 }
-  // CHECK-NEXT:   cleanup
-}
-
-void test2_helper();
-void test2() {
-  // CHECK: define arm_aapcscc void @test2() [[STRICTFP0]] personality i8* 
bitcast (i32 (...)* @__gcc_personality_sj0 to i8*) {
-  __block int x = 10;
-  ^{ (void)x; };
-
-  // CHECK: invoke arm_aapcscc void @test2_helper({{.*}}) [[STRICTFP1:#[0-9]+]]
-  test2_helper(5, 6, 7);
-
-  // CHECK:  landingpad { i8*, i32 }
-  // CHECK-NEXT:   cleanup
-}
-void test2_helper(int x, int y) {
-}
-
-// CHECK: attributes [[STRICTFP0]] = { {{.*}}strictfp{{.*}} }
-// CHECK: attributes [[STRICTFP1]] = { strictfp }

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index 6010f1a706a3..c2b3446d159f 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -301,7 +301,7 @@ class IRBuilderBase {
 }
   }
 
-  void setConstrainedFPCallAttr(CallBase *I) {
+  void setConstrainedFPCallAttr(CallInst *I) {
 I->addAttribute(AttributeList::FunctionIndex, Attribute::StrictFP);
   }
 
@@ -1023,21 +1023,16 @@ class IRBuilderBase {
ArrayRef Args,
ArrayRef OpBundles,
const Twine &Name = "") {
-InvokeInst *II =
-InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, 
OpBundles);
-if (IsFPConstrained)
-  setConstrainedFPCallAttr(II);
-return Insert(II, Name);
+return Insert(
+InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, 
OpBundles),
+Name);
   }
   InvokeInst *CreateInvoke(FunctionType *Ty, Value *Callee,
BasicBlock *NormalDest, BasicBlock *UnwindDest,
ArrayRef Args = None,
const Twine &Name = "") {
-InvokeInst *II =
-InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args);
-if (IsFPConstrained)
-  setConstrainedFPCallAttr(II);
-return Insert(II, Name);
+return Insert(InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args),
+  Name);
   }
 
   InvokeInst *CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest,



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


[clang] 7fef551 - Revert "Revert "[FPEnv] Teach the IRBuilder about invoke's correct use of the strictfp attribute.""

2020-12-18 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-12-18T12:42:06-05:00
New Revision: 7fef551cb123d9f1956f8ec7a142bd8a63d25fa9

URL: 
https://github.com/llvm/llvm-project/commit/7fef551cb123d9f1956f8ec7a142bd8a63d25fa9
DIFF: 
https://github.com/llvm/llvm-project/commit/7fef551cb123d9f1956f8ec7a142bd8a63d25fa9.diff

LOG: Revert "Revert "[FPEnv] Teach the IRBuilder about invoke's correct use of 
the strictfp attribute.""

Similar to D69312, and documented in D69839, the IRBuilder needs to add
the strictfp attribute to invoke instructions when constrained floating
point is enabled.

This is try 2, with the test corrected.

Differential Revision: https://reviews.llvm.org/D93134

Added: 
clang/test/CodeGen/exceptions-strictfp.c

Modified: 
llvm/include/llvm/IR/IRBuilder.h

Removed: 




diff  --git a/clang/test/CodeGen/exceptions-strictfp.c 
b/clang/test/CodeGen/exceptions-strictfp.c
new file mode 100644
index ..6f9e9f891b6c
--- /dev/null
+++ b/clang/test/CodeGen/exceptions-strictfp.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple armv7-apple-unknown -ffp-exception-behavior=strict 
-fexperimental-strict-floating-point -emit-llvm -o - %s -fexceptions 
-exception-model=sjlj -fblocks | FileCheck %s
+
+// Verify strictfp attributes on invoke calls (and therefore also on
+// function definitions).
+
+// rdar://problem/8621849
+void test1() {
+  extern void test1_helper(void (^)(int));
+
+  // CHECK: define arm_aapcscc void @test1() [[STRICTFP0:#[0-9]+]] personality 
i8* bitcast (i32 (...)* @__gcc_personality_sj0 to i8*)
+
+  __block int x = 10;
+
+  // CHECK: invoke arm_aapcscc void @test1_helper({{.*}}) [[STRICTFP1:#[0-9]+]]
+  test1_helper(^(int v) { x = v; });
+
+  // CHECK:  landingpad { i8*, i32 }
+  // CHECK-NEXT:   cleanup
+}
+
+void test2_helper();
+void test2() {
+  // CHECK: define arm_aapcscc void @test2() [[STRICTFP0]] personality i8* 
bitcast (i32 (...)* @__gcc_personality_sj0 to i8*) {
+  __block int x = 10;
+  ^{ (void)x; };
+
+  // CHECK: invoke arm_aapcscc void @test2_helper({{.*}}) [[STRICTFP1:#[0-9]+]]
+  test2_helper(5, 6, 7);
+
+  // CHECK:  landingpad { i8*, i32 }
+  // CHECK-NEXT:   cleanup
+}
+void test2_helper(int x, int y) {
+}
+
+// CHECK: attributes [[STRICTFP0]] = { {{.*}}strictfp{{.*}} }
+// CHECK: attributes [[STRICTFP1]] = { strictfp }

diff  --git a/llvm/include/llvm/IR/IRBuilder.h 
b/llvm/include/llvm/IR/IRBuilder.h
index 56005b26a538..6bc5e89453ad 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -350,7 +350,7 @@ class IRBuilderBase {
 }
   }
 
-  void setConstrainedFPCallAttr(CallInst *I) {
+  void setConstrainedFPCallAttr(CallBase *I) {
 I->addAttribute(AttributeList::FunctionIndex, Attribute::StrictFP);
   }
 
@@ -1088,16 +1088,21 @@ class IRBuilderBase {
ArrayRef Args,
ArrayRef OpBundles,
const Twine &Name = "") {
-return Insert(
-InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, 
OpBundles),
-Name);
+InvokeInst *II =
+InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args, 
OpBundles);
+if (IsFPConstrained)
+  setConstrainedFPCallAttr(II);
+return Insert(II, Name);
   }
   InvokeInst *CreateInvoke(FunctionType *Ty, Value *Callee,
BasicBlock *NormalDest, BasicBlock *UnwindDest,
ArrayRef Args = None,
const Twine &Name = "") {
-return Insert(InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args),
-  Name);
+InvokeInst *II =
+InvokeInst::Create(Ty, Callee, NormalDest, UnwindDest, Args);
+if (IsFPConstrained)
+  setConstrainedFPCallAttr(II);
+return Insert(II, Name);
   }
 
   InvokeInst *CreateInvoke(FunctionCallee Callee, BasicBlock *NormalDest,



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


[clang] ac523d2 - [FPEnv][Clang][Driver] Use MarshallingInfoFlag for -fexperimental-strict-floating-point

2020-11-12 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-11-12T12:51:35-05:00
New Revision: ac523d2de51c4119ae6233200af07599d61de1fc

URL: 
https://github.com/llvm/llvm-project/commit/ac523d2de51c4119ae6233200af07599d61de1fc
DIFF: 
https://github.com/llvm/llvm-project/commit/ac523d2de51c4119ae6233200af07599d61de1fc.diff

LOG: [FPEnv][Clang][Driver] Use MarshallingInfoFlag for 
-fexperimental-strict-floating-point

As of D80952 we are disabling strict floating point on all hosts except
those that are explicitly listed as supported. Use of strict floating point
on other hosts requires use of the -fexperimental-strict-floating-point
flag. This is to avoid bugs like "https://bugs.llvm.org/show_bug.cgi?id=45329";
(which has an incorrect link in the previous review).

In the review for D80952 I was asked to mark the -fexperimental option as
a MarshallingInfoFlag. This patch does exactly that.

Differential Revision: https://reviews.llvm.org/D88987

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Frontend/CompilerInvocation.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 6df4a0222484..245e6765d613 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1308,7 +1308,8 @@ def fexperimental_new_pass_manager : Flag<["-"], 
"fexperimental-new-pass-manager
   HelpText<"Enables an experimental new pass manager in LLVM.">;
 def fexperimental_strict_floating_point : Flag<["-"], 
"fexperimental-strict-floating-point">,
   Group, Flags<[CC1Option]>,
-  HelpText<"Enables experimental strict floating point in LLVM.">;
+  HelpText<"Enables experimental strict floating point in LLVM.">,
+  MarshallingInfoFlag<"LangOpts->ExpStrictFP">;
 def finput_charset_EQ : Joined<["-"], "finput-charset=">, Group;
 def fexec_charset_EQ : Joined<["-"], "fexec-charset=">, Group;
 def finstrument_functions : Flag<["-"], "finstrument-functions">, 
Group, Flags<[CC1Option]>,

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index b2ce88f6cf6b..ffcc3d359e62 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3335,9 +3335,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList 
&Args, InputKind IK,
   Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
   }
 
-  if (Args.hasArg(OPT_fexperimental_strict_floating_point))
-Opts.ExpStrictFP = true;
-
   auto FPRM = llvm::RoundingMode::NearestTiesToEven;
   if (Args.hasArg(OPT_frounding_math)) {
 FPRM = llvm::RoundingMode::Dynamic;



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


[clang] abfbc55 - [FPEnv] clang should get from the AST the metadata for constrained FP builtins

2020-11-30 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-11-30T11:59:37-05:00
New Revision: abfbc5579bd4507ae286d4f29f8a157de0629372

URL: 
https://github.com/llvm/llvm-project/commit/abfbc5579bd4507ae286d4f29f8a157de0629372
DIFF: 
https://github.com/llvm/llvm-project/commit/abfbc5579bd4507ae286d4f29f8a157de0629372.diff

LOG: [FPEnv] clang should get from the AST the metadata for constrained FP 
builtins

Currently clang is not correctly retrieving from the AST the metadata for
constrained FP builtins. This patch fixes that for the non-target specific
builtins.

Differential Revision: https://reviews.llvm.org/D92122

Added: 
clang/test/CodeGen/strictfp_fpclassify.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtin_float_strictfp.c
clang/test/CodeGen/constrained-math-builtins.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 828d66f83de9..73897a27bd94 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -440,6 +440,7 @@ static Value 
*emitUnaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
 
   if (CGF.Builder.getIsFPConstrained()) {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0 });
   } else {
@@ -457,6 +458,7 @@ static Value 
*emitBinaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
 
   if (CGF.Builder.getIsFPConstrained()) {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1 });
   } else {
@@ -475,6 +477,7 @@ static Value 
*emitTernaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
   llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2));
 
   if (CGF.Builder.getIsFPConstrained()) {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1, Src2 });
   } else {
@@ -556,6 +559,7 @@ emitMaybeConstrainedFPToIntRoundBuiltin(CodeGenFunction 
&CGF, const CallExpr *E,
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
 
   if (CGF.Builder.getIsFPConstrained()) {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID,
{ResultType, Src0->getType()});
 return CGF.Builder.CreateConstrainedFPCall(F, {Src0});
@@ -2218,6 +,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 case Builtin::BI__builtin_fmodf16:
 case Builtin::BI__builtin_fmodl:
 case Builtin::BI__builtin_fmodf128: {
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
   Value *Arg1 = EmitScalarExpr(E->getArg(0));
   Value *Arg2 = EmitScalarExpr(E->getArg(1));
   return RValue::get(Builder.CreateFRem(Arg1, Arg2, "fmod"));
@@ -2828,6 +2833,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_isunordered: {
 // Ordered comparisons: we know the arguments to these are matching scalar
 // floating point values.
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+// FIXME: for strictfp/IEEE-754 we need to not trap on SNaN here.
 Value *LHS = EmitScalarExpr(E->getArg(0));
 Value *RHS = EmitScalarExpr(E->getArg(1));
 
@@ -2856,6 +2863,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 return RValue::get(Builder.CreateZExt(LHS, ConvertType(E->getType(;
   }
   case Builtin::BI__builtin_isnan: {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+// FIXME: for strictfp/IEEE-754 we need to not trap on SNaN here.
 Value *V = EmitScalarExpr(E->getArg(0));
 V = Builder.CreateFCmpUNO(V, V, "cmp");
 return RValue::get(Builder.CreateZExt(V, ConvertType(E->getType(;
@@ -2919,6 +2928,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 // isinf(x)--> fabs(x) == infinity
 // isfinite(x) --> fabs(x) != infinity
 // x != NaN via the ordered compare in either case.
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
+// FIXME: for strictfp/IEEE-754 we need to not trap on SNaN here.
 Value *V = EmitScalarExpr(E->getArg(0));
 Value *Fabs = EmitFAbs(*this, V);
 Constant *Infinity = ConstantFP::getInfinity(V->getType());
@@ -2931,6 +2942,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 
   case Builtin::BI__builtin_isinf_sign: {
 // isinf_sign(x) -> fabs(x) == infinity ? (sign

[clang] 81b6987 - [FPEnv][X86] Platform builtins edition: clang should get from the AST the metadata for constrained FP builtins

2021-02-03 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2021-02-03T11:49:17-05:00
New Revision: 81b69879c946533c71cc484bd8d9202bf1e34bfe

URL: 
https://github.com/llvm/llvm-project/commit/81b69879c946533c71cc484bd8d9202bf1e34bfe
DIFF: 
https://github.com/llvm/llvm-project/commit/81b69879c946533c71cc484bd8d9202bf1e34bfe.diff

LOG: [FPEnv][X86] Platform builtins edition: clang should get from the AST the 
metadata for constrained FP builtins

Currently clang is not correctly retrieving from the AST the metadata for
constrained FP builtins. This patch fixes that for the X86 specific builtins.

Differential Revision: https://reviews.llvm.org/D94614

Added: 
clang/test/CodeGen/X86/avx512dq-builtins-constrained.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/X86/avx-builtins-constrained-cmp.c
clang/test/CodeGen/X86/avx512f-builtins-constrained.c
clang/test/CodeGen/X86/fma-builtins-constrained.c
clang/test/CodeGen/X86/sse-builtins-constrained.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 973a20f2f58c..d8bb1bc84daa 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -11664,7 +11664,7 @@ static Value *EmitX86ConvertToMask(CodeGenFunction 
&CGF, Value *In) {
   return EmitX86MaskedCompare(CGF, 1, true, { In, Zero });
 }
 
-static Value *EmitX86ConvertIntToFp(CodeGenFunction &CGF,
+static Value *EmitX86ConvertIntToFp(CodeGenFunction &CGF, const CallExpr *E,
 ArrayRef Ops, bool IsSigned) {
   unsigned Rnd = cast(Ops[3])->getZExtValue();
   llvm::Type *Ty = Ops[1]->getType();
@@ -11676,6 +11676,7 @@ static Value *EmitX86ConvertIntToFp(CodeGenFunction 
&CGF,
 Function *F = CGF.CGM.getIntrinsic(IID, { Ty, Ops[0]->getType() });
 Res = CGF.Builder.CreateCall(F, { Ops[0], Ops[3] });
   } else {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Res = IsSigned ? CGF.Builder.CreateSIToFP(Ops[0], Ty)
: CGF.Builder.CreateUIToFP(Ops[0], Ty);
   }
@@ -11684,8 +11685,9 @@ static Value *EmitX86ConvertIntToFp(CodeGenFunction 
&CGF,
 }
 
 // Lowers X86 FMA intrinsics to IR.
-static Value *EmitX86FMAExpr(CodeGenFunction &CGF, ArrayRef Ops,
- unsigned BuiltinID, bool IsAddSub) {
+static Value *EmitX86FMAExpr(CodeGenFunction &CGF, const CallExpr *E,
+ ArrayRef Ops, unsigned BuiltinID,
+ bool IsAddSub) {
 
   bool Subtract = false;
   Intrinsic::ID IID = Intrinsic::not_intrinsic;
@@ -11742,6 +11744,7 @@ static Value *EmitX86FMAExpr(CodeGenFunction &CGF, 
ArrayRef Ops,
 llvm::Type *Ty = A->getType();
 Function *FMA;
 if (CGF.Builder.getIsFPConstrained()) {
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   FMA = CGF.CGM.getIntrinsic(Intrinsic::experimental_constrained_fma, Ty);
   Res = CGF.Builder.CreateConstrainedFPCall(FMA, {A, B, C});
 } else {
@@ -11783,10 +11786,10 @@ static Value *EmitX86FMAExpr(CodeGenFunction &CGF, 
ArrayRef Ops,
   return Res;
 }
 
-static Value *
-EmitScalarFMAExpr(CodeGenFunction &CGF, MutableArrayRef Ops,
-  Value *Upper, bool ZeroMask = false, unsigned PTIdx = 0,
-  bool NegAcc = false) {
+static Value *EmitScalarFMAExpr(CodeGenFunction &CGF, const CallExpr *E,
+MutableArrayRef Ops, Value *Upper,
+bool ZeroMask = false, unsigned PTIdx = 0,
+bool NegAcc = false) {
   unsigned Rnd = 4;
   if (Ops.size() > 4)
 Rnd = cast(Ops[4])->getZExtValue();
@@ -11805,6 +11808,7 @@ EmitScalarFMAExpr(CodeGenFunction &CGF, 
MutableArrayRef Ops,
 Res = CGF.Builder.CreateCall(CGF.CGM.getIntrinsic(IID),
  {Ops[0], Ops[1], Ops[2], Ops[4]});
   } else if (CGF.Builder.getIsFPConstrained()) {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *FMA = CGF.CGM.getIntrinsic(
 Intrinsic::experimental_constrained_fma, Ops[0]->getType());
 Res = CGF.Builder.CreateConstrainedFPCall(FMA, Ops.slice(0, 3));
@@ -12142,8 +12146,9 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   // TODO: The builtins could be removed if the SSE header files used vector
   // extension comparisons directly (vector ordered/unordered may need
   // additional support via __builtin_isnan()).
-  auto getVectorFCmpIR = [this, &Ops](CmpInst::Predicate Pred,
-  bool IsSignaling) {
+  auto getVectorFCmpIR = [this, &Ops, E](CmpInst::Predicate Pred,
+ bool IsSignaling) {
+CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E);
 Value *Cmp;
 if (IsSignaling)
   Cmp = Builder.CreateFCmpS(Pred, Ops[0], Ops[1]);
@@ -12385,31 +12390,31 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
Bui

[clang] 5eb1fbd - [clang][Docs] Correct typo: "may_trap" is rejected, the value is "maytrap".

2022-10-28 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2022-10-28T11:40:42-04:00
New Revision: 5eb1fbd109734771554465aa307e8205c2a2632e

URL: 
https://github.com/llvm/llvm-project/commit/5eb1fbd109734771554465aa307e8205c2a2632e
DIFF: 
https://github.com/llvm/llvm-project/commit/5eb1fbd109734771554465aa307e8205c2a2632e.diff

LOG: [clang][Docs] Correct typo: "may_trap" is rejected, the value is "maytrap".

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 8d825691721aa..11bc5c9066111 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1371,7 +1371,7 @@ describes the various floating point semantic modes and 
the corresponding option
   :header: "Mode", "Values"
   :widths: 15, 30, 30
 
-  "ffp-exception-behavior", "{ignore, strict, may_trap}",
+  "ffp-exception-behavior", "{ignore, strict, maytrap}",
   "fenv_access", "{off, on}", "(none)"
   "frounding-math", "{dynamic, tonearest, downward, upward, towardzero}"
   "ffp-contract", "{on, off, fast, fast-honor-pragmas}"



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


[clang] 91f886a - [FPEnv][TableGen] Add strictfp attribute to constrained intrinsics by default.

2023-07-12 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2023-07-12T09:55:53-04:00
New Revision: 91f886a40d3fbabfc539c2bd8977a1ccb45aa450

URL: 
https://github.com/llvm/llvm-project/commit/91f886a40d3fbabfc539c2bd8977a1ccb45aa450
DIFF: 
https://github.com/llvm/llvm-project/commit/91f886a40d3fbabfc539c2bd8977a1ccb45aa450.diff

LOG: [FPEnv][TableGen] Add strictfp attribute to constrained intrinsics by 
default.

In D146869 @arsenm pointed out that the constrained intrinsics aren't
getting the strictfp attribute by default. They should be since they are
required to have it anyway.

TableGen did not know about this attribute until now. This patch adds
strictfp to TableGen, and it uses it on all of the constrained intrinsics.

Differential Revision: https://reviews.llvm.org/D154991

Added: 
llvm/test/Assembler/fp-intrinsics-attr.ll

Modified: 
clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl
llvm/include/llvm/IR/Intrinsics.td
llvm/test/Verifier/fp-intrinsics-pass.ll
llvm/utils/TableGen/CodeGenIntrinsics.cpp
llvm/utils/TableGen/CodeGenIntrinsics.h
llvm/utils/TableGen/IntrinsicEmitter.cpp

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl 
b/clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl
index e7433787c89c88..605790164a7898 100644
--- a/clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl
+++ b/clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl
@@ -171,7 +171,7 @@ kernel void device_side_enqueue(global float *a, global 
float *b, int i) {
 // STRICTFP: attributes #[[ATTR0]] = { convergent noinline norecurse nounwind 
optnone strictfp "stack-protector-buffer-size"="8" 
"uniform-work-group-size"="false" }
 // STRICTFP: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nounwind 
willreturn memory(argmem: readwrite) }
 // STRICTFP: attributes #[[ATTR2]] = { convergent noinline nounwind optnone 
strictfp "stack-protector-buffer-size"="8" }
-// STRICTFP: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync 
nounwind willreturn memory(inaccessiblemem: readwrite) }
+// STRICTFP: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync 
nounwind strictfp willreturn memory(inaccessiblemem: readwrite) }
 // STRICTFP: attributes #[[ATTR4]] = { convergent nounwind 
"stack-protector-buffer-size"="8" }
 // STRICTFP: attributes #[[ATTR5]] = { strictfp }
 //.

diff  --git a/llvm/include/llvm/IR/Intrinsics.td 
b/llvm/include/llvm/IR/Intrinsics.td
index 0779d1fd958f60..638a9fda29b15c 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -1099,7 +1099,11 @@ def int_is_fpclass
 //===--- Constrained Floating Point Intrinsics 
===//
 //
 
-let IntrProperties = [IntrInaccessibleMemOnly, IntrWillReturn] in {
+/// IntrStrictFP - The intrinsic is allowed to be used in an alternate
+/// floating point environment.
+def IntrStrictFP : IntrinsicProperty;
+
+let IntrProperties = [IntrInaccessibleMemOnly, IntrWillReturn, IntrStrictFP] 
in {
   def int_experimental_constrained_fadd : DefaultAttrsIntrinsic<[ 
llvm_anyfloat_ty ],
 [ LLVMMatchType<0>,
   LLVMMatchType<0>,

diff  --git a/llvm/test/Assembler/fp-intrinsics-attr.ll 
b/llvm/test/Assembler/fp-intrinsics-attr.ll
new file mode 100644
index 00..6546d1a275c99f
--- /dev/null
+++ b/llvm/test/Assembler/fp-intrinsics-attr.ll
@@ -0,0 +1,318 @@
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s
+
+; Test to verify that constrained intrinsics all have the strictfp attribute.
+; Ordering is from Intrinsics.td.
+
+define void @func(double %a, double %b, double %c, i32 %i) strictfp {
+; CHECK-LABEL: define void @func
+; CHECK-SAME: (double [[A:%.*]], double [[B:%.*]], double [[C:%.*]], i32 
[[I:%.*]]) #[[ATTR0:[0-9]+]] {
+
+  %add = call double @llvm.experimental.constrained.fadd.f64(
+   double %a, double %b,
+   metadata !"round.dynamic",
+   metadata !"fpexcept.strict")
+
+  %sub = call double @llvm.experimental.constrained.fsub.f64(
+   double %a, double %b,
+   metadata !"round.dynamic",
+   metadata !"fpexcept.strict")
+
+  %mul = call double @llvm.experimental.constrained.fmul.f64(
+   double %a, double %b,
+   metadata !"round.dynamic",
+   metadata !"fpexcept.strict")
+
+  %div = call double @llvm.experimental.constrained.fdiv.f64(
+   double %a, double %b,
+   

[clang] 6515c52 - [FPEnv] clang support for constrained FP builtins

2019-12-10 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2019-12-10T13:09:12-05:00
New Revision: 6515c524b0ae50dd5bb052558afa8c81d3a75780

URL: 
https://github.com/llvm/llvm-project/commit/6515c524b0ae50dd5bb052558afa8c81d3a75780
DIFF: 
https://github.com/llvm/llvm-project/commit/6515c524b0ae50dd5bb052558afa8c81d3a75780.diff

LOG: [FPEnv] clang support for constrained FP builtins

Change the IRBuilder and clang so that constrained FP intrinsics will be
emitted for builtins when appropriate. Only non-target-specific builtins
are affected in this patch.

Differential Revision: https://reviews.llvm.org/D70256

Added: 
clang/test/CodeGen/constrained-math-builtins.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
llvm/include/llvm/IR/IRBuilder.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2b2738252a05..68c956a98637 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -348,6 +348,58 @@ static Value *EmitISOVolatileStore(CodeGenFunction &CGF, 
const CallExpr *E) {
   return Store;
 }
 
+// Emit a simple mangled intrinsic that has 1 argument and a return type
+// matching the argument type. Depending on mode, this may be a constrained
+// floating-point intrinsic.
+static Value *emitUnaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
+const CallExpr *E, unsigned IntrinsicID,
+unsigned ConstrainedIntrinsicID) {
+  llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
+
+  if (CGF.Builder.getIsFPConstrained()) {
+Value *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, Src0->getType());
+return CGF.Builder.CreateConstrainedFPCall(F, { Src0 });
+  } else {
+Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
+return CGF.Builder.CreateCall(F, Src0);
+  }
+}
+  
+// Emit an intrinsic that has 2 operands of the same type as its result.
+// Depending on mode, this may be a constrained floating-point intrinsic.
+static Value *emitBinaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
+const CallExpr *E, unsigned IntrinsicID,
+unsigned ConstrainedIntrinsicID) {
+  llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
+  llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
+
+  if (CGF.Builder.getIsFPConstrained()) {
+Value *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, Src0->getType());
+return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1 });
+  } else {
+Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
+return CGF.Builder.CreateCall(F, { Src0, Src1 });
+  }
+}
+
+// Emit an intrinsic that has 3 operands of the same type as its result.
+// Depending on mode, this may be a constrained floating-point intrinsic.
+static Value *emitTernaryMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
+ const CallExpr *E, unsigned IntrinsicID,
+ unsigned ConstrainedIntrinsicID) {
+  llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
+  llvm::Value *Src1 = CGF.EmitScalarExpr(E->getArg(1));
+  llvm::Value *Src2 = CGF.EmitScalarExpr(E->getArg(2));
+
+  if (CGF.Builder.getIsFPConstrained()) {
+Value *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, Src0->getType());
+return CGF.Builder.CreateConstrainedFPCall(F, { Src0, Src1, Src2 });
+  } else {
+Value *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
+return CGF.Builder.CreateCall(F, { Src0, Src1, Src2 });
+  }
+}
+
 // Emit a simple mangled intrinsic that has 1 argument and a return type
 // matching the argument type.
 static Value *emitUnaryBuiltin(CodeGenFunction &CGF,
@@ -394,15 +446,22 @@ static Value *emitFPIntBuiltin(CodeGenFunction &CGF,
 }
 
 // Emit an intrinsic that has overloaded integer result and fp operand.
-static Value *emitFPToIntRoundBuiltin(CodeGenFunction &CGF,
-  const CallExpr *E,
-  unsigned IntrinsicID) {
-   llvm::Type *ResultType = CGF.ConvertType(E->getType());
-   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
+static Value *
+emitMaybeConstrainedFPToIntRoundBuiltin(CodeGenFunction &CGF, const CallExpr 
*E,
+unsigned IntrinsicID,
+unsigned ConstrainedIntrinsicID) {
+  llvm::Type *ResultType = CGF.ConvertType(E->getType());
+  llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
 
-   Function *F = CGF.CGM.getIntrinsic(IntrinsicID,
-  {ResultType, Src0->getType()});
-   return CGF.Builder.CreateCall(F, Src0);
+  if (CGF.Builder.getIsFPConstrained()) {
+Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID,
+   {ResultType, Src0->getType()});
+return CGF.Builder.CreateConstrainedFPCall(F, {Src0});

[clang] 0293b5d - [NFC] Remove some dead code from CGBuiltin.cpp.

2019-12-24 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2019-12-24T09:38:34-05:00
New Revision: 0293b5d67123786daf80528af9ef356b7bd9d2f6

URL: 
https://github.com/llvm/llvm-project/commit/0293b5d67123786daf80528af9ef356b7bd9d2f6
DIFF: 
https://github.com/llvm/llvm-project/commit/0293b5d67123786daf80528af9ef356b7bd9d2f6.diff

LOG: [NFC] Remove some dead code from CGBuiltin.cpp.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3b35fc23a1b9..17b8cab71294 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2297,20 +2297,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   case Builtin::BI__builtin_powil:
 return RValue::get(emitBinaryMaybeConstrainedFPBuiltin(
 *this, E, Intrinsic::powi, Intrinsic::experimental_constrained_powi));
-#if 0
-Value *Base = EmitScalarExpr(E->getArg(0));
-Value *Exponent = EmitScalarExpr(E->getArg(1));
-llvm::Type *ArgType = Base->getType();
-// XXX Maybe
-if (Builder.getIsFPConstrained()) {
-  Function *F = CGM.getIntrinsic(Intrinsic::experimental_constrained_powi, 
ArgType);
-  return RValue::get(Builder.CreateConstrainedFPCall(F, {Base, Exponent}));
-}
-else {
-  Function *F = CGM.getIntrinsic(Intrinsic::powi, ArgType);
-  return RValue::get(Builder.CreateCall(F, {Base, Exponent}));
-}
-#endif
 
   case Builtin::BI__builtin_isgreater:
   case Builtin::BI__builtin_isgreaterequal:



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


[clang] 208470d - [FPEnv][X86] Platform-specific builtin constrained FP enablement

2020-02-06 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-02-06T14:20:44-05:00
New Revision: 208470dd5d0a46bc3c24b66489b687eda4954262

URL: 
https://github.com/llvm/llvm-project/commit/208470dd5d0a46bc3c24b66489b687eda4954262
DIFF: 
https://github.com/llvm/llvm-project/commit/208470dd5d0a46bc3c24b66489b687eda4954262.diff

LOG: [FPEnv][X86] Platform-specific builtin constrained FP enablement

When constrained floating point is enabled the X86-specific builtins don't
use constrained intrinsics in some cases. Fix that.

Differential Revision: https://reviews.llvm.org/D73570

Added: 
clang/test/CodeGen/avx512f-builtins-constrained.c
clang/test/CodeGen/fma-builtins-constrained.c
clang/test/CodeGen/sse-builtins-constrained.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 44947b4b1d64..ca41413ae278 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10094,8 +10094,14 @@ static Value *EmitX86FMAExpr(CodeGenFunction &CGF, 
ArrayRef Ops,
 Res = CGF.Builder.CreateCall(Intr, {A, B, C, Ops.back() });
   } else {
 llvm::Type *Ty = A->getType();
-Function *FMA = CGF.CGM.getIntrinsic(Intrinsic::fma, Ty);
-Res = CGF.Builder.CreateCall(FMA, {A, B, C} );
+Function *FMA;
+if (CGF.Builder.getIsFPConstrained()) {
+  FMA = CGF.CGM.getIntrinsic(Intrinsic::experimental_constrained_fma, Ty);
+  Res = CGF.Builder.CreateConstrainedFPCall(FMA, {A, B, C});
+} else {
+  FMA = CGF.CGM.getIntrinsic(Intrinsic::fma, Ty);
+  Res = CGF.Builder.CreateCall(FMA, {A, B, C});
+}
 
 if (IsAddSub) {
   // Negate even elts in C using a mask.
@@ -10105,7 +10111,11 @@ static Value *EmitX86FMAExpr(CodeGenFunction &CGF, 
ArrayRef Ops,
 Indices[i] = i + (i % 2) * NumElts;
 
   Value *NegC = CGF.Builder.CreateFNeg(C);
-  Value *FMSub = CGF.Builder.CreateCall(FMA, {A, B, NegC} );
+  Value *FMSub;
+  if (CGF.Builder.getIsFPConstrained())
+FMSub = CGF.Builder.CreateConstrainedFPCall(FMA, {A, B, NegC} );
+  else
+FMSub = CGF.Builder.CreateCall(FMA, {A, B, NegC} );
   Res = CGF.Builder.CreateShuffleVector(FMSub, Res, Indices);
 }
   }
@@ -10164,6 +10174,10 @@ EmitScalarFMAExpr(CodeGenFunction &CGF, 
MutableArrayRef Ops,
 Intrinsic::x86_avx512_vfmadd_f64;
 Res = CGF.Builder.CreateCall(CGF.CGM.getIntrinsic(IID),
  {Ops[0], Ops[1], Ops[2], Ops[4]});
+  } else if (CGF.Builder.getIsFPConstrained()) {
+Function *FMA = CGF.CGM.getIntrinsic(
+Intrinsic::experimental_constrained_fma, Ops[0]->getType());
+Res = CGF.Builder.CreateConstrainedFPCall(FMA, Ops.slice(0, 3));
   } else {
 Function *FMA = CGF.CGM.getIntrinsic(Intrinsic::fma, Ops[0]->getType());
 Res = CGF.Builder.CreateCall(FMA, Ops.slice(0, 3));
@@ -11892,8 +11906,15 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_sqrtss:
   case X86::BI__builtin_ia32_sqrtsd: {
 Value *A = Builder.CreateExtractElement(Ops[0], (uint64_t)0);
-Function *F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
-A = Builder.CreateCall(F, {A});
+Function *F;
+if (Builder.getIsFPConstrained()) {
+  F = CGM.getIntrinsic(Intrinsic::experimental_constrained_sqrt,
+   A->getType());
+  A = Builder.CreateConstrainedFPCall(F, {A});
+} else {
+  F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
+  A = Builder.CreateCall(F, {A});
+}
 return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
   }
   case X86::BI__builtin_ia32_sqrtsd_round_mask:
@@ -11908,8 +11929,15 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   return Builder.CreateCall(CGM.getIntrinsic(IID), Ops);
 }
 Value *A = Builder.CreateExtractElement(Ops[1], (uint64_t)0);
-Function *F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
-A = Builder.CreateCall(F, A);
+Function *F;
+if (Builder.getIsFPConstrained()) {
+  F = CGM.getIntrinsic(Intrinsic::experimental_constrained_sqrt,
+   A->getType());
+  A = Builder.CreateConstrainedFPCall(F, A);
+} else {
+  F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
+  A = Builder.CreateCall(F, A);
+}
 Value *Src = Builder.CreateExtractElement(Ops[2], (uint64_t)0);
 A = EmitX86ScalarSelect(*this, Ops[3], A, Src);
 return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
@@ -11931,8 +11959,14 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
 return Builder.CreateCall(CGM.getIntrinsic(IID), Ops);
   }
 }
-Function *F = CGM.getIntrinsic(Intrinsic::sqrt, Ops[0]->getType());
-return Builder.CreateCall(F, Ops[0]);
+if (Builder.getIsFPConstrained()) {
+  Function *F = CGM.get

[clang] 80e17e5 - [FPEnv][X86] Speculative fix for failures introduced by eda495426.

2020-02-06 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-02-06T15:28:36-05:00
New Revision: 80e17e5fcc09dc5baa940022e6988fcb08c5d92d

URL: 
https://github.com/llvm/llvm-project/commit/80e17e5fcc09dc5baa940022e6988fcb08c5d92d
DIFF: 
https://github.com/llvm/llvm-project/commit/80e17e5fcc09dc5baa940022e6988fcb08c5d92d.diff

LOG: [FPEnv][X86] Speculative fix for failures introduced by eda495426.

Differential Revision: https://reviews.llvm.org/D73570

Added: 


Modified: 
clang/test/CodeGen/avx512f-builtins-constrained.c
clang/test/CodeGen/fma-builtins-constrained.c
clang/test/CodeGen/sse-builtins-constrained.c

Removed: 




diff  --git a/clang/test/CodeGen/avx512f-builtins-constrained.c 
b/clang/test/CodeGen/avx512f-builtins-constrained.c
index 1a8df1a85c7c..75fad73d60f6 100644
--- a/clang/test/CodeGen/avx512f-builtins-constrained.c
+++ b/clang/test/CodeGen/avx512f-builtins-constrained.c
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +avx512f -emit-llvm -o - -Wall -Werror | FileCheck 
--check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
+// RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-unknown-linux-gnu -target-feature +avx512f -emit-llvm -o - -Wall 
-Werror | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=UNCONSTRAINED %s
 // RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding 
%s -triple=x86_64-windows-msvc -target-feature +avx512f -emit-llvm -o - -Wall 
-Werror | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=UNCONSTRAINED %s
-// RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +avx512f -ffp-exception-behavior=strict -emit-llvm -o - -Wall 
-Werror | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=CONSTRAINED %s
-// RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -fms-compatibility -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f 
-ffp-exception-behavior=strict -emit-llvm -o - -Wall -Werror | FileCheck 
--check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
-// RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +avx512f -S -o - -Wall -Werror | FileCheck 
--check-prefix=COMMON --check-prefix=CHECK-ASM %s
-// RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +avx512f -ffp-exception-behavior=strict -S -o - -Wall -Werror | 
FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-unknown-linux-gnu -target-feature +avx512f 
-ffp-exception-behavior=strict -emit-llvm -o - -Wall -Werror | FileCheck 
--check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
+// RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -fms-compatibility -ffreestanding %s 
-triple=x86_64-unknown-linux-gnu -target-feature +avx512f 
-ffp-exception-behavior=strict -emit-llvm -o - -Wall -Werror | FileCheck 
--check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
+// RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-unknown-linux-gnu -target-feature +avx512f -S -o - -Wall -Werror 
| FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: %clang_cc1 -fexperimental-new-pass-manager 
-flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-unknown-linux-gnu -target-feature +avx512f 
-ffp-exception-behavior=strict -S -o - -Wall -Werror | FileCheck 
--check-prefix=COMMON --check-prefix=CHECK-ASM %s
 
 #include 
 

diff  --git a/clang/test/CodeGen/fma-builtins-constrained.c 
b/clang/test/CodeGen/fma-builtins-constrained.c
index 91e2d25c4d46..8a3ce821a568 100644
--- a/clang/test/CodeGen/fma-builtins-constrained.c
+++ b/clang/test/CodeGen/fma-builtins-constrained.c
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +fma -O -emit-llvm -o - | FileCheck --check-prefix=COMMON 
--check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +fma -ffp-exception-behavior=strict -O -emit-llvm -o - | 
FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=CONSTRAINED %s
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +fma -O -S -o - | FileCheck --check-pr

[clang] ad0e03f - Revert "[FPEnv][X86] Platform-specific builtin constrained FP enablement"

2020-02-06 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-02-06T19:17:14-05:00
New Revision: ad0e03fd4c8066843f4138e44661ee0287ceb631

URL: 
https://github.com/llvm/llvm-project/commit/ad0e03fd4c8066843f4138e44661ee0287ceb631
DIFF: 
https://github.com/llvm/llvm-project/commit/ad0e03fd4c8066843f4138e44661ee0287ceb631.diff

LOG: Revert "[FPEnv][X86] Platform-specific builtin constrained FP enablement"

This reverts commit 208470dd5d0a46bc3c24b66489b687eda4954262.

Tests fail:
error: unable to create target: 'No available targets are compatible with 
triple "x86_64-apple-darwin"'

This happens on clang-hexagon-elf, clang-cmake-armv7-quick, and
clang-cmake-armv7-quick bots.

If anyone has any suggestions on why then I'm all ears.

Differential Revision: https://reviews.llvm.org/D73570

Revert "[FPEnv][X86] Speculative fix for failures introduced by eda495426."

This reverts commit 80e17e5fcc09dc5baa940022e6988fcb08c5d92d.

The speculative fix didn't solve the test failures on Hexagon, ARMv6, and
MSVC AArch64.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 
clang/test/CodeGen/avx512f-builtins-constrained.c
clang/test/CodeGen/fma-builtins-constrained.c
clang/test/CodeGen/sse-builtins-constrained.c



diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ca41413ae278..44947b4b1d64 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10094,14 +10094,8 @@ static Value *EmitX86FMAExpr(CodeGenFunction &CGF, 
ArrayRef Ops,
 Res = CGF.Builder.CreateCall(Intr, {A, B, C, Ops.back() });
   } else {
 llvm::Type *Ty = A->getType();
-Function *FMA;
-if (CGF.Builder.getIsFPConstrained()) {
-  FMA = CGF.CGM.getIntrinsic(Intrinsic::experimental_constrained_fma, Ty);
-  Res = CGF.Builder.CreateConstrainedFPCall(FMA, {A, B, C});
-} else {
-  FMA = CGF.CGM.getIntrinsic(Intrinsic::fma, Ty);
-  Res = CGF.Builder.CreateCall(FMA, {A, B, C});
-}
+Function *FMA = CGF.CGM.getIntrinsic(Intrinsic::fma, Ty);
+Res = CGF.Builder.CreateCall(FMA, {A, B, C} );
 
 if (IsAddSub) {
   // Negate even elts in C using a mask.
@@ -10111,11 +10105,7 @@ static Value *EmitX86FMAExpr(CodeGenFunction &CGF, 
ArrayRef Ops,
 Indices[i] = i + (i % 2) * NumElts;
 
   Value *NegC = CGF.Builder.CreateFNeg(C);
-  Value *FMSub;
-  if (CGF.Builder.getIsFPConstrained())
-FMSub = CGF.Builder.CreateConstrainedFPCall(FMA, {A, B, NegC} );
-  else
-FMSub = CGF.Builder.CreateCall(FMA, {A, B, NegC} );
+  Value *FMSub = CGF.Builder.CreateCall(FMA, {A, B, NegC} );
   Res = CGF.Builder.CreateShuffleVector(FMSub, Res, Indices);
 }
   }
@@ -10174,10 +10164,6 @@ EmitScalarFMAExpr(CodeGenFunction &CGF, 
MutableArrayRef Ops,
 Intrinsic::x86_avx512_vfmadd_f64;
 Res = CGF.Builder.CreateCall(CGF.CGM.getIntrinsic(IID),
  {Ops[0], Ops[1], Ops[2], Ops[4]});
-  } else if (CGF.Builder.getIsFPConstrained()) {
-Function *FMA = CGF.CGM.getIntrinsic(
-Intrinsic::experimental_constrained_fma, Ops[0]->getType());
-Res = CGF.Builder.CreateConstrainedFPCall(FMA, Ops.slice(0, 3));
   } else {
 Function *FMA = CGF.CGM.getIntrinsic(Intrinsic::fma, Ops[0]->getType());
 Res = CGF.Builder.CreateCall(FMA, Ops.slice(0, 3));
@@ -11906,15 +11892,8 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_sqrtss:
   case X86::BI__builtin_ia32_sqrtsd: {
 Value *A = Builder.CreateExtractElement(Ops[0], (uint64_t)0);
-Function *F;
-if (Builder.getIsFPConstrained()) {
-  F = CGM.getIntrinsic(Intrinsic::experimental_constrained_sqrt,
-   A->getType());
-  A = Builder.CreateConstrainedFPCall(F, {A});
-} else {
-  F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
-  A = Builder.CreateCall(F, {A});
-}
+Function *F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
+A = Builder.CreateCall(F, {A});
 return Builder.CreateInsertElement(Ops[0], A, (uint64_t)0);
   }
   case X86::BI__builtin_ia32_sqrtsd_round_mask:
@@ -11929,15 +11908,8 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   return Builder.CreateCall(CGM.getIntrinsic(IID), Ops);
 }
 Value *A = Builder.CreateExtractElement(Ops[1], (uint64_t)0);
-Function *F;
-if (Builder.getIsFPConstrained()) {
-  F = CGM.getIntrinsic(Intrinsic::experimental_constrained_sqrt,
-   A->getType());
-  A = Builder.CreateConstrainedFPCall(F, A);
-} else {
-  F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
-  A = Builder.CreateCall(F, A);
-}
+Function *F = CGM.getIntrinsic(Intrinsic::sqrt, A->getType());
+A = Builder.CreateCall(F, A);
 Value *Src = Builder.CreateExtractElement(Ops[2], (uint64_t)0);
 A = EmitX86ScalarSelect(

[clang] 2e667d0 - [FPEnv][SystemZ] Platform-specific builtin constrained FP enablement

2020-01-21 Thread Kevin P. Neal via cfe-commits

Author: Kevin P. Neal
Date: 2020-01-21T12:44:39-05:00
New Revision: 2e667d07c773f684ea893b9ce5d9b73e9f23b438

URL: 
https://github.com/llvm/llvm-project/commit/2e667d07c773f684ea893b9ce5d9b73e9f23b438
DIFF: 
https://github.com/llvm/llvm-project/commit/2e667d07c773f684ea893b9ce5d9b73e9f23b438.diff

LOG: [FPEnv][SystemZ] Platform-specific builtin constrained FP enablement

When constrained floating point is enabled the SystemZ-specific builtins
don't use constrained intrinsics in some cases. Fix that.

Differential Revision: https://reviews.llvm.org/D72722

Added: 
clang/test/CodeGen/builtins-systemz-vector-constrained.c
clang/test/CodeGen/builtins-systemz-vector2-constrained.c
clang/test/CodeGen/builtins-systemz-zvector-constrained.c
clang/test/CodeGen/builtins-systemz-zvector2-constrained.c
clang/test/CodeGen/builtins-systemz-zvector3-constrained.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 8d00d3d64f5c..29eebbb403ea 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -13310,8 +13310,13 @@ Value 
*CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
   case SystemZ::BI__builtin_s390_vfsqdb: {
 llvm::Type *ResultType = ConvertType(E->getType());
 Value *X = EmitScalarExpr(E->getArg(0));
-Function *F = CGM.getIntrinsic(Intrinsic::sqrt, ResultType);
-return Builder.CreateCall(F, X);
+if (Builder.getIsFPConstrained()) {
+  Function *F = CGM.getIntrinsic(Intrinsic::experimental_constrained_sqrt, 
ResultType);
+  return Builder.CreateConstrainedFPCall(F, { X });
+} else {
+  Function *F = CGM.getIntrinsic(Intrinsic::sqrt, ResultType);
+  return Builder.CreateCall(F, X);
+}
   }
   case SystemZ::BI__builtin_s390_vfmasb:
   case SystemZ::BI__builtin_s390_vfmadb: {
@@ -13319,8 +13324,13 @@ Value 
*CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
-return Builder.CreateCall(F, {X, Y, Z});
+if (Builder.getIsFPConstrained()) {
+  Function *F = CGM.getIntrinsic(Intrinsic::experimental_constrained_fma, 
ResultType);
+  return Builder.CreateConstrainedFPCall(F, {X, Y, Z});
+} else {
+  Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
+  return Builder.CreateCall(F, {X, Y, Z});
+}
   }
   case SystemZ::BI__builtin_s390_vfmssb:
   case SystemZ::BI__builtin_s390_vfmsdb: {
@@ -13328,8 +13338,13 @@ Value 
*CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
-return Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")});
+if (Builder.getIsFPConstrained()) {
+  Function *F = CGM.getIntrinsic(Intrinsic::experimental_constrained_fma, 
ResultType);
+  return Builder.CreateConstrainedFPCall(F, {X, Y, Builder.CreateFNeg(Z, 
"neg")});
+} else {
+  Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
+  return Builder.CreateCall(F, {X, Y, Builder.CreateFNeg(Z, "neg")});
+}
   }
   case SystemZ::BI__builtin_s390_vfnmasb:
   case SystemZ::BI__builtin_s390_vfnmadb: {
@@ -13337,8 +13352,13 @@ Value 
*CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
-return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, Z}), "neg");
+if (Builder.getIsFPConstrained()) {
+  Function *F = CGM.getIntrinsic(Intrinsic::experimental_constrained_fma, 
ResultType);
+  return Builder.CreateFNeg(Builder.CreateConstrainedFPCall(F, {X, Y,  
Z}), "neg");
+} else {
+  Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
+  return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, Z}), "neg");
+}
   }
   case SystemZ::BI__builtin_s390_vfnmssb:
   case SystemZ::BI__builtin_s390_vfnmsdb: {
@@ -13346,9 +13366,15 @@ Value 
*CodeGenFunction::EmitSystemZBuiltinExpr(unsigned BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *Z = EmitScalarExpr(E->getArg(2));
-Function *F = CGM.getIntrinsic(Intrinsic::fma, ResultType);
-Value *NegZ = Builder.CreateFNeg(Z, "neg");
-return Builder.CreateFNeg(Builder.CreateCall(F, {X, Y, NegZ}));
+if (Builder.getIsFPConstrained()) {
+  Function *F = CGM.getIntrinsic(Intrinsic::experimental_constrained_fma, 
ResultType);
+  Va

[clang] [Driver] Introduce ffp-model=aggressive (PR #100453)

2024-08-12 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

Since you asked about "=strict", I don't think the strict model should change 
handling of excess precision. The rounding part of the constrained intrinsics 
shouldn't have any effect at all on excess precision. Eliminating excess 
precision also shouldn't happen with exception handling that isn't "default" 
since that would introduce exceptions (inexact, probably) that wouldn't be 
there normally since the excess precision is, I understand, allowed by the 
standard. Using the constrained intrinsics to indicate accessing the FP 
environment, but otherwise in the default FP environment, shouldn't have 
anything to do with excess precision.

Working backwards, having the "=strict" mode disable excess precision despite 
this not being a good idea with the constrained intrinsics would be surprising.

I also don't see how use of the constrained intrinsics indicates the program 
wants to be less accurate.

>From the POV of a programming language, it seems to me that the programmer 
>shouldn't have to choose between accessing the FP environment or having excess 
>precision that's allowed by the language.

>From the POV of clang command line arguments, the "=strict" mode is a 
>combination of flags that disables some optimizations (like code movement) and 
>generally makes the code more predictable. I don't think it follows that it 
>should also, as a goal, reduce accuracy.

https://github.com/llvm/llvm-project/pull/100453
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-10-04 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

> It does not look as a good base for safety. Many users want the code in 
> non-default FP modes to be more efficient, Now any any deviation from the 
> default mode requires use of constrained intrinsics in the entire function, 
> but now such solution exhibits poor performance, unsuitable for practical 
> needs. Eventually optimizations will involve the constrained intrinsics too.

This sounds like a rejection of safe-by-default. Keep in mind that "unsuitable 
for practical needs" doesn't mean that everyone agrees with you about what 
level of performance is unsuitable for one's practical needs. And a compiler 
that generates good performing code with random FP exceptions inserted is, in 
my experience, unusable if one runs with traps on. Trading performance for 
exception safety is a valid choice for some. Trading away all of the 
performance lost because few optimization passes know how to deal with the 
constrained intrinsics is still a valid choice for some.

WRT eliminating the constrained intrinsics completely, I thought that operand 
bundles could only be attached to function calls and not regular instructions? 
If I'm wrong, we _still_ have a problem because there are so many uses of the 
regular FP instructions that we can't be safe-by-default and still use those 
instructions. We'd need to keep some kind of the constrained intrinsics (or new 
intrinsics) that give us replacements for the regular FP instructions.

I do like the idea of finding ways to get the behavior we need without having 
to have most developers care about strictfp. Reality is that most LLVM 
developers don't have any interest in strictfp. If we're piggybacking off of 
other parts of the LLVM design that are already widely supported then that 
makes our jobs much easier. If we can rely on marking calls as 
"inaccessiblememonly" or other side effects then that sounds quite helpful.

The problem I've run into with the IR Verifier is that the strictfp mode of the 
IR Builder needs to be turned on in all cases needed, but currently doesn't 
because the IR Builder's constructor doesn't know to construct itself in 
strictfp mode. Now, many instantiations of the IR Builder occur with the 
constructor able to chase down the function definition and find out if strictfp 
mode is required. Many, hundreds, don't have that luxury and thus each has to 
be touched and corrected.

Having the IR Builder keep this strictfp mode and automatically add side-effect 
notes and/or operand bundles when required allows most developers to continue 
to not care about strictfp but preserve strictfp functionality at the same 
time. We'd still need a way to find out that some cases were missed because, 
for example, a strictfp attribute was forgotten. So the IR Builder 
instantiations still need to be corrected, but that's work in progress. 
Eventually the IR Builder could be changed to add bundles to, I don't know, all 
function calls that have a FP type passed to them perhaps?

No IR Builder changes are needed for this patch, of course, but I do want us to 
make sure we're keeping the whole design in mind as we go.

https://github.com/llvm/llvm-project/pull/109798
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-10-31 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

> > I do have a ticket open to change the IRBuilder to check the function 
> > definition and set the strictfp mode automatically. But I pooched the 
> > branch on my end so I'll need to open a new ticket, hopefully this year. 
> > That still leaves hundreds of cases that need to be manually corrected.
> 
> The attribute `strictfp` requires refinement, which is outside of the 
> proposed changes and needs to be discussed separately. In particular a 
> function that changes FP environmet, but then restores it should not require 
> `strictfp` environment. It means `strictfp` should not be assigned 
> automatically.

Without the strictfp attribute the inliner will be allowed to inline that 
function that changes the FP environment into a function that is non-strictfp. 
Since we don't have FP barriers we'll then have optimizations moving 
instructions into and out of the inlined body. This can result in incorrect 
trap behavior, incorrect rounding happening, whatever, depending on how the FP 
environment is modified. So the strictfp attribute is required, period. What we 
need to do is reword the description in the LangRef to make this more clear.

https://github.com/llvm/llvm-project/pull/109798
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-10-23 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

> > WRT eliminating the constrained intrinsics completely, I thought that 
> > operand bundles could only be attached to function calls and not regular 
> > instructions? If I'm wrong, we _still_ have a problem because there are so 
> > many uses of the regular FP instructions that we can't be safe-by-default 
> > and still use those instructions. We'd need to keep some kind of the 
> > constrained intrinsics (or new intrinsics) that give us replacements for 
> > the regular FP instructions.
> 
> Right, we would need to introduce new llvm.fadd etc. to carry bundles. If 
> there are no bundles these could fold back to the regular instruction

Good. The new intrinsics will be unknown to the optimization passes and thus be 
"safe by default". 

The target-specific intrinsics with bundles will be "unsafe by default", but 
that's a step up from the current just plain unsafe.

We will need someone to go through and audit the libm-style intrinsics and make 
sure all optimizations of them are safe before we can switch over. Those are 
"unsafe by default" since the optimizers know about them already.

Folding back to regular instructions will be fairly limited I expect until 
perhaps very late in the target-specific pipeline. Otherwise we run into the 
instruction reordering issue. The outliner can probably sometimes extract the 
non-strictfp parts of a function and mark the new outlined function as not 
being strictfp which would then enable folding back to instructions.

Do we know how we're going to get bundles through the SelectionDAG?

https://github.com/llvm/llvm-project/pull/109798
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-10-23 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

> > This sounds like a rejection of safe-by-default.
> 
> What do you mean by "safe-by-default"? Implementation must be correct, and 
> produce the code that executes in accordance to standards and documentation. 
> Any deviation from them is an error and should be fixed. Does it mean that 
> such implementation would be "safe"?

When I say "safe-by-default" I'm referring to the case where the optimizers 
don't know about the intrinsics so the optimizers get very conservative and 
don't optimize. 

It is assumed that all optimizations that actually are done will be in 
accordance with standards and documentation. 

> > Keep in mind that "unsuitable for practical needs" doesn't mean that 
> > everyone agrees with you about what level of performance is unsuitable for 
> > one's practical needs. And a compiler that generates good performing code 
> > with random FP exceptions inserted is, in my experience, unusable if one 
> > runs with traps on.
> 
> Users have different needs and can tune compilation using appropriate 
> options. Those who need strict exception behavior chose suitable option set 
> and should get code that behave as expected but probably has lower 
> performance. And there is a large number of users who need maximum 
> performance but can sacrifice exception strictness. They should use another 
> set of options. Does using different compilation options solves this problem?

Aren't you describing the current state of clang/llvm? Users have different 
compiler options to choose between FP trap safe and trap-unsafe. Compiled code 
that is FP trap safe has lower performance. 

The sticky point is the rounding mode. Running with a different rounding mode 
ideally wouldn't affect performance much at all, but it currently does. But 
fixing that requires fixing all the optimization passes. 

> > Trading performance for exception safety is a valid choice for some. 
> > Trading away all of the performance lost because few optimization passes 
> > know how to deal with the constrained intrinsics is still a valid choice 
> > for some.
> 
> There is no hope to produce code as performant as in default mode, but with 
> strict exception semantics. So the only way to make a compiler suitable for 
> all users is to provide means to tune it.

Is there a disagreement here? I don't see it. It's true that after we finish 
teaching all the passes about strictfp (constrained or bundles) we still won't 
have code that is as optimized if strict exception semantics are selected. This 
is inevitable since, for example, we can't hoist an FP instruction out of a 
loop unless we can prove it never traps when traps matter.

> > WRT eliminating the constrained intrinsics completely, I thought that 
> > operand bundles could only be attached to function calls and not regular 
> > instructions? If I'm wrong, we still have a problem because there are so 
> > many uses of the regular FP instructions that we can't be safe-by-default 
> > and still use those instructions. We'd need to keep some kind of the 
> > constrained intrinsics (or new intrinsics) that give us replacements for 
> > the regular FP instructions.
> 
> There is no intention to remove constrained intrinsics (like 
> `experimental.constrained.fadd`), because operand bundles could only be 
> attached to function calls. The constrained intrinsics however need to change 
> their shape in future to use operand bundles as well.

Agreed, we'll need to keep some kind of intrinsics to replace the FP 
instructions. Since we're going to be replacing the metadata with bundles it 
might make sense to switch the names of the intrinsics while we're at it. That 
would also allow for parallel implementations during a switchover.

Changing to use bundles will be more flexible and can include things like the 
denormal mode. More flexibility sounds like a good change. It's a shame we'll 
lose "safe-by-default" for libm-style intrinsics, but I don't have an 
alternative.
 
> > The problem I've run into with the IR Verifier is that the strictfp mode of 
> > the IR Builder needs to be turned on in all cases needed, but currently 
> > doesn't because the IR Builder's constructor doesn't know to construct 
> > itself in strictfp mode. Now, many instantiations of the IR Builder occur 
> > with the constructor able to chase down the function definition and find 
> > out if strictfp mode is required. Many, hundreds, don't have that luxury 
> > and thus each has to be touched and corrected.
> 
> If IRBuilder does not set strictfp when it should, it usually ends up with 
> assertion violation or verification errors. I guess in this case IR is 
> created by some tool, probably MLIR-based, not by clang? Maybe this is a use 
> case that we do not support enough well now and it would be helpful to 
> investigate it.

No, there are hundreds of instantiations of the IRBuilder strewn all throughout 
llvm that don't properly set the strictfp mode when they should. Optimization 
pas

[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-09-25 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

> > If we can't keep the constrained semantics and near-100% guarantee that no 
> > new exceptions will be introduced then operand bundles are not a 
> > replacement for the constrained intrinsics.
> 
> We would still need a call / function attribute to indicate strictfp calls, 
> and such calls would then be annotatable with bundles to relax the 
> assumptions. The default would always have to be the most conservative 
> assumption

With the constrained intrinsics the default is safe because optimizations don't 
recognize the constrained intrinsic and thus don't know how to optimize it. If 
we instead rely on the strictfp attribute then we'll need possibly thousands of 
checks for this attribute, we'll need everyone going forward to remember to 
check for it, and we'll have no way to verify that this rule is being followed.

https://github.com/llvm/llvm-project/pull/109798
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Implement operand bundles for floating-point operations (PR #109798)

2024-12-05 Thread Kevin P. Neal via cfe-commits


@@ -273,29 +306,6 @@ void InstrProfCallsite::setCallee(Value *Callee) {
   setArgOperand(4, Callee);
 }
 
-std::optional ConstrainedFPIntrinsic::getRoundingMode() const {
-  unsigned NumOperands = arg_size();
-  Metadata *MD = nullptr;
-  auto *MAV = dyn_cast(getArgOperand(NumOperands - 2));
-  if (MAV)
-MD = MAV->getMetadata();
-  if (!MD || !isa(MD))
-return std::nullopt;
-  return convertStrToRoundingMode(cast(MD)->getString());
-}
-
-std::optional
-ConstrainedFPIntrinsic::getExceptionBehavior() const {
-  unsigned NumOperands = arg_size();
-  Metadata *MD = nullptr;
-  auto *MAV = dyn_cast(getArgOperand(NumOperands - 1));
-  if (MAV)
-MD = MAV->getMetadata();
-  if (!MD || !isa(MD))
-return std::nullopt;
-  return convertStrToExceptionBehavior(cast(MD)->getString());
-}
-

kpneal wrote:

I thought the plan was to have concurrent implementations until we can throw 
the switch. That way we won't have releases that have half-broken constrained 
intrinsic support but half-implemented operand bundles.

https://github.com/llvm/llvm-project/pull/109798
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Reimplement constrained 'trunc' using operand bundles (PR #118253)

2024-12-05 Thread Kevin P. Neal via cfe-commits


@@ -251,10 +251,12 @@ static bool markTails(Function &F, 
OptimizationRemarkEmitter *ORE) {
 
   // Special-case operand bundles "clang.arc.attachedcall", "ptrauth", and
   // "kcfi".

kpneal wrote:

This comment needs to be updated. I suggest removing the list that is present 
in the code and replacing it with text explaining why these operand bundles are 
special cases.

https://github.com/llvm/llvm-project/pull/118253
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [IR] Don't set strictfp on irrelevant calls (PR #122735)

2025-02-04 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

> To handle the case where a block isn't owned by a function, we need the 
> attribute at the call site. I don't know the specifics of how that case 
> arises, but if we remove the attribute from the call site, we would have to 
> do something to add it again when the block gets detached from the function 
> (possibly during cloning?).

And then remove it again when reinserting the BB into a function body? That 
sounds like a complication, said complication may be missed by someone in the 
future who isn't focused on FP, and I haven't yet heard a reason we need all of 
this.

@spavloff -- Why do we need to change how we handle the strictfp attribute? 
What's the benefit?

https://github.com/llvm/llvm-project/pull/122735
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [IR] Don't set strictfp on irrelevant calls (PR #122735)

2025-02-04 Thread Kevin P. Neal via cfe-commits


@@ -66,6 +66,12 @@ bool IntrinsicInst::mayLowerToFunctionCall(Intrinsic::ID 
IID) {
   }
 }
 
+bool IntrinsicInst::canAccessFPEnvironment(LLVMContext &C, Intrinsic::ID IID) {
+  AttributeList Attrs = Intrinsic::getAttributes(C, IID);
+  MemoryEffects ME = Attrs.getMemoryEffects();
+  return ME.onlyAccessesInaccessibleMem();

kpneal wrote:

Wouldn't a large fraction of existing functions that may or may not have any 
floating point in them qualify as doesAccessInaccessibleMem()? It seems like if 
we're going to model the FP environment like "memory" then we need an FP 
environment modeling flag proper.

https://github.com/llvm/llvm-project/pull/122735
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [IR] Don't set strictfp on irrelevant calls (PR #122735)

2025-02-04 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

> > > If strict floating-point semantics are required at this call site, they 
> > > are are required on every relevant call in this function. It means 
> > > strictfp is a function attribute. Does anything prevents us from removal 
> > > strictfp from all call sites?
> > 
> > 
> > I think that takes us back to @kpneal's history, "Then we found that basic 
> > blocks were being optimized when they didn't belong to a function so we 
> > couldn't get to the where the strictfp attribute was located. The solution 
> > was to add the attribute to every function call."
> 
> It sounds like a transient property, used in very specific cases. We could 
> return to this problem later, when/if transition to bundles happens.

Revisiting decisions made in the past is, in general, a good thing. Sometimes 
(frequently?) it doesn't result in any change, but that doesn't make it any 
less worthwhile.

> What about this PR? With it `strictfp` can be used as an indicator of a call 
> that requires special handling for both constrained functions and calls with 
> FP bundles, while both coexist.

I think efforts to change the rules around the `strictfp` attribute are not 
warranted at this time. If, in the future, there's a real benefit to changing 
the rules then we can talk about it then. 

https://github.com/llvm/llvm-project/pull/122735
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Reimplement constrained 'trunc' using operand bundles (PR #118253)

2024-12-13 Thread Kevin P. Neal via cfe-commits


@@ -86,6 +86,43 @@ IRBuilderBase::createCallHelper(Function *Callee, 
ArrayRef Ops,
   return CI;
 }
 
+CallInst *IRBuilderBase::CreateCall(FunctionType *FTy, Value *Callee,
+ArrayRef Args,
+ArrayRef OpBundles,
+const Twine &Name, MDNode *FPMathTag) {
+  ArrayRef ActualBundlesRef = OpBundles;
+  SmallVector ActualBundles;
+
+  if (IsFPConstrained) {
+if (const auto *Func = dyn_cast(Callee)) {
+  if (Intrinsic::ID ID = Func->getIntrinsicID()) {
+if (IntrinsicInst::canAccessFPEnvironment(ID)) {
+  bool NeedRound = true, NeedExcept = true;
+  for (const auto &Item : OpBundles) {
+if (NeedRound && Item.getTag() == "fpe.round")
+  NeedRound = false;
+else if (NeedExcept && Item.getTag() == "fpe.except")
+  NeedExcept = false;
+ActualBundles.push_back(Item);

kpneal wrote:

Do we want intrinsics where the rounding mode is baked in (like trunc or floor) 
to be allowed to have a rounding mode bundle? Or, do we want the rounding mode 
bundle to be able to specify a rounding mode that isn't the one baked into the 
intrinsic? I'm leaning towards the rounding mode bundle not being allowed.

https://github.com/llvm/llvm-project/pull/118253
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [IR] Don't set strictfp on irrelevant calls (PR #122735)

2025-01-16 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

No, this is the wrong approach

https://github.com/llvm/llvm-project/pull/122735
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Reimplement constrained 'trunc' using operand bundles (PR #118253)

2025-01-08 Thread Kevin P. Neal via cfe-commits


@@ -86,6 +86,43 @@ IRBuilderBase::createCallHelper(Function *Callee, 
ArrayRef Ops,
   return CI;
 }
 
+CallInst *IRBuilderBase::CreateCall(FunctionType *FTy, Value *Callee,
+ArrayRef Args,
+ArrayRef OpBundles,
+const Twine &Name, MDNode *FPMathTag) {
+  ArrayRef ActualBundlesRef = OpBundles;
+  SmallVector ActualBundles;
+
+  if (IsFPConstrained) {
+if (const auto *Func = dyn_cast(Callee)) {
+  if (Intrinsic::ID ID = Func->getIntrinsicID()) {
+if (IntrinsicInst::canAccessFPEnvironment(ID)) {
+  bool NeedRound = true, NeedExcept = true;
+  for (const auto &Item : OpBundles) {
+if (NeedRound && Item.getTag() == "fpe.round")
+  NeedRound = false;
+else if (NeedExcept && Item.getTag() == "fpe.except")
+  NeedExcept = false;
+ActualBundles.push_back(Item);

kpneal wrote:

I think #1 is a better choice despite the downsides. Having more opportunities 
to optimize when lowering if we know the current rounding mode seems like a 
good choice. It does simplify the implementation in places as you said.

Having the rounding mode bundle specify the FP environment is a change from the 
constrained intrinsics, and this point is a little fine, so I do think we'll 
need to clearly state this in the LangRef at some point.

I am a little worried that we're creating a footgun and someone may write code 
that relies on the rounding mode bundle when handling trunc, floor, or one of 
the other math intrinsics/library calls. Then again, if code is trying to 
evaluate an expression then a switch is going to be needed with entries that 
would be expected to have rounding modes hardcoded into them. So I'm not 
worried enough to change my view that #1 is preferred.

Having the rounding mode bundle specify the FP environment also means we don't 
need any Verifier checks for improperly present or specified rounding bundles. 
That's a minor win.

One last point: this is another example of how having the rounding mode 
specified is useful. Since we've defined the constrained intrinsics to require 
the rounding mode be correct, and an incorrect rounding mode is undefined 
behavior, we can rely on the specified rounding mode being correct. The 
constant folding that we're doing currently checks the rounding mode in the 
cases I remember. We should carry over in the LangRef the verbiage about 
incorrect rounding mode metadata being UB.

https://github.com/llvm/llvm-project/pull/118253
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Reimplement constrained 'trunc' using operand bundles (PR #118253)

2025-01-08 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

I do think that before we start adding in code like this ticket we need to add 
IR Verifier code to check for proper use of the strictfp attribute. This code 
never made it into the tree because there are too many broken tests already in 
the tree.

Verifier code could be written that only fires when an error is detected AND no 
constrained intrinsics are used in a function. This should eliminate failures 
from most, but not all, of the currently broken tests. Hopefully the few broken 
tests that are in tree and fire will be small enough that they can be fixed. 
The remainder of the broken tests will be corrected over time or will simply be 
removed.

My ticket that never got pushed is here: https://reviews.llvm.org/D146845

I can provide a current version of that code if it would be useful.

I also have checks that are implemented on top of that code to ensure that 
regular FP instructions are never mixed with constrained intrinsics. We'll need 
to push something like that hopefully not long after we start putting this 
bundle support into the tree. 

https://github.com/llvm/llvm-project/pull/118253
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Reimplement constrained 'trunc' using operand bundles (PR #118253)

2025-01-09 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

D146845 wasn't committed because it would have caused test failures. The tests 
are wrong, the new checks reveal this, but the new checks cannot be committed 
until all broken tests are fixed. Otherwise we get failures from the bots and 
the Verifier checks would have been reverted.

The D146845 ticket encodes the current rules for the strictfp attribute. If you 
are making changes that fail with D146845 applied to your tree then you are 
moving in the wrong direction.

https://github.com/llvm/llvm-project/pull/118253
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [IR] Don't set strictfp on irrelevant calls (PR #122735)

2025-01-16 Thread Kevin P. Neal via cfe-commits

kpneal wrote:

A recap of the history of the strictfp attribute.

Originally we needed a way to prevent the Inliner from inlining a non-strictfp 
function into a strictfp function. We added the `strictfp` attribute to the 
function definition for this. Then we found that basic blocks were being 
optimized when they didn't belong to a function so we couldn't get to the where 
the `strictfp `attribute was located. The solution was to add the attribute to 
every function call. Simple.

Then I went to work on the Verifier changes. Originally I implemented it by 
checking to see if the presence of the attribute on a call site matched the 
presence on the function definition. Easy. But then I ran into a problem: 
Checks at call sites to see if an attribute is present will look through to the 
function declaration. 

Thus, we had to weaken the rule. Now, the `strictfp` attribute is allowed at 
call sites when the attribute is missing from the calling function's 
definition. If the `strictfp` attribute is present on the calling function's 
definition then the strictfp attribute is required on all call sites. This is 
the rule that is present in my IR Verifier ticket that was [approved 
(D146845)](https://reviews.llvm.org/D146845?id=542509) but not pushed because 
we still have broken tests.

Clearly intrinisics don't get inlined by the Inliner. But what if an intrinsic 
gets lowered to a call to a real function? Especially if LTO is being used? 
Will we lose the information that the function now being called needs the 
`strictfp` attribute or something similar? Since we don't have a way to mark 
accessing the FP environment, exactly, then aren't we throwing away information?

Is it still possible to write a check in the Verifier to catch any places where 
the `strictfp` attribute, or some equivalent, is missing?

I'm not convinced we're ready to drop any uses of the `strictfp` attribute 
without having all places that check for it changed first. And, does it make 
sense for the Inliner to be unable to inline a function if the called function 
`onlyAccessesInaccessibleMem()`? I don't think we're ready for a switchover.

https://github.com/llvm/llvm-project/pull/122735
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits