Index: llvm/include/llvm/CodeGen/TargetLowering.h =================================================================== --- llvm/include/llvm/CodeGen/TargetLowering.h +++ llvm/include/llvm/CodeGen/TargetLowering.h @@ -231,6 +231,11 @@ TargetLoweringBase &operator=(const TargetLoweringBase &) = delete; virtual ~TargetLoweringBase() = default; + /// Return true if the target support strict float operation + bool isStrictFPEnabled() const { + return IsStrictFPEnabled; + } + protected: /// Initialize all of the actions to default values. void initActions(); @@ -2932,6 +2937,8 @@ /// details. MachineBasicBlock *emitXRayTypedEvent(MachineInstr &MI, MachineBasicBlock *MBB) const; + + bool IsStrictFPEnabled; }; /// This class defines information used to lower LLVM code to legal SelectionDAG Index: llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -2655,6 +2655,18 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) { LLVM_DEBUG(dbgs() << "Trying to expand node\n"); + // FIXME: when the backend has enabled strict-float, we + // assume that expanding a strict floating-point operation + // only when the corresponding normal float-point operation + // is expanded. + if (Node->isStrictFPOpcode() && TLI.isStrictFPEnabled() + && TLI.getStrictFPOperationAction(Node->getOpcode(), + Node->getValueType(0)) + != TargetLowering::Expand) { + LLVM_DEBUG(dbgs() << "Cannot expand node\n"); + return false; + } + SmallVector Results; SDLoc dl(Node); SDValue Tmp1, Tmp2, Tmp3, Tmp4; Index: llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp +++ llvm/lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp @@ -344,9 +344,9 @@ // best approach, except in the case where the resulting strict (scalar) // operations would themselves use the fallback mutation to non-strict. // In that specific case, just do the fallback on the vector op. - if (Action == TargetLowering::Expand && + if (Action == TargetLowering::Expand && !TLI.isStrictFPEnabled() && TLI.getStrictFPOperationAction(Node->getOpcode(), - Node->getValueType(0)) + Node->getValueType(0)) == TargetLowering::Legal) { EVT EltVT = Node->getValueType(0).getVectorElementType(); if (TLI.getOperationAction(Node->getOpcode(), EltVT) Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -1159,9 +1159,9 @@ // we convert them to normal FP opcodes instead at this point. This // will allow them to be handled by existing target-specific instruction // selectors. - if (Node->isStrictFPOpcode() && - (TLI->getOperationAction(Node->getOpcode(), Node->getValueType(0)) - != TargetLowering::Legal)) + if (!TLI->isStrictFPEnabled() && Node->isStrictFPOpcode() + && (TLI->getOperationAction(Node->getOpcode(), Node->getValueType(0)) + != TargetLowering::Legal)) Node = CurDAG->mutateStrictFPToFP(Node); LLVM_DEBUG(dbgs() << "\nISEL: Starting selection on root node: "; Index: llvm/lib/CodeGen/TargetLoweringBase.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringBase.cpp +++ llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -88,6 +88,14 @@ cl::desc("Minimum density for building a jump table in " "an optsize function")); +// FIXME: This option is only to test if the strict fp operation processed +// correctly by preventing mutating strict fp operation to normal fp operation +// during development. When the backend supports strict float operation, this +// option will be meaningless. +static cl::opt DisableStrictNodeMutation("disable-strictnode-mutation", + cl::desc("Don't mutate strict-float node to a legalize node"), + cl::init(false), cl::Hidden); + static bool darwinHasSinCos(const Triple &TT) { assert(TT.isOSDarwin() && "should be called with darwin triple"); // Don't bother with 32 bit x86. @@ -585,6 +593,7 @@ BooleanVectorContents = UndefinedBooleanContent; SchedPreferenceInfo = Sched::ILP; GatherAllAliasesMaxDepth = 18; + IsStrictFPEnabled = DisableStrictNodeMutation; // TODO: the default will be switched to 0 in the next commit, along // with the Target-specific changes necessary. MaxAtomicSizeInBitsSupported = 1024; Index: llvm/lib/Target/SystemZ/SystemZISelLowering.cpp =================================================================== --- llvm/lib/Target/SystemZ/SystemZISelLowering.cpp +++ llvm/lib/Target/SystemZ/SystemZISelLowering.cpp @@ -634,6 +634,9 @@ // than "STC;MVC". Handle the choice in target-specific code instead. MaxStoresPerMemset = 0; MaxStoresPerMemsetOptSize = 0; + + // Default to having -disable-strictnode-mutation on + IsStrictFPEnabled = true; } EVT SystemZTargetLowering::getSetCCResultType(const DataLayout &DL,