[llvm] a8cc904 - CodeGen: Add -denormal-fp-math-f32 flag
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 27 14:00:58 PDT 2020
Author: Matt Arsenault
Date: 2020-03-27T14:00:39-07:00
New Revision: a8cc9047de090352d244c0e1d1db8b4d9b4b7502
URL: https://github.com/llvm/llvm-project/commit/a8cc9047de090352d244c0e1d1db8b4d9b4b7502
DIFF: https://github.com/llvm/llvm-project/commit/a8cc9047de090352d244c0e1d1db8b4d9b4b7502.diff
LOG: CodeGen: Add -denormal-fp-math-f32 flag
Make the set of FP related attributes and command flags closer.
Added:
llvm/test/Other/opt-override-denormal-fp-math-f32.ll
llvm/test/Other/opt-override-denormal-fp-math-mixed.ll
llvm/test/Other/opt-override-denormal-fp-math.ll
Modified:
llvm/include/llvm/CodeGen/CommandFlags.h
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
llvm/test/CodeGen/NVPTX/f16-instructions.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/CommandFlags.h b/llvm/include/llvm/CodeGen/CommandFlags.h
index f6d221689f6c..c017652b469b 100644
--- a/llvm/include/llvm/CodeGen/CommandFlags.h
+++ b/llvm/include/llvm/CodeGen/CommandFlags.h
@@ -64,6 +64,7 @@ bool getEnableNoSignedZerosFPMath();
bool getEnableNoTrappingFPMath();
DenormalMode::DenormalModeKind getDenormalFPMath();
+DenormalMode::DenormalModeKind getDenormalFP32Math();
bool getEnableHonorSignDependentRoundingFPMath();
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index d1540afc702a..12fc1df8d9b7 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -55,6 +55,7 @@ CGOPT(bool, EnableNoNaNsFPMath)
CGOPT(bool, EnableNoSignedZerosFPMath)
CGOPT(bool, EnableNoTrappingFPMath)
CGOPT(DenormalMode::DenormalModeKind, DenormalFPMath)
+CGOPT(DenormalMode::DenormalModeKind, DenormalFP32Math)
CGOPT(bool, EnableHonorSignDependentRoundingFPMath)
CGOPT(FloatABI::ABIType, FloatABIForCalls)
CGOPT(FPOpFusion::FPOpFusionMode, FuseFPOps)
@@ -212,20 +213,30 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
cl::init(false));
CGBINDOPT(EnableNoTrappingFPMath);
+ static const auto DenormFlagEnumOptions =
+ cl::values(clEnumValN(DenormalMode::IEEE, "ieee",
+ "IEEE 754 denormal numbers"),
+ clEnumValN(DenormalMode::PreserveSign, "preserve-sign",
+ "the sign of a flushed-to-zero number is preserved "
+ "in the sign of 0"),
+ clEnumValN(DenormalMode::PositiveZero, "positive-zero",
+ "denormals are flushed to positive zero"));
+
+ // FIXME: Doesn't have way to specify separate input and output modes.
static cl::opt<DenormalMode::DenormalModeKind> DenormalFPMath(
- "denormal-fp-math",
- cl::desc(
- "Select which denormal numbers the code is permitted to require"),
- cl::init(DenormalMode::IEEE),
- cl::values(
- clEnumValN(DenormalMode::IEEE, "ieee", "IEEE 754 denormal numbers"),
- clEnumValN(DenormalMode::PreserveSign, "preserve-sign",
- "the sign of a flushed-to-zero number is preserved "
- "in the sign of 0"),
- clEnumValN(DenormalMode::PositiveZero, "positive-zero",
- "denormals are flushed to positive zero")));
+ "denormal-fp-math",
+ cl::desc("Select which denormal numbers the code is permitted to require"),
+ cl::init(DenormalMode::IEEE),
+ DenormFlagEnumOptions);
CGBINDOPT(DenormalFPMath);
+ static cl::opt<DenormalMode::DenormalModeKind> DenormalFP32Math(
+ "denormal-fp-math-f32",
+ cl::desc("Select which denormal numbers the code is permitted to require for float"),
+ cl::init(DenormalMode::Invalid),
+ DenormFlagEnumOptions);
+ CGBINDOPT(DenormalFP32Math);
+
static cl::opt<bool> EnableHonorSignDependentRoundingFPMath(
"enable-sign-dependent-rounding-fp-math", cl::Hidden,
cl::desc("Force codegen to assume rounding mode can change dynamically"),
@@ -577,6 +588,16 @@ void codegen::setFunctionAttributes(StringRef CPU, StringRef Features,
DenormalMode(DenormKind, DenormKind).str());
}
+ if (DenormalFP32MathView->getNumOccurrences() > 0 &&
+ !F.hasFnAttribute("denormal-fp-math-f32")) {
+ // FIXME: Command line flag should expose separate input/output modes.
+ DenormalMode::DenormalModeKind DenormKind = getDenormalFP32Math();
+
+ NewAttrs.addAttribute(
+ "denormal-fp-math-f32",
+ DenormalMode(DenormKind, DenormKind).str());
+ }
+
if (TrapFuncNameView->getNumOccurrences() > 0)
for (auto &B : F)
for (auto &I : B)
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
index f1b66094ff76..83074ca22768 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
@@ -88,11 +88,6 @@ static cl::opt<bool> UsePrecSqrtF32(
cl::desc("NVPTX Specific: 0 use sqrt.approx, 1 use sqrt.rn."),
cl::init(true));
-static cl::opt<bool> FtzEnabled(
- "nvptx-f32ftz", cl::ZeroOrMore, cl::Hidden,
- cl::desc("NVPTX Specific: Flush f32 subnormals to sign-preserving zero."),
- cl::init(false));
-
int NVPTXTargetLowering::getDivF32Level() const {
if (UsePrecDivF32.getNumOccurrences() > 0) {
// If nvptx-prec-div32=N is used on the command-line, always honor it
@@ -117,12 +112,6 @@ bool NVPTXTargetLowering::usePrecSqrtF32() const {
}
bool NVPTXTargetLowering::useF32FTZ(const MachineFunction &MF) const {
- // TODO: Get rid of this flag; there can be only one way to do this.
- if (FtzEnabled.getNumOccurrences() > 0) {
- // If nvptx-f32ftz is used on the command-line, always honor it
- return FtzEnabled;
- }
-
return MF.getDenormalMode(APFloat::IEEEsingle()).Output ==
DenormalMode::PreserveSign;
}
diff --git a/llvm/test/CodeGen/NVPTX/f16-instructions.ll b/llvm/test/CodeGen/NVPTX/f16-instructions.ll
index 891842af5a8d..3856cb63350d 100644
--- a/llvm/test/CodeGen/NVPTX/f16-instructions.ll
+++ b/llvm/test/CodeGen/NVPTX/f16-instructions.ll
@@ -5,7 +5,7 @@
; ## Full FP16 with FTZ
; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda -mcpu=sm_53 -asm-verbose=false \
; RUN: -O0 -disable-post-ra -frame-pointer=all -verify-machineinstrs \
-; RUN: -nvptx-f32ftz \
+; RUN: -denormal-fp-math-f32=preserve-sign \
; RUN: | FileCheck -check-prefixes CHECK,CHECK-F16,CHECK-F16-FTZ %s
; ## FP16 support explicitly disabled.
; RUN: llc < %s -mtriple=nvptx64-nvidia-cuda -mcpu=sm_53 -asm-verbose=false \
diff --git a/llvm/test/Other/opt-override-denormal-fp-math-f32.ll b/llvm/test/Other/opt-override-denormal-fp-math-f32.ll
new file mode 100644
index 000000000000..3bb88a66e854
--- /dev/null
+++ b/llvm/test/Other/opt-override-denormal-fp-math-f32.ll
@@ -0,0 +1,23 @@
+; RUN: opt -S -denormal-fp-math-f32=ieee %s | FileCheck -check-prefixes=IEEE,ALL %s
+; RUN: opt -S -denormal-fp-math-f32=preserve-sign %s | FileCheck -check-prefixes=PRESERVESIGN,ALL %s
+; RUN: opt -S -denormal-fp-math-f32=positive-zero %s | FileCheck -check-prefixes=POSZERO,ALL %s
+
+; ALL: @no_denormal_fp_math_f32_attr() [[NOATTR:#[0-9]+]] {
+define i32 @no_denormal_fp_math_f32_attr() #0 {
+entry:
+ ret i32 0
+}
+
+; ALL: denormal_fp_math_attr_preserve_sign_ieee() [[ATTR:#[0-9]+]] {
+define i32 @denormal_fp_math_attr_preserve_sign_ieee() #1 {
+entry:
+ ret i32 0
+}
+
+; ALL-DAG: attributes [[ATTR]] = { nounwind "denormal-fp-math-f32"="preserve-sign,ieee" }
+; IEEE-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math-f32"="ieee,ieee" }
+; PRESERVESIGN-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math-f32"="preserve-sign,preserve-sign" }
+; POSITIVEZERO-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math-f32"="positive-zero,positive-zero" }
+
+attributes #0 = { nounwind }
+attributes #1 = { nounwind "denormal-fp-math-f32"="preserve-sign,ieee" }
diff --git a/llvm/test/Other/opt-override-denormal-fp-math-mixed.ll b/llvm/test/Other/opt-override-denormal-fp-math-mixed.ll
new file mode 100644
index 000000000000..dffabbb7dccd
--- /dev/null
+++ b/llvm/test/Other/opt-override-denormal-fp-math-mixed.ll
@@ -0,0 +1,42 @@
+; RUN: opt -S -denormal-fp-math=ieee %s | FileCheck -check-prefixes=IEEE,ALL %s
+; RUN: opt -S -denormal-fp-math=preserve-sign %s | FileCheck -check-prefixes=PRESERVESIGN,ALL %s
+; RUN: opt -S -denormal-fp-math=positive-zero %s | FileCheck -check-prefixes=POSZERO,ALL %s
+
+; RUN: opt -S -denormal-fp-math-f32=ieee %s | FileCheck -check-prefixes=IEEEF32,ALL %s
+; RUN: opt -S -denormal-fp-math-f32=preserve-sign %s | FileCheck -check-prefixes=PRESERVESIGNF32,ALL %s
+; RUN: opt -S -denormal-fp-math-f32=positive-zero %s | FileCheck -check-prefixes=POSZEROF32,ALL %s
+
+; RUN: opt -S -denormal-fp-math=ieee -denormal-fp-math-f32=ieee %s | FileCheck -check-prefixes=IEEE-BOTH,ALL %s
+; RUN: opt -S -denormal-fp-math=preserve-sign -denormal-fp-math-f32=preserve-sign %s | FileCheck -check-prefixes=PRESERVESIGN-BOTH,ALL %s
+; RUN: opt -S -denormal-fp-math=positive-zero -denormal-fp-math-f32=positive-zero %s | FileCheck -check-prefixes=POSZERO-BOTH,ALL %s
+
+
+
+; ALL: @no_denormal_fp_math_attrs() [[NOATTR:#[0-9]+]] {
+define i32 @no_denormal_fp_math_attrs() #0 {
+entry:
+ ret i32 0
+}
+
+; ALL: both_denormal_fp_math_attrs_preserve_sign_ieee() [[ATTR:#[0-9]+]] {
+define i32 @both_denormal_fp_math_attrs_preserve_sign_ieee() #1 {
+entry:
+ ret i32 0
+}
+
+; ALL-DAG: attributes [[ATTR]] = { nounwind "denormal-fp-math"="preserve-sign,ieee" "denormal-fp-math-f32"="preserve-sign,ieee" }
+
+; IEEE-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math"="ieee,ieee" }
+; PRESERVESIGN-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math"="preserve-sign,preserve-sign" }
+; POSITIVEZERO-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math"="positive-zero,positive-zero" }
+
+; IEEEF32-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math-f32"="ieee,ieee" }
+; PRESERVESIGNF32-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math-f32"="preserve-sign,preserve-sign" }
+; POSITIVEZEROF32-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math-f32"="positive-zero,positive-zero" }
+
+; IEEE-BOTH-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math"="ieee,ieee" "denormal-fp-math-f32"="ieee,ieee" }
+; PRESERVESIGN-BOTH-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math"="preserve-sign,preserve-sign" "denormal-fp-math-f32"="preserve-sign,preserve-sign" }
+; POSITIVEZERO-BOTH-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math"="positive-zero,positive-zero" "denormal-fp-math-f32"="positive-zero,positive-zero" }
+
+attributes #0 = { nounwind }
+attributes #1 = { nounwind "denormal-fp-math"="preserve-sign,ieee" "denormal-fp-math-f32"="preserve-sign,ieee" }
diff --git a/llvm/test/Other/opt-override-denormal-fp-math.ll b/llvm/test/Other/opt-override-denormal-fp-math.ll
new file mode 100644
index 000000000000..5a248205e53f
--- /dev/null
+++ b/llvm/test/Other/opt-override-denormal-fp-math.ll
@@ -0,0 +1,23 @@
+; RUN: opt -S -denormal-fp-math=ieee %s | FileCheck -check-prefixes=IEEE,ALL %s
+; RUN: opt -S -denormal-fp-math=preserve-sign %s | FileCheck -check-prefixes=PRESERVESIGN,ALL %s
+; RUN: opt -S -denormal-fp-math=positive-zero %s | FileCheck -check-prefixes=POSZERO,ALL %s
+
+; ALL: @no_denormal_fp_math_attr() [[NOATTR:#[0-9]+]] {
+define i32 @no_denormal_fp_math_attr() #0 {
+entry:
+ ret i32 0
+}
+
+; ALL: denormal_fp_math_attr_preserve_sign_ieee() [[ATTR:#[0-9]+]] {
+define i32 @denormal_fp_math_attr_preserve_sign_ieee() #1 {
+entry:
+ ret i32 0
+}
+
+; ALL-DAG: attributes [[ATTR]] = { nounwind "denormal-fp-math"="preserve-sign,ieee" }
+; IEEE-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math"="ieee,ieee" }
+; PRESERVESIGN-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math"="preserve-sign,preserve-sign" }
+; POSITIVEZERO-DAG: attributes [[NOATTR]] = { nounwind "denormal-fp-math"="positive-zero,positive-zero" }
+
+attributes #0 = { nounwind }
+attributes #1 = { nounwind "denormal-fp-math"="preserve-sign,ieee" }
More information about the llvm-commits
mailing list