Skip to content

Commit ae6a780

Browse files
authored
[HLSL] [DirectX] translate llvm fast math flags to llvm 3.7 fast math flags (llvm#122025)
Translate modern LLVM fast math flags to LLVM 3.7 equivalent in DXIL bitcode. Mostly use patch from llvm#120630 Closes llvm#120630
1 parent b3ce6dc commit ae6a780

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,8 @@ uint64_t DXILBitcodeWriter::getOptimizationFlags(const Value *V) {
749749
if (PEO->isExact())
750750
Flags |= 1 << bitc::PEO_EXACT;
751751
} else if (const auto *FPMO = dyn_cast<FPMathOperator>(V)) {
752-
if (FPMO->hasAllowReassoc())
753-
Flags |= bitc::AllowReassoc;
752+
if (FPMO->hasAllowReassoc() || FPMO->hasAllowContract())
753+
Flags |= bitc::UnsafeAlgebra;
754754
if (FPMO->hasNoNaNs())
755755
Flags |= bitc::NoNaNs;
756756
if (FPMO->hasNoInfs())
@@ -759,10 +759,6 @@ uint64_t DXILBitcodeWriter::getOptimizationFlags(const Value *V) {
759759
Flags |= bitc::NoSignedZeros;
760760
if (FPMO->hasAllowReciprocal())
761761
Flags |= bitc::AllowReciprocal;
762-
if (FPMO->hasAllowContract())
763-
Flags |= bitc::AllowContract;
764-
if (FPMO->hasApproxFunc())
765-
Flags |= bitc::ApproxFunc;
766762
}
767763

768764
return Flags;

llvm/test/tools/dxil-dis/fastmath.ll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc %s --filetype=obj -o - | dxil-dis -o - | FileCheck %s
2+
target triple = "dxil-unknown-shadermodel6.7-library"
3+
4+
define float @fma(float %0, float %1, float %2) #0 {
5+
; verify reassoc and contract are converted to fast
6+
; CHECK: %4 = fmul fast float %0, %1
7+
%4 = fmul reassoc float %0, %1
8+
; CHECK-NEXT: %5 = fadd fast float %4, %2
9+
%5 = fadd contract float %4, %2
10+
; verify these are converted to a single fast flag
11+
; CHECK-NEXT: %6 = fmul fast float %0, %1
12+
%6 = fmul reassoc contract float %0, %1
13+
; verify these flags are maintained
14+
; CHECK-NEXT: %7 = fadd nnan ninf nsz arcp float %0, %1
15+
%7 = fadd nnan ninf nsz arcp float %0, %1
16+
; verify that afn is removed
17+
; CHECK-NEXT: %8 = fmul float %0, %1
18+
%8 = fmul afn float %0, %1
19+
ret float %5
20+
}
21+
22+
attributes #0 = { norecurse nounwind readnone willreturn "disable-tail-calls"="false" "waveops-include-helper-lanes" "fp32-denorm-mode"="any" "hlsl.export" }
23+

0 commit comments

Comments
 (0)