[llvm] f4e3daa - [DAG] Early exit for flags in canCreateUndefOrPoison [nfc] (#89834)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 25 09:13:03 PDT 2024
Author: Philip Reames
Date: 2024-04-25T09:12:59-07:00
New Revision: f4e3daa562ce077c729634bd3ae8757aae8d46ef
URL: https://github.com/llvm/llvm-project/commit/f4e3daa562ce077c729634bd3ae8757aae8d46ef
DIFF: https://github.com/llvm/llvm-project/commit/f4e3daa562ce077c729634bd3ae8757aae8d46ef.diff
LOG: [DAG] Early exit for flags in canCreateUndefOrPoison [nfc] (#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.
Added:
Modified:
llvm/include/llvm/CodeGen/SelectionDAGNodes.h
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index 70d6b09a0c895c..e7c71041454557 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -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; }
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 5b7d6376d7d75b..224c0c5ee9706c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5128,6 +5128,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:
@@ -5167,34 +5170,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.
More information about the llvm-commits
mailing list