Skip to content

Commit d76db3e

Browse files
committed
Ignore spirv.Decorations metadata related to FP flags.
1 parent 37a3abe commit d76db3e

File tree

2 files changed

+20
-47
lines changed

2 files changed

+20
-47
lines changed

llvm/lib/Target/SPIRV/SPIRVUtils.cpp

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,18 @@ void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder,
197197
report_fatal_error("Expect SPIR-V <Decoration> operand to be the first "
198198
"element of the decoration");
199199

200-
// NoContraction decoration is deprecated by SPV_KHR_float_controls2, and
201-
// should be replaced with FPFastMathMode with appropriate flags. However, a
202-
// instruction can have both NoContraction and FPFastMathMode decorations,
203-
// and there is no guarantee about the order in which we will encounter
204-
// them, so we store the information of both and will handle them separately
205-
// after the loop so that we can combine them, if needed.
206-
if (ST.canUseExtension(SPIRV::Extension::SPV_KHR_float_controls2) &&
200+
// The goal of `spirv.Decorations` metadata is to provide a way to
201+
// represent SPIR-V entities that do not map to LLVM in an obvious way.
202+
// FP flags do have obvious matches between LLVM IR and SPIR-V.
203+
// Additionally, we have no guarantee at this point that the flags passed
204+
// through the decoration are not violated already in the optimizer passes.
205+
// Therefore, we simply ignore FP flags, including NoContraction, and
206+
// FPFastMathMode.
207+
if (DecorationId->getZExtValue() ==
208+
static_cast<uint32_t>(SPIRV::Decoration::NoContraction) ||
207209
DecorationId->getZExtValue() ==
208-
static_cast<uint32_t>(SPIRV::Decoration::NoContraction)) {
209-
NoContractionFound = true;
210-
continue; // NoContraction is handled separately.
211-
} else if (DecorationId->getZExtValue() ==
212-
static_cast<uint32_t>(SPIRV::Decoration::FPFastMathMode)) {
213-
FPFastMathModeFound = true;
214-
FPFastMathFlags = mdconst::dyn_extract<ConstantInt>(OpMD->getOperand(1))
215-
->getZExtValue();
216-
continue; // FPFastMathMode is handled separately.
210+
static_cast<uint32_t>(SPIRV::Decoration::FPFastMathMode)) {
211+
continue; // Ignored.
217212
}
218213
auto MIB = MIRBuilder.buildInstr(SPIRV::OpDecorate)
219214
.addUse(Reg)
@@ -228,20 +223,6 @@ void buildOpSpirvDecorations(Register Reg, MachineIRBuilder &MIRBuilder,
228223
report_fatal_error("Unexpected operand of the decoration");
229224
}
230225
}
231-
// If we have NoContraction decoration, we should set the
232-
// FPFastMathMode::AllowContract bit to 0. If it has been set to 1 by
233-
// FPFastMathMode decoration, we should report an error.
234-
if (NoContractionFound &&
235-
(FPFastMathFlags & SPIRV::FPFastMathMode::AllowContract))
236-
report_fatal_error(
237-
"Conflicting FPFastMathFlags: NoContraction and AllowContract");
238-
239-
if (NoContractionFound || FPFastMathModeFound) {
240-
MIRBuilder.buildInstr(SPIRV::OpDecorate)
241-
.addUse(Reg)
242-
.addImm(static_cast<uint32_t>(SPIRV::Decoration::FPFastMathMode))
243-
.addImm(FPFastMathFlags);
244-
}
245226
}
246227

247228
MachineBasicBlock::iterator getOpVariableMBBIt(MachineInstr &I) {

llvm/test/CodeGen/SPIRV/extensions/SPV_KHR_float_controls2/decoration.ll

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_float_controls2 %s -o - | FileCheck %s
22
; TODO: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_float_controls2 %s -o - -filetype=obj | spirv-val %}
33

4-
; CHECK-DAG: Capability FloatControls2
4+
; CHECK-DAG: Capability FloatControls2
55
; CHECK: Extension "SPV_KHR_float_controls2"
66

