Skip to content

Commit 3e85bc4

Browse files
committed
Extract min<->max conversion into its own helper function
1 parent 55d7531 commit 3e85bc4

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,8 @@ inline bool isBitwiseLogicOp(unsigned Opcode) {
15061506
return Opcode == ISD::AND || Opcode == ISD::OR || Opcode == ISD::XOR;
15071507
}
15081508

1509+
NodeType getInverseMinMaxOpcode(unsigned MinMaxOpc);
1510+
15091511
/// Get underlying scalar opcode for VECREDUCE opcode.
15101512
/// For example ISD::AND for ISD::VECREDUCE_AND.
15111513
NodeType getVecReduceBaseOpcode(unsigned VecReduceOpcode);

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3962,23 +3962,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
39623962
m_UMax(m_Value(X), NegPat),
39633963
m_SMin(m_Value(X), NegPat),
39643964
m_UMin(m_Value(X), NegPat))))) {
3965-
unsigned NewOpc = 0;
3966-
switch (N1->getOpcode()) {
3967-
case ISD::SMAX:
3968-
NewOpc = ISD::SMIN;
3969-
break;
3970-
case ISD::UMAX:
3971-
NewOpc = ISD::UMIN;
3972-
break;
3973-
case ISD::SMIN:
3974-
NewOpc = ISD::SMAX;
3975-
break;
3976-
case ISD::UMIN:
3977-
NewOpc = ISD::UMAX;
3978-
break;
3979-
default:
3980-
llvm_unreachable("unrecognized opcode");
3981-
}
3965+
unsigned NewOpc = ISD::getInverseMinMaxOpcode(N1->getOpcode());
39823966
if (hasOperation(NewOpc, VT))
39833967
return DAG.getNode(NewOpc, DL, VT, X, S0);
39843968
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,21 @@ bool ISD::matchBinaryPredicate(
430430
return true;
431431
}
432432

433+
ISD::NodeType ISD::getInverseMinMaxOpcode(unsigned MinMaxOpc) {
434+
switch (MinMaxOpc) {
435+
default:
436+
llvm_unreachable("unrecognized opcode");
437+
case ISD::UMIN:
438+
return ISD::UMAX;
439+
case ISD::UMAX:
440+
return ISD::UMIN;
441+
case ISD::SMIN:
442+
return ISD::SMAX;
443+
case ISD::SMAX:
444+
return ISD::SMIN;
445+
}
446+
}
447+
433448
ISD::NodeType ISD::getVecReduceBaseOpcode(unsigned VecReduceOpcode) {
434449
switch (VecReduceOpcode) {
435450
default:

0 commit comments

Comments
 (0)