Skip to content

[DAG] Early exit for flags in canCreateUndefOrPoison [nfc] #89834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/include/llvm/CodeGen/SelectionDAGNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,13 @@ END_TWO_BYTE_PACK()
/// If Flags is not in a defined state then this has no effect.
void intersectFlagsWith(const SDNodeFlags Flags);

bool hasPoisonGeneratingFlags() const {
SDNodeFlags Flags = getFlags();
return Flags.hasNoUnsignedWrap() || Flags.hasNoSignedWrap() ||
Flags.hasExact() || Flags.hasDisjoint() || Flags.hasNonNeg() ||
Flags.hasNoNaNs() || Flags.hasNoInfs();
}

void setCFIType(uint32_t Type) { CFIType = Type; }
uint32_t getCFIType() const { return CFIType; }

Expand Down
27 changes: 8 additions & 19 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5095,6 +5095,9 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
if (VT.isScalableVector())
return true;

if (ConsiderFlags && Op->hasPoisonGeneratingFlags())
return true;

unsigned Opcode = Op.getOpcode();
switch (Opcode) {
case ISD::FREEZE:
Expand Down Expand Up @@ -5134,34 +5137,20 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
return true;

const TargetOptions &Options = getTarget().Options;
return Options.NoNaNsFPMath || Options.NoInfsFPMath ||
(ConsiderFlags &&
(Op->getFlags().hasNoNaNs() || Op->getFlags().hasNoInfs()));
return Options.NoNaNsFPMath || Options.NoInfsFPMath;
}

// Matches hasPoisonGeneratingFlags().
case ISD::OR:
case ISD::ZERO_EXTEND:
return ConsiderFlags && Op->getFlags().hasNonNeg();

case ISD::ADD:
case ISD::SUB:
case ISD::MUL:
// Matches hasPoisonGeneratingFlags().
return ConsiderFlags && (Op->getFlags().hasNoSignedWrap() ||
Op->getFlags().hasNoUnsignedWrap());
// No poison except from flags (which is handled above)
return false;

case ISD::SHL:
// If the max shift amount isn't in range, then the shift can create poison.
if (!getValidMaximumShiftAmountConstant(Op, DemandedElts))
return true;

// Matches hasPoisonGeneratingFlags().
return ConsiderFlags && (Op->getFlags().hasNoSignedWrap() ||
Op->getFlags().hasNoUnsignedWrap());

// Matches hasPoisonGeneratingFlags().
case ISD::OR:
return ConsiderFlags && Op->getFlags().hasDisjoint();
return !getValidMaximumShiftAmountConstant(Op, DemandedElts);

case ISD::SCALAR_TO_VECTOR:
// Check if we demand any upper (undef) elements.
Expand Down