Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit df7e862

Browse files
committed
[DAG] Refactor ReassociateOps - no functional change intended.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199146 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent bf2609e commit df7e862

File tree

1 file changed

+44
-73
lines changed

1 file changed

+44
-73
lines changed

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 44 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -607,87 +607,58 @@ static bool isOneUseSetCC(SDValue N) {
607607
return false;
608608
}
609609

610+
// \brief Returns the SDNode if it is a constant BuildVector or constant int.
611+
static SDNode *isConstantBuildVectorOrConstantInt(SDValue N) {
612+
if (isa<ConstantSDNode>(N))
613+
return N.getNode();
614+
BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N);
615+
if(BV && BV->isConstant())
616+
return BV;
617+
return NULL;
618+
}
619+
610620
SDValue DAGCombiner::ReassociateOps(unsigned Opc, SDLoc DL,
611621
SDValue N0, SDValue N1) {
612622
EVT VT = N0.getValueType();
613-
if (VT.isVector()) {
614-
if (N0.getOpcode() == Opc) {
615-
BuildVectorSDNode *L = dyn_cast<BuildVectorSDNode>(N0.getOperand(1));
616-
if(L && L->isConstant()) {
617-
BuildVectorSDNode *R = dyn_cast<BuildVectorSDNode>(N1);
618-
if (R && R->isConstant()) {
619-
// reassoc. (op (op x, c1), c2) -> (op x, (op c1, c2))
620-
SDValue OpNode = DAG.FoldConstantArithmetic(Opc, VT, L, R);
621-
return DAG.getNode(Opc, DL, VT, N0.getOperand(0), OpNode);
622-
}
623-
624-
if (N0.hasOneUse()) {
625-
// reassoc. (op (op x, c1), y) -> (op (op x, y), c1) iff x+c1 has one
626-
// use
627-
SDValue OpNode = DAG.getNode(Opc, SDLoc(N0), VT,
628-
N0.getOperand(0), N1);
629-
AddToWorkList(OpNode.getNode());
630-
return DAG.getNode(Opc, DL, VT, OpNode, N0.getOperand(1));
631-
}
623+
if (N0.getOpcode() == Opc) {
624+
if (SDNode *L = isConstantBuildVectorOrConstantInt(N0.getOperand(1))) {
625+
if (SDNode *R = isConstantBuildVectorOrConstantInt(N1)) {
626+
// reassoc. (op (op x, c1), c2) -> (op x, (op c1, c2))
627+
SDValue OpNode = DAG.FoldConstantArithmetic(Opc, VT, L, R);
628+
if (!OpNode.getNode())
629+
return SDValue();
630+
return DAG.getNode(Opc, DL, VT, N0.getOperand(0), OpNode);
632631
}
633-
}
634-
635-
if (N1.getOpcode() == Opc) {
636-
BuildVectorSDNode *R = dyn_cast<BuildVectorSDNode>(N1.getOperand(1));
637-
if (R && R->isConstant()) {
638-
BuildVectorSDNode *L = dyn_cast<BuildVectorSDNode>(N0);
639-
if (L && L->isConstant()) {
640-
// reassoc. (op c2, (op x, c1)) -> (op x, (op c1, c2))
641-
SDValue OpNode = DAG.FoldConstantArithmetic(Opc, VT, R, L);
642-
return DAG.getNode(Opc, DL, VT, N1.getOperand(0), OpNode);
643-
}
644-
if (N1.hasOneUse()) {
645-
// reassoc. (op y, (op x, c1)) -> (op (op x, y), c1) iff x+c1 has one
646-
// use
647-
SDValue OpNode = DAG.getNode(Opc, SDLoc(N0), VT,
648-
N1.getOperand(0), N0);
649-
AddToWorkList(OpNode.getNode());
650-
return DAG.getNode(Opc, DL, VT, OpNode, N1.getOperand(1));
651-
}
632+
if (N0.hasOneUse()) {
633+
// reassoc. (op (op x, c1), y) -> (op (op x, y), c1) iff x+c1 has one
634+
// use
635+
SDValue OpNode = DAG.getNode(Opc, SDLoc(N0), VT, N0.getOperand(0), N1);
636+
if (!OpNode.getNode())
637+
return SDValue();
638+
AddToWorkList(OpNode.getNode());
639+
return DAG.getNode(Opc, DL, VT, OpNode, N0.getOperand(1));
652640
}
653641
}
654-
655-
return SDValue();
656642
}
657643

658-
if (N0.getOpcode() == Opc && isa<ConstantSDNode>(N0.getOperand(1))) {
659-
if (isa<ConstantSDNode>(N1)) {
660-
// reassoc. (op (op x, c1), c2) -> (op x, (op c1, c2))
661-
SDValue OpNode =
662-
DAG.FoldConstantArithmetic(Opc, VT,
663-
cast<ConstantSDNode>(N0.getOperand(1)),
664-
cast<ConstantSDNode>(N1));
665-
return DAG.getNode(Opc, DL, VT, N0.getOperand(0), OpNode);
666-
}
667-
if (N0.hasOneUse()) {
668-
// reassoc. (op (op x, c1), y) -> (op (op x, y), c1) iff x+c1 has one use
669-
SDValue OpNode = DAG.getNode(Opc, SDLoc(N0), VT,
670-
N0.getOperand(0), N1);
671-
AddToWorkList(OpNode.getNode());
672-
return DAG.getNode(Opc, DL, VT, OpNode, N0.getOperand(1));
673-
}
674-
}
675-
676-
if (N1.getOpcode() == Opc && isa<ConstantSDNode>(N1.getOperand(1))) {
677-
if (isa<ConstantSDNode>(N0)) {
678-
// reassoc. (op c2, (op x, c1)) -> (op x, (op c1, c2))
679-
SDValue OpNode =
680-
DAG.FoldConstantArithmetic(Opc, VT,
681-
cast<ConstantSDNode>(N1.getOperand(1)),
682-
cast<ConstantSDNode>(N0));
683-
return DAG.getNode(Opc, DL, VT, N1.getOperand(0), OpNode);
684-
}
685-
if (N1.hasOneUse()) {
686-
// reassoc. (op y, (op x, c1)) -> (op (op x, y), c1) iff x+c1 has one use
687-
SDValue OpNode = DAG.getNode(Opc, SDLoc(N0), VT,
688-
N1.getOperand(0), N0);
689-
AddToWorkList(OpNode.getNode());
690-
return DAG.getNode(Opc, DL, VT, OpNode, N1.getOperand(1));
644+
if (N1.getOpcode() == Opc) {
645+
if (SDNode *R = isConstantBuildVectorOrConstantInt(N1.getOperand(1))) {
646+
if (SDNode *L = isConstantBuildVectorOrConstantInt(N0)) {
647+
// reassoc. (op c2, (op x, c1)) -> (op x, (op c1, c2))
648+
SDValue OpNode = DAG.FoldConstantArithmetic(Opc, VT, R, L);
649+
if (!OpNode.getNode())
650+
return SDValue();
651+
return DAG.getNode(Opc, DL, VT, N1.getOperand(0), OpNode);
652+
}
653+
if (N1.hasOneUse()) {
654+
// reassoc. (op y, (op x, c1)) -> (op (op x, y), c1) iff x+c1 has one
655+
// use
656+
SDValue OpNode = DAG.getNode(Opc, SDLoc(N0), VT, N1.getOperand(0), N0);
657+
if (!OpNode.getNode())
658+
return SDValue();
659+
AddToWorkList(OpNode.getNode());
660+
return DAG.getNode(Opc, DL, VT, OpNode, N1.getOperand(1));
661+
}
691662
}
692663
}
693664

0 commit comments

Comments
 (0)