77
; CHECK: OpName %[[#addRes:]] "addRes"
@@ -33,22 +33,14 @@
3333
; CHECK: OpDecorate %[[#remRes]] FPFastMathMode AllowRecip
3434
; CHECK: OpDecorate %[[#negRes]] FPFastMathMode NotNaN|NotInf|NSZ|AllowRecip|AllowContract|AllowReassoc|AllowTransform
3535
; CHECK: OpDecorate %[[#oeqRes]] FPFastMathMode NotNaN|NotInf
36-
; CHECK: OpDecorate %[[#oneRes]] FPFastMathMode AllowReassoc|AllowTransform
37-
; CHECK: OpDecorate %[[#oltRes]] FPFastMathMode NotNaN|AllowReassoc|AllowTransform
38-
; CHECK: OpDecorate %[[#ogtRes]] FPFastMathMode NotInf|AllowReassoc|AllowTransform
39-
; CHECK: OpDecorate %[[#oleRes]] FPFastMathMode NSZ|AllowReassoc|AllowTransform
40-
; CHECK: OpDecorate %[[#ogeRes]] FPFastMathMode AllowRecip|AllowReassoc|AllowTransform
41-
; CHECK: OpDecorate %[[#ordRes]] FPFastMathMode NotNaN|NotInf|NSZ|AllowRecip|AllowContract|AllowReassoc|AllowTransform
42-
; CHECK: OpDecorate %[[#ueqRes]] FPFastMathMode NotNaN|NotInf|AllowReassoc|AllowTransform
43-
; CHECK: OpDecorate %[[#uneRes]] FPFastMathMode AllowReassoc|AllowTransform
44-
; CHECK: OpDecorate %[[#ultRes]] FPFastMathMode AllowReassoc|AllowTransform
45-
; CHECK: OpDecorate %[[#ugtRes]] FPFastMathMode AllowReassoc|AllowTransform
46-
; CHECK: OpDecorate %[[#uleRes]] FPFastMathMode AllowReassoc|AllowTransform
47-
; CHECK: OpDecorate %[[#ugeRes]] FPFastMathMode AllowReassoc|AllowTransform
48-
; CHECK: OpDecorate %[[#unoRes]] FPFastMathMode AllowReassoc|AllowTransform
49-
; CHECK-NOT: OpDecorate %[[#modRes]] FPFastMathMode
50-
; CHECK: OpDecorate %[[#maxRes]] FPFastMathMode NotNaN|NotInf|NSZ|AllowRecip|AllowContract|AllowReassoc|AllowTransform
51-
; CHECK: OpDecorate %[[#maxCommonRes:]] FPFastMathMode NotNaN|NotInf
36+
; CHECK: OpDecorate %[[#oltRes]] FPFastMathMode NotNaN
37+
; CHECK: OpDecorate %[[#ogtRes]] FPFastMathMode NotInf
38+
; CHECK: OpDecorate %[[#oleRes]] FPFastMathMode NSZ
39+
; CHECK: OpDecorate %[[#ogeRes]] FPFastMathMode AllowRecip
40+
; CHECK: OpDecorate %[[#ordRes]] FPFastMathMode NotNaN|NotInf|NSZ|AllowRecip|AllowContract|AllowReassoc|AllowTransform
41+
; CHECK: OpDecorate %[[#ueqRes]] FPFastMathMode NotNaN|NotInf
42+
; CHECK: OpDecorate %[[#maxRes]] FPFastMathMode NotNaN|NotInf|NSZ|AllowRecip|AllowContract|AllowReassoc|AllowTransform
43+
; CHECK: OpDecorate %[[#maxCommonRes:]] FPFastMathMode NotNaN|NotInf
5244

5345
; Function Attrs: convergent mustprogress nofree nounwind willreturn memory(none)
5446
declare spir_func float @_Z4fmodff(float, float)

0 commit comments

Comments
 (0)