Skip to content

Commit f4e3daa

Browse files
authored
[DAG] Early exit for flags in canCreateUndefOrPoison [nfc] (llvm#89834)
This matches the style used in the Analysis version of this routine, and makes it less likely we'll miss a poison generating flag in future changes. Unlike IR, the check for poison generating flags doesn't need to switch over opcode since all nodes have the SDFlags storage.
1 parent 09cdfd6 commit f4e3daa

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,13 @@ END_TWO_BYTE_PACK()
999999
/// If Flags is not in a defined state then this has no effect.
10001000
void intersectFlagsWith(const SDNodeFlags Flags);
10011001

1002+
bool hasPoisonGeneratingFlags() const {
1003+
SDNodeFlags Flags = getFlags();
1004+
return Flags.hasNoUnsignedWrap() || Flags.hasNoSignedWrap() ||
1005+
Flags.hasExact() || Flags.hasDisjoint() || Flags.hasNonNeg() ||
1006+
Flags.hasNoNaNs() || Flags.hasNoInfs();
1007+
}
1008+
10021009
void setCFIType(uint32_t Type) { CFIType = Type; }
10031010
uint32_t getCFIType() const { return CFIType; }
10041011

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5128,6 +5128,9 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
51285128
if (VT.isScalableVector())
51295129
return true;
51305130

5131+
if (ConsiderFlags && Op->hasPoisonGeneratingFlags())
5132+
return true;
5133+
51315134
unsigned Opcode = Op.getOpcode();
51325135
switch (Opcode) {
51335136
case ISD::FREEZE:
@@ -5167,34 +5170,20 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts,
51675170
return true;
51685171

51695172
const TargetOptions &Options = getTarget().Options;
5170-
return Options.NoNaNsFPMath || Options.NoInfsFPMath ||
5171-
(ConsiderFlags &&
5172-
(Op->getFlags().hasNoNaNs() || Op->getFlags().hasNoInfs()));
5173+
return Options.NoNaNsFPMath || Options.NoInfsFPMath;
51735174
}
51745175

5175-
// Matches hasPoisonGeneratingFlags().
5176+
case ISD::OR:
51765177
case ISD::ZERO_EXTEND:
5177-
return ConsiderFlags && Op->getFlags().hasNonNeg();
5178-
51795178
case ISD::ADD:
51805179
case ISD::SUB:
51815180
case ISD::MUL:
5182-
// Matches hasPoisonGeneratingFlags().
5183-
return ConsiderFlags && (Op->getFlags().hasNoSignedWrap() ||
5184-
Op->getFlags().hasNoUnsignedWrap());
5181+
// No poison except from flags (which is handled above)
5182+
return false;
51855183

51865184
case ISD::SHL:
51875185
// If the max shift amount isn't in range, then the shift can create poison.
5188-
if (!getValidMaximumShiftAmountConstant(Op, DemandedElts))
5189-
return true;
5190-
5191-
// Matches hasPoisonGeneratingFlags().
5192-
return ConsiderFlags && (Op->getFlags().hasNoSignedWrap() ||
5193-
Op->getFlags().hasNoUnsignedWrap());
5194-
5195-
// Matches hasPoisonGeneratingFlags().
5196-
case ISD::OR:
5197-
return ConsiderFlags && Op->getFlags().hasDisjoint();
5186+
return !getValidMaximumShiftAmountConstant(Op, DemandedElts);
51985187

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

0 commit comments

Comments
 (0)