llvm.org GIT mirror llvm / 1223276
DAGCombiner: simplify by using condition variables; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225836 91177308-0d34-0410-b5e6-96231b3b80d8 Matthias Braun 5 years ago
2 changed file(s) with 15 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
737737 if (SDNode *L = isConstantBuildVectorOrConstantInt(N0.getOperand(1))) {
738738 if (SDNode *R = isConstantBuildVectorOrConstantInt(N1)) {
739739 // reassoc. (op (op x, c1), c2) -> (op x, (op c1, c2))
740 SDValue OpNode = DAG.FoldConstantArithmetic(Opc, VT, L, R);
741 if (!OpNode.getNode())
742 return SDValue();
743 return DAG.getNode(Opc, DL, VT, N0.getOperand(0), OpNode);
740 if (SDValue OpNode = DAG.FoldConstantArithmetic(Opc, VT, L, R))
741 return DAG.getNode(Opc, DL, VT, N0.getOperand(0), OpNode);
742 return SDValue();
744743 }
745744 if (N0.hasOneUse()) {
746745 // reassoc. (op (op x, c1), y) -> (op (op x, y), c1) iff x+c1 has one
758757 if (SDNode *R = isConstantBuildVectorOrConstantInt(N1.getOperand(1))) {
759758 if (SDNode *L = isConstantBuildVectorOrConstantInt(N0)) {
760759 // reassoc. (op c2, (op x, c1)) -> (op x, (op c1, c2))
761 SDValue OpNode = DAG.FoldConstantArithmetic(Opc, VT, R, L);
762 if (!OpNode.getNode())
763 return SDValue();
764 return DAG.getNode(Opc, DL, VT, N1.getOperand(0), OpNode);
760 if (SDValue OpNode = DAG.FoldConstantArithmetic(Opc, VT, R, L))
761 return DAG.getNode(Opc, DL, VT, N1.getOperand(0), OpNode);
762 return SDValue();
765763 }
766764 if (N1.hasOneUse()) {
767765 // reassoc. (op y, (op x, c1)) -> (op (op x, y), c1) iff x+c1 has one
34483446 isa(N0.getOperand(1))) {
34493447 ConstantSDNode *C1 = cast(N0.getOperand(1));
34503448 if ((C1->getAPIntValue() & N1C->getAPIntValue()) != 0) {
3451 SDValue COR = DAG.FoldConstantArithmetic(ISD::OR, VT, N1C, C1);
3452 if (!COR.getNode())
3453 return SDValue();
3454 return DAG.getNode(ISD::AND, SDLoc(N), VT,
3455 DAG.getNode(ISD::OR, SDLoc(N0), VT,
3456 N0.getOperand(0), N1), COR);
3449 if (SDValue COR = DAG.FoldConstantArithmetic(ISD::OR, VT, N1C, C1))
3450 return DAG.getNode(
3451 ISD::AND, SDLoc(N), VT,
3452 DAG.getNode(ISD::OR, SDLoc(N0), VT, N0.getOperand(0), N1), COR);
3453 return SDValue();
34573454 }
34583455 }
34593456 // fold (or (setcc x), (setcc y)) -> (setcc (or x, y))
40694066 if (N01CV && N01CV->isConstant() && N00.getOpcode() == ISD::SETCC &&
40704067 TLI.getBooleanContents(N00.getOperand(0).getValueType()) ==
40714068 TargetLowering::ZeroOrNegativeOneBooleanContent) {
4072 SDValue C = DAG.FoldConstantArithmetic(ISD::SHL, VT, N01CV, N1CV);
4073 if (C.getNode())
4069 if (SDValue C = DAG.FoldConstantArithmetic(ISD::SHL, VT, N01CV, N1CV))
40744070 return DAG.getNode(ISD::AND, SDLoc(N), VT, N00, C);
40754071 }
40764072 } else {
33823382 }
33833383
33843384 // Perform trivial constant folding.
3385 SDValue SV = FoldConstantArithmetic(Opcode, VT, N1.getNode(), N2.getNode());
3386 if (SV.getNode()) return SV;
3385 if (SDValue SV =
3386 FoldConstantArithmetic(Opcode, VT, N1.getNode(), N2.getNode()))
3387 return SV;
33873388
33883389 // Canonicalize constant to RHS if commutative.
33893390 if (N1C && !N2C && isCommutativeBinOp(Opcode)) {