Skip to content

Commit 1abcdc3

Browse files
committed
Address review comments
Preserve the flags from the first sub
1 parent 25c43d8 commit 1abcdc3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3953,14 +3953,16 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
39533953
// (sub 0, (max X, (sub 0, X))) --> (min X, (sub 0, X))
39543954
// Note that this is applicable to both signed and unsigned min/max.
39553955
SDValue X;
3956+
SDValue S0;
39563957
if (LegalOperations &&
3957-
sd_match(N1,
3958-
m_OneUse(m_AnyOf(m_SMax(m_Value(X), m_Neg(m_Deferred(X))),
3959-
m_UMax(m_Value(X), m_Neg(m_Deferred(X))))))) {
3958+
sd_match(N1, m_OneUse(m_AnyOf(
3959+
m_SMax(m_Value(X),
3960+
m_AllOf(m_Neg(m_Deferred(X)), m_Value(S0))),
3961+
m_UMax(m_Value(X), m_AllOf(m_Neg(m_Deferred(X)),
3962+
m_Value(S0))))))) {
39603963
unsigned MinOpc = N1->getOpcode() == ISD::SMAX ? ISD::SMIN : ISD::UMIN;
39613964
if (hasOperation(MinOpc, VT))
3962-
return DAG.getNode(MinOpc, DL, VT, X,
3963-
DAG.getNode(ISD::SUB, DL, VT, N0, X));
3965+
return DAG.getNode(MinOpc, DL, VT, X, S0);
39643966
}
39653967

39663968
// Fold neg(splat(neg(x)) -> splat(x)

0 commit comments

Comments
 (0)