Skip to content

Commit e4fa2e3

Browse files
authored
[DAG] isGuaranteedNotToBeUndefOrPoisonForTargetNode - add fallback implementation (#86125)
Allow targets to rely on TargetLowering::isGuaranteedNotToBeUndefOrPoisonForTargetNode to test nodes for canCreateUndefOrPoisonForTargetNode + all arguments are isGuaranteedNotToBeUndefOrPoison. Targets can still perform this themselves for specific special case nodes (e.g. target shuffles). Matches the fallback in SelectionDAG::isGuaranteedNotToBeUndefOrPoison
1 parent 8d7a6e2 commit e4fa2e3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5042,8 +5042,9 @@ bool SelectionDAG::isGuaranteedNotToBeUndefOrPoison(SDValue Op,
50425042

50435043
// If Op can't create undef/poison and none of its operands are undef/poison
50445044
// then Op is never undef/poison.
5045-
// NOTE: TargetNodes should handle this in themselves in
5046-
// isGuaranteedNotToBeUndefOrPoisonForTargetNode.
5045+
// NOTE: TargetNodes can handle this in themselves in
5046+
// isGuaranteedNotToBeUndefOrPoisonForTargetNode or let
5047+
// TargetLowering::isGuaranteedNotToBeUndefOrPoisonForTargetNode handle it.
50475048
return !canCreateUndefOrPoison(Op, PoisonOnly, /*ConsiderFlags*/ true,
50485049
Depth) &&
50495050
all_of(Op->ops(), [&](SDValue V) {

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3786,7 +3786,15 @@ bool TargetLowering::isGuaranteedNotToBeUndefOrPoisonForTargetNode(
37863786
Op.getOpcode() == ISD::INTRINSIC_VOID) &&
37873787
"Should use isGuaranteedNotToBeUndefOrPoison if you don't know whether Op"
37883788
" is a target node!");
3789-
return false;
3789+
3790+
// If Op can't create undef/poison and none of its operands are undef/poison
3791+
// then Op is never undef/poison.
3792+
return !canCreateUndefOrPoisonForTargetNode(Op, DemandedElts, DAG, PoisonOnly,
3793+
/*ConsiderFlags*/ true, Depth) &&
3794+
all_of(Op->ops(), [&](SDValue V) {
3795+
return DAG.isGuaranteedNotToBeUndefOrPoison(V, PoisonOnly,
3796+
Depth + 1);
3797+
});
37903798
}
37913799

37923800
bool TargetLowering::canCreateUndefOrPoisonForTargetNode(

0 commit comments

Comments
 (0)