Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 16742ac

Browse files
committed
[DAGCombiner] visitSDIV - add special case handling for (sdiv X, 1) -> X in pow2 expansion
For divisor = 1, perform a select of X - reduces scalarisation of simple SDIVs git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@335727 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 823c169 commit 16742ac

File tree

2 files changed

+1422
-3546
lines changed

2 files changed

+1422
-3546
lines changed

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,12 +3048,6 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
30483048
auto IsPowerOfTwo = [](ConstantSDNode *C) {
30493049
if (C->isNullValue() || C->isOpaque())
30503050
return false;
3051-
// The instruction sequence to be generated contains shifting C by (op size
3052-
// in bits - # of trailing zeros in C), which results in an undef value when
3053-
// C == 1. (e.g. if the op size in bits is 32, it will be (sra x , 32) if C
3054-
// == 1)
3055-
if (C->getAPIntValue().isOneValue())
3056-
return false;
30573051
if (C->getAPIntValue().isAllOnesValue())
30583052
return false;
30593053
if (C->getAPIntValue().isMinSignedValue())
@@ -3100,14 +3094,16 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
31003094

31013095
// If dividing by a positive value, we're done. Otherwise, the result must
31023096
// be negated.
3103-
SDValue Sub =
3104-
DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), Sra);
3097+
SDValue Zero = DAG.getConstant(0, DL, VT);
3098+
SDValue Sub = DAG.getNode(ISD::SUB, DL, VT, Zero, Sra);
31053099

31063100
// FIXME: Use SELECT_CC once we improve SELECT_CC constant-folding.
31073101
SDValue Res = DAG.getSelect(
3108-
DL, VT,
3109-
DAG.getSetCC(DL, VT, N1, DAG.getConstant(0, DL, VT), ISD::SETLT), Sub,
3110-
Sra);
3102+
DL, VT, DAG.getSetCC(DL, VT, N1, Zero, ISD::SETLT), Sub, Sra);
3103+
// Special case: (sdiv X, 1) -> X
3104+
SDValue One = DAG.getConstant(1, DL, VT);
3105+
Res = DAG.getSelect(DL, VT, DAG.getSetCC(DL, VT, N1, One, ISD::SETEQ), N0,
3106+
Res);
31113107
return Res;
31123108
}
31133109

0 commit comments

Comments
 (0)