Skip to content

Commit 130bbb6

Browse files
committed
[DAGCombiner] Move the transform from RISCVISelLowering
1 parent 75b5292 commit 130bbb6

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4251,6 +4251,19 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
42514251
sd_match(N1, m_UMaxLike(m_Specific(A), m_Specific(B))))
42524252
return DAG.getNegative(DAG.getNode(ISD::ABDU, DL, VT, A, B), DL, VT);
42534253

4254+
// (sub x, (select (ult x, y), 0, y)) -> (umin x, (sub x, y))
4255+
auto LK = TLI.getTypeConversion(*DAG.getContext(), VT);
4256+
if ((LK.first == TargetLoweringBase::TypeLegal ||
4257+
LK.first == TargetLoweringBase::TypePromoteInteger) &&
4258+
TLI.isOperationLegal(ISD::UMIN, LK.second)) {
4259+
SDValue Y;
4260+
if (sd_match(N1, m_OneUse(m_Select(m_SetCC(m_Specific(N0), m_Value(Y),
4261+
m_SpecificCondCode(ISD::SETULT)),
4262+
m_Zero(), m_Deferred(Y)))))
4263+
return DAG.getNode(ISD::UMIN, DL, VT, N0,
4264+
DAG.getNode(ISD::SUB, DL, VT, N0, Y));
4265+
}
4266+
42544267
return SDValue();
42554268
}
42564269

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14917,23 +14917,6 @@ static SDValue performSUBCombine(SDNode *N, SelectionDAG &DAG,
1491714917
if (SDValue V = combineSubShiftToOrcB(N, DAG, Subtarget))
1491814918
return V;
1491914919

14920-
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
14921-
auto LK = TLI.getTypeConversion(*DAG.getContext(), VT);
14922-
if ((LK.first == TargetLoweringBase::TypeLegal ||
14923-
LK.first == TargetLoweringBase::TypePromoteInteger) &&
14924-
TLI.isOperationLegal(ISD::UMIN, LK.second)) {
14925-
// fold (sub x, (select (ult x, y), 0, y)) -> (umin x, (sub x, y))
14926-
using namespace llvm::SDPatternMatch;
14927-
SDValue Y;
14928-
if (sd_match(N1, m_OneUse(m_Select(m_SetCC(m_Specific(N0), m_Value(Y),
14929-
m_SpecificCondCode(ISD::SETULT)),
14930-
m_Zero(), m_Deferred(Y))))) {
14931-
SDLoc DL(N);
14932-
return DAG.getNode(ISD::UMIN, DL, VT, N0,
14933-
DAG.getNode(ISD::SUB, DL, VT, N0, Y));
14934-
}
14935-
}
14936-
1493714920
// fold (sub x, (select lhs, rhs, cc, 0, y)) ->
1493814921
// (select lhs, rhs, cc, x, (sub x, y))
1493914922
return combineSelectAndUse(N, N1, N0, DAG, /*AllOnes*/ false, Subtarget);

0 commit comments

Comments
 (0)