diff options
| author | Björn Pettersson <bjorn.a.pettersson@ericsson.com> | 2024-04-29 07:56:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-29 07:56:49 +0200 |
| commit | b3c55b707110084a9f50a16aade34c3be6fa18da (patch) | |
| tree | 12d02b86f874407e3cb1708220f87040064b6e9c /llvm/lib/CodeGen | |
| parent | 6cd6bde3090a405e4091ef6f743cb2e56b376a55 (diff) | |
| download | llvm-b3c55b707110084a9f50a16aade34c3be6fa18da.tar.gz llvm-b3c55b707110084a9f50a16aade34c3be6fa18da.tar.bz2 llvm-b3c55b707110084a9f50a16aade34c3be6fa18da.zip | |
[SelectionDAG] Handle more opcodes in canCreateUndefOrPoison (#84921)
[SelectionDAG] Handle more opcodes in canCreateUndefOrPoison
Handle SELECT_CC similarly as SETCC.
Handle these operations that only propagate poison/undef based on the
input operands:
SADDSAT, UADDSAT, SSUBSAT, USUBSAT, MULHU, MULHS,
SMIN, SMAX, UMIN, UMAX
These operations may create poison based on shift amount and exact
flag being violated:
SRL, SRA
One goal here is to allow pushing freeze through these operations
when allowed, as well as letting analyses such as
isGuaranteedNotToBeUndefOrPoison to not break on such operations.
Since some problems have been observed with pushing freeze through
SRA/SRL we block that explicitly in DAGCombiner::visitFreeze now.
That way we can still model SRA/SRL properly in
SelectionDAG::canCreateUndefOrPoison, e.g. when used by
isGuaranteedNotToBeUndefOrPoison, even if we do not want to push
freeze through those instructions.
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 16 |
2 files changed, 21 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index b6d5b309ceb9..326a004d06f2 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -15459,6 +15459,12 @@ SDValue DAGCombiner::visitFREEZE(SDNode *N) { if (DAG.isGuaranteedNotToBeUndefOrPoison(N0, /*PoisonOnly*/ false)) return N0; + // We currently avoid folding freeze over SRA/SRL, due to the problems seen + // with (freeze (assert ext)) blocking simplifications of SRA/SRL. See for + // example https://reviews.llvm.org/D136529#4120959. + if (N0.getOpcode() == ISD::SRA || N0.getOpcode() == ISD::SRL) + return SDValue(); + // Fold freeze(op(x, ...)) -> op(freeze(x), ...). // Try to push freeze through instructions that propagate but don't produce // poison as far as possible. If an operand of freeze follows three diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index dde10fd4b8c8..dfbfaa8c894f 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5137,6 +5137,16 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts, case ISD::FREEZE: case ISD::CONCAT_VECTORS: case ISD::INSERT_SUBVECTOR: + case ISD::SADDSAT: + case ISD::UADDSAT: + case ISD::SSUBSAT: + case ISD::USUBSAT: + case ISD::MULHU: + case ISD::MULHS: + case ISD::SMIN: + case ISD::SMAX: + case ISD::UMIN: + case ISD::UMAX: case ISD::AND: case ISD::XOR: case ISD::ROTL: @@ -5157,6 +5167,7 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts, case ISD::BUILD_PAIR: return false; + case ISD::SELECT_CC: case ISD::SETCC: { // Integer setcc cannot create undef or poison. if (Op.getOperand(0).getValueType().isInteger()) @@ -5166,7 +5177,8 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts, // based on options and flags. The options and flags also cause special // nonan condition codes to be used. Those condition codes may be preserved // even if the nonan flag is dropped somewhere. - ISD::CondCode CCCode = cast<CondCodeSDNode>(Op.getOperand(2))->get(); + unsigned CCOp = Opcode == ISD::SETCC ? 2 : 4; + ISD::CondCode CCCode = cast<CondCodeSDNode>(Op.getOperand(CCOp))->get(); if (((unsigned)CCCode & 0x10U)) return true; @@ -5183,6 +5195,8 @@ bool SelectionDAG::canCreateUndefOrPoison(SDValue Op, const APInt &DemandedElts, return false; case ISD::SHL: + case ISD::SRL: + case ISD::SRA: // If the max shift amount isn't in range, then the shift can create poison. return !getValidMaximumShiftAmountConstant(Op, DemandedElts); |
