@@ -3741,13 +3741,14 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
3741
3741
SDLoc DL(N);
3742
3742
3743
3743
// fold (sdiv c1, c2) -> c1/c2
3744
- ConstantSDNode *N0C = isConstOrConstSplat(N0);
3745
3744
ConstantSDNode *N1C = isConstOrConstSplat(N1);
3746
- if (N0C && N1C && !N0C->isOpaque() && !N1C->isOpaque())
3747
- return DAG.FoldConstantArithmetic(ISD::SDIV, DL, VT, N0C, N1C);
3745
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::SDIV, DL, VT, {N0, N1}))
3746
+ return C;
3747
+
3748
3748
// fold (sdiv X, -1) -> 0-X
3749
3749
if (N1C && N1C->isAllOnesValue())
3750
3750
return DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), N0);
3751
+
3751
3752
// fold (sdiv X, MIN_SIGNED) -> select(X == MIN_SIGNED, 1, 0)
3752
3753
if (N1C && N1C->getAPIntValue().isMinSignedValue())
3753
3754
return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ),
@@ -3885,12 +3886,10 @@ SDValue DAGCombiner::visitUDIV(SDNode *N) {
3885
3886
SDLoc DL(N);
3886
3887
3887
3888
// fold (udiv c1, c2) -> c1/c2
3888
- ConstantSDNode *N0C = isConstOrConstSplat(N0);
3889
3889
ConstantSDNode *N1C = isConstOrConstSplat(N1);
3890
- if (N0C && N1C)
3891
- if (SDValue Folded = DAG.FoldConstantArithmetic(ISD::UDIV, DL, VT,
3892
- N0C, N1C))
3893
- return Folded;
3890
+ if (SDValue C = DAG.FoldConstantArithmetic(ISD::UDIV, DL, VT, {N0, N1}))
3891
+ return C;
3892
+
3894
3893
// fold (udiv X, -1) -> select(X == -1, 1, 0)
3895
3894
if (N1C && N1C->getAPIntValue().isAllOnesValue())
3896
3895
return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ),
@@ -3983,11 +3982,10 @@ SDValue DAGCombiner::visitREM(SDNode *N) {
3983
3982
SDLoc DL(N);
3984
3983
3985
3984
// fold (rem c1, c2) -> c1%c2
3986
- ConstantSDNode *N0C = isConstOrConstSplat(N0);
3987
3985
ConstantSDNode *N1C = isConstOrConstSplat(N1);
3988
- if (N0C && N1C )
3989
- if (SDValue Folded = DAG.FoldConstantArithmetic(Opcode, DL, VT, N0C, N1C))
3990
- return Folded;
3986
+ if (SDValue C = DAG.FoldConstantArithmetic(Opcode, DL, VT, {N0, N1}) )
3987
+ return C;
3988
+
3991
3989
// fold (urem X, -1) -> select(X == -1, 0, x)
3992
3990
if (!isSigned && N1C && N1C->getAPIntValue().isAllOnesValue())
3993
3991
return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ),
0 commit comments