Skip to content

Commit a967aa2

Browse files
committed
[DAGCombiner] ISD::SDIV/UDIV/SREM/UREM - use general SelectionDAG::FoldConstantArithmetic
This handles all the constant splat / opaque testing for us.
1 parent d242aa2 commit a967aa2

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3741,13 +3741,14 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
37413741
SDLoc DL(N);
37423742

37433743
// fold (sdiv c1, c2) -> c1/c2
3744-
ConstantSDNode *N0C = isConstOrConstSplat(N0);
37453744
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+
37483748
// fold (sdiv X, -1) -> 0-X
37493749
if (N1C && N1C->isAllOnesValue())
37503750
return DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), N0);
3751+
37513752
// fold (sdiv X, MIN_SIGNED) -> select(X == MIN_SIGNED, 1, 0)
37523753
if (N1C && N1C->getAPIntValue().isMinSignedValue())
37533754
return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ),
@@ -3885,12 +3886,10 @@ SDValue DAGCombiner::visitUDIV(SDNode *N) {
38853886
SDLoc DL(N);
38863887

38873888
// fold (udiv c1, c2) -> c1/c2
3888-
ConstantSDNode *N0C = isConstOrConstSplat(N0);
38893889
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+
38943893
// fold (udiv X, -1) -> select(X == -1, 1, 0)
38953894
if (N1C && N1C->getAPIntValue().isAllOnesValue())
38963895
return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ),
@@ -3983,11 +3982,10 @@ SDValue DAGCombiner::visitREM(SDNode *N) {
39833982
SDLoc DL(N);
39843983

39853984
// fold (rem c1, c2) -> c1%c2
3986-
ConstantSDNode *N0C = isConstOrConstSplat(N0);
39873985
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+
39913989
// fold (urem X, -1) -> select(X == -1, 0, x)
39923990
if (!isSigned && N1C && N1C->getAPIntValue().isAllOnesValue())
39933991
return DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, N0, N1, ISD::SETEQ),

0 commit comments

Comments
 (0)