Skip to content

Commit bbd57e1

Browse files
authored
[SelectionDAG] Add initial plumbing for the disjoint flag. (#76751)
This copies the flag from IR to the SDNode in SelectionDAGBuilder, clears the flag in SimplifyDemandedBits, and adds it to canCreateUndefOrPoison. Uses of the flag will come in later patches.
1 parent 923f6ac commit bbd57e1

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ struct SDNodeFlags {
381381
bool NoUnsignedWrap : 1;
382382
bool NoSignedWrap : 1;
383383
bool Exact : 1;
384+
bool Disjoint : 1;
384385
bool NonNeg : 1;
385386
bool NoNaNs : 1;
386387
bool NoInfs : 1;
@@ -402,10 +403,11 @@ struct SDNodeFlags {
402403
public:
403404
/// Default constructor turns off all optimization flags.
404405
SDNodeFlags()
405-
: NoUnsignedWrap(false), NoSignedWrap(false), Exact(false), NonNeg(false),
406-
NoNaNs(false), NoInfs(false), NoSignedZeros(false),
407-
AllowReciprocal(false), AllowContract(false), ApproximateFuncs(false),
408-
AllowReassociation(false), NoFPExcept(false), Unpredictable(false) {}
406+
: NoUnsignedWrap(false), NoSignedWrap(false), Exact(false),
407+
Disjoint(false), NonNeg(false), NoNaNs(false), NoInfs(false),
408+
NoSignedZeros(false), AllowReciprocal(false), AllowContract(false),
409+
ApproximateFuncs(false), AllowReassociation(false), NoFPExcept(false),
410+
Unpredictable(false) {}
409411

410412
/// Propagate the fast-math-flags from an IR FPMathOperator.
411413
void copyFMF(const FPMathOperator &FPMO) {
@@ -422,6 +424,7 @@ struct SDNodeFlags {
422424
void setNoUnsignedWrap(bool b) { NoUnsignedWrap = b; }
423425
void setNoSignedWrap(bool b) { NoSignedWrap = b; }
424426
void setExact(bool b) { Exact = b; }
427+
void setDisjoint(bool b) { Disjoint = b; }
425428
void setNonNeg(bool b) { NonNeg = b; }
426429
void setNoNaNs(bool b) { NoNaNs = b; }
427430
void setNoInfs(bool b) { NoInfs = b; }
@@ -437,6 +440,7 @@ struct SDNodeFlags {
437440
bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
438441
bool hasNoSignedWrap() const { return NoSignedWrap; }
439442
bool hasExact() const { return Exact; }
443+
bool hasDisjoint() const { return Disjoint; }
440444
bool hasNonNeg() const { return NonNeg; }
441445
bool hasNoNaNs() const { return NoNaNs; }
442446
bool hasNoInfs() const { return NoInfs; }
@@ -454,6 +458,7 @@ struct SDNodeFlags {
454458
NoUnsignedWrap &= Flags.NoUnsignedWrap;
455459
NoSignedWrap &= Flags.NoSignedWrap;
456460
Exact &= Flags.Exact;
461+
Disjoint &= Flags.Disjoint;
457462
NonNeg &= Flags.NonNeg;
458463
NoNaNs &= Flags.NoNaNs;
459464
NoInfs &= Flags.NoInfs;

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5022,7 +5022,6 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
50225022
case ISD::CONCAT_VECTORS:
50235023
case ISD::INSERT_SUBVECTOR:
50245024
case ISD::AND:
5025-
case ISD::OR:
50265025
case ISD::XOR:
50275026
case ISD::ROTL:
50285027
case ISD::ROTR:
@@ -5062,6 +5061,10 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
50625061
return ConsiderFlags && (Op->getFlags().hasNoSignedWrap() ||
50635062
Op->getFlags().hasNoUnsignedWrap());
50645063

5064+
// Matches hasPoisonGeneratingFlags().
5065+
case ISD::OR:
5066+
return ConsiderFlags && Op->getFlags().hasDisjoint();
5067+
50655068
case ISD::INSERT_VECTOR_ELT:{
50665069
// Ensure that the element index is in bounds.
50675070
EVT VecVT = Op.getOperand(0).getValueType();

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,8 @@ void SelectionDAGBuilder::visitBinary(const User &I, unsigned Opcode) {
33543354
}
33553355
if (auto *ExactOp = dyn_cast<PossiblyExactOperator>(&I))
33563356
Flags.setExact(ExactOp->isExact());
3357+
if (auto *DisjointOp = dyn_cast<PossiblyDisjointInst>(&I))
3358+
Flags.setDisjoint(DisjointOp->isDisjoint());
33573359
if (auto *FPOp = dyn_cast<FPMathOperator>(&I))
33583360
Flags.copyFMF(*FPOp);
33593361

llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
597597
if (getFlags().hasExact())
598598
OS << " exact";
599599

600+
if (getFlags().hasDisjoint())
601+
OS << " disjoint";
602+
600603
if (getFlags().hasNonNeg())
601604
OS << " nneg";
602605

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,14 +1468,24 @@ bool TargetLowering::SimplifyDemandedBits(
14681468
case ISD::OR: {
14691469
SDValue Op0 = Op.getOperand(0);
14701470
SDValue Op1 = Op.getOperand(1);
1471-
1471+
SDNodeFlags Flags = Op.getNode()->getFlags();
14721472
if (SimplifyDemandedBits(Op1, DemandedBits, DemandedElts, Known, TLO,
1473-
Depth + 1))
1473+
Depth + 1)) {
1474+
if (Flags.hasDisjoint()) {
1475+
Flags.setDisjoint(false);
1476+
Op->setFlags(Flags);
1477+
}
14741478
return true;
1479+
}
14751480
assert(!Known.hasConflict() && "Bits known to be one AND zero?");
14761481
if (SimplifyDemandedBits(Op0, ~Known.One & DemandedBits, DemandedElts,
1477-
Known2, TLO, Depth + 1))
1482+
Known2, TLO, Depth + 1)) {
1483+
if (Flags.hasDisjoint()) {
1484+
Flags.setDisjoint(false);
1485+
Op->setFlags(Flags);
1486+
}
14781487
return true;
1488+
}
14791489
assert(!Known2.hasConflict() && "Bits known to be one AND zero?");
14801490

14811491
// If all of the demanded bits are known zero on one side, return the other.

0 commit comments

Comments
 (0)