[llvm] [HLSL] [DirectX] translate llvm fast math flags to llvm 3.7 fast math flags (PR #122025)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 7 16:18:52 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-directx
Author: Sarah Spall (spall)
<details>
<summary>Changes</summary>
Translate modern LLVM fast math flags to LLVM 3.7 equivalent in DXIL bitcode. Mostly use patch from #<!-- -->120630
Closes #<!-- -->120630
---
Full diff: https://github.com/llvm/llvm-project/pull/122025.diff
2 Files Affected:
- (modified) llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp (+2-6)
- (added) llvm/test/tools/dxil-dis/fastmath.ll (+23)
``````````diff
diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
index 45aadac861946b..be68d46a876db2 100644
--- a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
+++ b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
@@ -749,8 +749,8 @@ uint64_t DXILBitcodeWriter::getOptimizationFlags(const Value *V) {
if (PEO->isExact())
Flags |= 1 << bitc::PEO_EXACT;
} else if (const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
- if (FPMO->hasAllowReassoc())
- Flags |= bitc::AllowReassoc;
+ if (FPMO->hasAllowReassoc() || FPMO->hasAllowContract())
+ Flags |= bitc::UnsafeAlgebra;
if (FPMO->hasNoNaNs())
Flags |= bitc::NoNaNs;
if (FPMO->hasNoInfs())
@@ -759,10 +759,6 @@ uint64_t DXILBitcodeWriter::getOptimizationFlags(const Value *V) {
Flags |= bitc::NoSignedZeros;
if (FPMO->hasAllowReciprocal())
Flags |= bitc::AllowReciprocal;
- if (FPMO->hasAllowContract())
- Flags |= bitc::AllowContract;
- if (FPMO->hasApproxFunc())
- Flags |= bitc::ApproxFunc;
}
return Flags;
diff --git a/llvm/test/tools/dxil-dis/fastmath.ll b/llvm/test/tools/dxil-dis/fastmath.ll
new file mode 100644
index 00000000000000..7f4ba5b4cdd9f8
--- /dev/null
+++ b/llvm/test/tools/dxil-dis/fastmath.ll
@@ -0,0 +1,23 @@
+; RUN: llc %s --filetype=obj -o - | dxil-dis -o - | FileCheck %s
+target triple = "dxil-unknown-shadermodel6.7-library"
+
+define float @fma(float %0, float %1, float %2) #0 {
+ ; verify reassoc and contract are converted to fast
+ ; CHECK: %4 = fmul fast float %0, %1
+ %4 = fmul reassoc float %0, %1
+ ; CHECK-NEXT: %5 = fadd fast float %4, %2
+ %5 = fadd contract float %4, %2
+ ; verify these are converted to a single fast flag
+ ; CHECK-NEXT: %6 = fmul fast float %0, %1
+ %6 = fmul reassoc contract float %0, %1
+ ; verify these flags are maintained
+ ; CHECK-NEXT: %7 = fadd nnan ninf nsz arcp float %0, %1
+ %7 = fadd nnan ninf nsz arcp float %0, %1
+ ; verify that afn is removed
+ ; CHECK-NEXT: %8 = fmul float %0, %1
+ %8 = fmul afn float %0, %1
+ ret float %5
+}
+
+attributes #0 = { norecurse nounwind readnone willreturn "disable-tail-calls"="false" "waveops-include-helper-lanes" "fp32-denorm-mode"="any" "hlsl.export" }
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/122025
More information about the llvm-commits
mailing list