diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h index 14a641512a67d..a38dd34a17097 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h @@ -1267,7 +1267,7 @@ class MachineIRBuilder { /// \return a MachineInstrBuilder for the newly created instruction. MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, const DstOp &Res, const SrcOp &Op0, const SrcOp &Op1, - std::optional Flgs = std::nullopt); + std::optional Flags = std::nullopt); /// Build and insert a \p Res = G_FCMP \p Pred\p Op0, \p Op1 /// diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h index ae07420479e14..739ce05e94734 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -411,12 +411,14 @@ struct SDNodeFlags { NoFPExcept = 1 << 12, // Instructions with attached 'unpredictable' metadata on IR level. Unpredictable = 1 << 13, + // Compare instructions which may carry the samesign flag. + SameSign = 1 << 14, // NOTE: Please update LargestValue in LLVM_DECLARE_ENUM_AS_BITMASK below // the class definition when adding new flags. PoisonGeneratingFlags = NoUnsignedWrap | NoSignedWrap | Exact | Disjoint | - NonNeg | NoNaNs | NoInfs, + NonNeg | NoNaNs | NoInfs | SameSign, }; /// Default constructor turns off all optimization flags. @@ -438,6 +440,7 @@ struct SDNodeFlags { void setNoSignedWrap(bool b) { setFlag(b); } void setExact(bool b) { setFlag(b); } void setDisjoint(bool b) { setFlag(b); } + void setSameSign(bool b) { setFlag(b); } void setNonNeg(bool b) { setFlag(b); } void setNoNaNs(bool b) { setFlag(b); } void setNoInfs(bool b) { setFlag(b); } @@ -454,6 +457,7 @@ struct SDNodeFlags { bool hasNoSignedWrap() const { return Flags & NoSignedWrap; } bool hasExact() const { return Flags & Exact; } bool hasDisjoint() const { return Flags & Disjoint; } + bool hasSameSign() const { return Flags & SameSign; } bool hasNonNeg() const { return Flags & NonNeg; } bool hasNoNaNs() const { return Flags & NoNaNs; } bool hasNoInfs() const { return Flags & NoInfs; } @@ -473,7 +477,7 @@ struct SDNodeFlags { }; LLVM_DECLARE_ENUM_AS_BITMASK(decltype(SDNodeFlags::None), - SDNodeFlags::Unpredictable); + SDNodeFlags::SameSign); inline SDNodeFlags operator|(SDNodeFlags LHS, SDNodeFlags RHS) { LHS |= RHS; diff --git a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp index 281d1578d0173..9c7085cc7e7a8 100644 --- a/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp @@ -1105,6 +1105,9 @@ EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned, if (Flags.hasDisjoint()) MI->setFlag(MachineInstr::MIFlag::Disjoint); + + if (Flags.hasSameSign()) + MI->setFlag(MachineInstr::MIFlag::SameSign); } // Emit all of the actual operands of this instruction, adding them to the diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 95125928cdc66..f41dbe81434c7 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -3652,6 +3652,10 @@ void SelectionDAGBuilder::visitICmp(const ICmpInst &I) { Op2 = DAG.getPtrExtOrTrunc(Op2, getCurSDLoc(), MemVT); } + SDNodeFlags Flags; + Flags.setSameSign(I.hasSameSign()); + SelectionDAG::FlagInserter FlagsInserter(DAG, Flags); + EVT DestVT = DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(), I.getType()); setValue(&I, DAG.getSetCC(getCurSDLoc(), DestVT, Op1, Op2, Opcode)); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp index 703efb7008974..580ff19065557 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp @@ -653,6 +653,9 @@ void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const { if (getFlags().hasDisjoint()) OS << " disjoint"; + if (getFlags().hasSameSign()) + OS << " samesign"; + if (getFlags().hasNonNeg()) OS << " nneg";