Skip to content

Commit 6c5d5ce

Browse files
committedJun 5, 2019
Allow target to handle STRICT floating-point nodes
The ISD::STRICT_ nodes used to implement the constrained floating-point intrinsics are currently never passed to the target back-end, which makes it impossible to handle them correctly (e.g. mark instructions are depending on a floating-point status and control register, or mark instructions as possibly trapping). This patch allows the target to use setOperationAction to switch the action on ISD::STRICT_ nodes to Legal. If this is done, the SelectionDAG common code will stop converting the STRICT nodes to regular floating-point nodes, but instead pass the STRICT nodes to the target using normal SelectionDAG matching rules. To avoid having the back-end duplicate all the floating-point instruction patterns to handle both strict and non-strict variants, we make the MI codegen explicitly aware of the floating-point exceptions by introducing two new concepts: - A new MCID flag "mayRaiseFPException" that the target should set on any instruction that possibly can raise FP exception according to the architecture definition. - A new MI flag FPExcept that CodeGen/SelectionDAG will set on any MI instruction resulting from expansion of any constrained FP intrinsic. Any MI instruction that is *both* marked as mayRaiseFPException *and* FPExcept then needs to be considered as raising exceptions by MI-level codegen (e.g. scheduling). Setting those two new flags is straightforward. The mayRaiseFPException flag is simply set via TableGen by marking all relevant instruction patterns in the .td files. The FPExcept flag is set in SDNodeFlags when creating the STRICT_ nodes in the SelectionDAG, and gets inherited in the MachineSDNode nodes created from it during instruction selection. The flag is then transfered to an MIFlag when creating the MI from the MachineSDNode. This is handled just like fast-math flags like no-nans are handled today. This patch includes both common code changes required to implement the new features, and the SystemZ implementation. Reviewed By: andrew.w.kaylor Differential Revision: https://reviews.llvm.org/D55506 llvm-svn: 362663
1 parent 2f94203 commit 6c5d5ce

File tree

82 files changed

+5788
-372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+5788
-372
lines changed
 

‎llvm/include/llvm/CodeGen/MachineInstr.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ class MachineInstr
102102
// no unsigned wrap.
103103
NoSWrap = 1 << 12, // Instruction supports binary operator
104104
// no signed wrap.
105-
IsExact = 1 << 13 // Instruction supports division is
105+
IsExact = 1 << 13, // Instruction supports division is
106106
// known to be exact.
107+
FPExcept = 1 << 14, // Instruction may raise floating-point
108+
// exceptions.
107109
};
108110

109111
private:
@@ -830,6 +832,17 @@ class MachineInstr
830832
return mayLoad(Type) || mayStore(Type);
831833
}
832834

835+
/// Return true if this instruction could possibly raise a floating-point
836+
/// exception. This is the case if the instruction is a floating-point
837+
/// instruction that can in principle raise an exception, as indicated
838+
/// by the MCID::MayRaiseFPException property, *and* at the same time,
839+
/// the instruction is used in a context where we expect floating-point
840+
/// exceptions might be enabled, as indicated by the FPExcept MI flag.
841+
bool mayRaiseFPException() const {
842+
return hasProperty(MCID::MayRaiseFPException) &&
843+
getFlag(MachineInstr::MIFlag::FPExcept);
844+
}
845+
833846
//===--------------------------------------------------------------------===//
834847
// Flags that indicate whether an instruction can be modified by a method.
835848
//===--------------------------------------------------------------------===//

‎llvm/include/llvm/CodeGen/SelectionDAGNodes.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,21 @@ struct SDNodeFlags {
368368
bool ApproximateFuncs : 1;
369369
bool AllowReassociation : 1;
370370

371+
// We assume instructions do not raise floating-point exceptions by default,
372+
// and only those marked explicitly may do so. We could choose to represent
373+
// this via a positive "FPExcept" flags like on the MI level, but having a
374+
// negative "NoFPExcept" flag here (that defaults to true) makes the flag
375+
// intersection logic more straightforward.
376+
bool NoFPExcept : 1;
377+
371378
public:
372379
/// Default constructor turns off all optimization flags.
373380
SDNodeFlags()
374381
: AnyDefined(false), NoUnsignedWrap(false), NoSignedWrap(false),
375382
Exact(false), NoNaNs(false), NoInfs(false),
376383
NoSignedZeros(false), AllowReciprocal(false), VectorReduction(false),
377384
AllowContract(false), ApproximateFuncs(false),
378-
AllowReassociation(false) {}
385+
AllowReassociation(false), NoFPExcept(true) {}
379386

380387
/// Propagate the fast-math-flags from an IR FPMathOperator.
381388
void copyFMF(const FPMathOperator &FPMO) {
@@ -438,6 +445,10 @@ struct SDNodeFlags {
438445
setDefined();
439446
AllowReassociation = b;
440447
}
448+
void setFPExcept(bool b) {
449+
setDefined();
450+
NoFPExcept = !b;
451+
}
441452

442453
// These are accessors for each flag.
443454
bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
@@ -451,9 +462,10 @@ struct SDNodeFlags {
451462
bool hasAllowContract() const { return AllowContract; }
452463
bool hasApproximateFuncs() const { return ApproximateFuncs; }
453464
bool hasAllowReassociation() const { return AllowReassociation; }
465+
bool hasFPExcept() const { return !NoFPExcept; }
454466

455467
bool isFast() const {
456-
return NoSignedZeros && AllowReciprocal && NoNaNs && NoInfs &&
468+
return NoSignedZeros && AllowReciprocal && NoNaNs && NoInfs && NoFPExcept &&
457469
AllowContract && ApproximateFuncs && AllowReassociation;
458470
}
459471

@@ -473,6 +485,7 @@ struct SDNodeFlags {
473485
AllowContract &= Flags.AllowContract;
474486
ApproximateFuncs &= Flags.ApproximateFuncs;
475487
AllowReassociation &= Flags.AllowReassociation;
488+
NoFPExcept &= Flags.NoFPExcept;
476489
}
477490
};
478491

0 commit comments

Comments
 (0)
Please sign in to comment.