Skip to content

Commit 19c8475

Browse files
[SelectionDAG] Add preliminary plumbing for samesign flag
Extend recently-added poison-generating IR flag to codegen as well.
1 parent e3222e6 commit 19c8475

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ class MachineIRBuilder {
12671267
/// \return a MachineInstrBuilder for the newly created instruction.
12681268
MachineInstrBuilder buildICmp(CmpInst::Predicate Pred, const DstOp &Res,
12691269
const SrcOp &Op0, const SrcOp &Op1,
1270-
std::optional<unsigned> Flgs = std::nullopt);
1270+
std::optional<unsigned> Flags = std::nullopt);
12711271

12721272
/// Build and insert a \p Res = G_FCMP \p Pred\p Op0, \p Op1
12731273
///

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,14 @@ struct SDNodeFlags {
411411
NoFPExcept = 1 << 12,
412412
// Instructions with attached 'unpredictable' metadata on IR level.
413413
Unpredictable = 1 << 13,
414+
// Compare instructions which may carry the samesign flag.
415+
SameSign = 1 << 14,
414416

415417
// NOTE: Please update LargestValue in LLVM_DECLARE_ENUM_AS_BITMASK below
416418
// the class definition when adding new flags.
417419

418420
PoisonGeneratingFlags = NoUnsignedWrap | NoSignedWrap | Exact | Disjoint |
419-
NonNeg | NoNaNs | NoInfs,
421+
NonNeg | NoNaNs | NoInfs | SameSign,
420422
};
421423

422424
/// Default constructor turns off all optimization flags.
@@ -438,6 +440,7 @@ struct SDNodeFlags {
438440
void setNoSignedWrap(bool b) { setFlag<NoSignedWrap>(b); }
439441
void setExact(bool b) { setFlag<Exact>(b); }
440442
void setDisjoint(bool b) { setFlag<Disjoint>(b); }
443+
void setSameSign(bool b) { setFlag<SameSign>(b); }
441444
void setNonNeg(bool b) { setFlag<NonNeg>(b); }
442445
void setNoNaNs(bool b) { setFlag<NoNaNs>(b); }
443446
void setNoInfs(bool b) { setFlag<NoInfs>(b); }
@@ -454,6 +457,7 @@ struct SDNodeFlags {
454457
bool hasNoSignedWrap() const { return Flags & NoSignedWrap; }
455458
bool hasExact() const { return Flags & Exact; }
456459
bool hasDisjoint() const { return Flags & Disjoint; }
460+
bool hasSameSign() const { return Flags & SameSign; }
457461
bool hasNonNeg() const { return Flags & NonNeg; }
458462
bool hasNoNaNs() const { return Flags & NoNaNs; }
459463
bool hasNoInfs() const { return Flags & NoInfs; }
@@ -473,7 +477,7 @@ struct SDNodeFlags {
473477
};
474478

475479
LLVM_DECLARE_ENUM_AS_BITMASK(decltype(SDNodeFlags::None),
476-
SDNodeFlags::Unpredictable);
480+
SDNodeFlags::SameSign);
477481

478482
inline SDNodeFlags operator|(SDNodeFlags LHS, SDNodeFlags RHS) {
479483
LHS |= RHS;

llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,9 @@ EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned,
11051105

11061106
if (Flags.hasDisjoint())
11071107
MI->setFlag(MachineInstr::MIFlag::Disjoint);
1108+
1109+
if (Flags.hasSameSign())
1110+
MI->setFlag(MachineInstr::MIFlag::SameSign);
11081111
}
11091112

11101113
// Emit all of the actual operands of this instruction, adding them to the

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3652,6 +3652,10 @@ void SelectionDAGBuilder::visitICmp(const ICmpInst &I) {
36523652
Op2 = DAG.getPtrExtOrTrunc(Op2, getCurSDLoc(), MemVT);
36533653
}
36543654

3655+
SDNodeFlags Flags;
3656+
Flags.setSameSign(I.hasSameSign());
3657+
SelectionDAG::FlagInserter FlagsInserter(DAG, Flags);
3658+
36553659
EVT DestVT = DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
36563660
I.getType());
36573661
setValue(&I, DAG.getSetCC(getCurSDLoc(), DestVT, Op1, Op2, Opcode));

llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,9 @@ void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
653653
if (getFlags().hasDisjoint())
654654
OS << " disjoint";
655655

656+
if (getFlags().hasSameSign())
657+
OS << " samesign";
658+
656659
if (getFlags().hasNonNeg())
657660
OS << " nneg";
658661

0 commit comments

Comments
 (0)