llvm.org GIT mirror llvm / ba36cb5
erect abstraction boundaries for accessing SDValue members, rename Val -> Node to reflect semantics git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55504 91177308-0d34-0410-b5e6-96231b3b80d8 Gabor Greif 11 years ago
39 changed file(s) with 1205 addition(s) and 1192 deletion(s). Raw diff Collapse all Expand all
3636 else if (Chain->getNumOperands() > 0) {
3737 SDValue C0 = Chain->getOperand(0);
3838 if (C0.getValueType() == MVT::Other)
39 return C0.Val != Op && IsChainCompatible(C0.Val, Op);
39 return C0.getNode() != Op && IsChainCompatible(C0.getNode(), Op);
4040 }
4141 return true;
4242 }
7575 /// AddToISelQueue - adds a node to the instruction
7676 /// selection queue.
7777 void AddToISelQueue(SDValue N) DISABLE_INLINE {
78 int Id = N.Val->getNodeId();
78 int Id = N.getNode()->getNodeId();
7979 if (Id != -1 && !isQueued(Id)) {
80 ISelQueue.push_back(N.Val);
80 ISelQueue.push_back(N.getNode());
8181 std::push_heap(ISelQueue.begin(), ISelQueue.end(), isel_sort());
8282 setQueued(Id);
8383 }
119119 void ReplaceUses(SDValue F, SDValue T) DISABLE_INLINE {
120120 ISelQueueUpdater ISQU(ISelQueue);
121121 CurDAG->ReplaceAllUsesOfValueWith(F, T, &ISQU);
122 setSelected(F.Val->getNodeId());
122 setSelected(F.getNode()->getNodeId());
123123 UpdateQueue(ISQU);
124124 }
125125
130130 ISelQueueUpdater ISQU(ISelQueue);
131131 CurDAG->ReplaceAllUsesOfValuesWith(F, T, Num, &ISQU);
132132 for (unsigned i = 0; i != Num; ++i)
133 setSelected(F[i].Val->getNodeId());
133 setSelected(F[i].getNode()->getNodeId());
134134 UpdateQueue(ISQU);
135135 }
136136
164164 // a reference to the root node, preventing it from being deleted,
165165 // and tracking any changes of the root.
166166 HandleSDNode Dummy(CurDAG->getRoot());
167 ISelQueue.push_back(CurDAG->getRoot().Val);
167 ISelQueue.push_back(CurDAG->getRoot().getNode());
168168
169169 // Select pending nodes from the instruction selection queue
170170 // until no more nodes are left for selection.
169169 /// setRoot - Set the current root tag of the SelectionDAG.
170170 ///
171171 const SDValue &setRoot(SDValue N) {
172 assert((!N.Val || N.getValueType() == MVT::Other) &&
172 assert((!N.getNode() || N.getValueType() == MVT::Other) &&
173173 "DAG root value is not a chain!");
174174 return Root = N;
175175 }
294294 SDValue Flag) {
295295 const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
296296 SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
297 return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
297 return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.getNode() ? 4 : 3);
298298 }
299299
300300 // Similar to last getCopyToReg() except parameter Reg is a SDValue
302302 SDValue Flag) {
303303 const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
304304 SDValue Ops[] = { Chain, Reg, N, Flag };
305 return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
305 return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.getNode() ? 4 : 3);
306306 }
307307
308308 SDValue getCopyFromReg(SDValue Chain, unsigned Reg, MVT VT) {
318318 SDValue Flag) {
319319 const MVT *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag);
320320 SDValue Ops[] = { Chain, getRegister(Reg, VT), Flag };
321 return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.Val ? 3 : 2);
321 return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.getNode() ? 3 : 2);
322322 }
323323
324324 SDValue getCondCode(ISD::CondCode Cond);
346346 Ops.push_back(Op2);
347347 Ops.push_back(InFlag);
348348 return getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0],
349 (unsigned)Ops.size() - (InFlag.Val == 0 ? 1 : 0));
349 (unsigned)Ops.size() - (InFlag.getNode() == 0 ? 1 : 0));
350350 }
351351
352352 /// getNode - Gets or creates the specified node.
836836 /// of information is represented with the SDValue value type.
837837 ///
838838 class SDValue {
839 public:
840 SDNode *Val; // The node defining the value we are using.
841 private:
839 SDNode *Node; // The node defining the value we are using.
842840 unsigned ResNo; // Which return value of the node we are using.
843841 public:
844 SDValue() : Val(0), ResNo(0) {}
845 SDValue(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
842 SDValue() : Node(0), ResNo(0) {}
843 SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
846844
847845 /// get the index which selects a specific result in the SDNode
848846 unsigned getResNo() const { return ResNo; }
849847
848 /// get the SDNode which holds the desired result
849 SDNode *getNode() const { return Node; }
850
851 /// set the SDNode
852 void setNode(SDNode *N) { Node = N; }
853
850854 bool operator==(const SDValue &O) const {
851 return Val == O.Val && ResNo == O.ResNo;
855 return Node == O.Node && ResNo == O.ResNo;
852856 }
853857 bool operator!=(const SDValue &O) const {
854858 return !operator==(O);
855859 }
856860 bool operator<(const SDValue &O) const {
857 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
861 return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
858862 }
859863
860864 SDValue getValue(unsigned R) const {
861 return SDValue(Val, R);
865 return SDValue(Node, R);
862866 }
863867
864868 // isOperandOf - Return true if this node is an operand of N.
893897 unsigned Depth = 2) const;
894898
895899 /// use_empty - Return true if there are no nodes using value ResNo
896 /// of node Val.
900 /// of Node.
897901 ///
898902 inline bool use_empty() const;
899903
900904 /// hasOneUse - Return true if there is exactly one node using value
901 /// ResNo of node Val.
905 /// ResNo of Node.
902906 ///
903907 inline bool hasOneUse() const;
904908 };
912916 return SDValue((SDNode*)-1, 0);
913917 }
914918 static unsigned getHashValue(const SDValue &Val) {
915 return ((unsigned)((uintptr_t)Val.Val >> 4) ^
916 (unsigned)((uintptr_t)Val.Val >> 9)) + Val.getResNo();
919 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
920 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
917921 }
918922 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
919923 return LHS == RHS;
926930 template<> struct simplify_type {
927931 typedef SDNode* SimpleType;
928932 static SimpleType getSimplifiedValue(const SDValue &Val) {
929 return static_cast(Val.Val);
933 return static_cast(Val.getNode());
930934 }
931935 };
932936 template<> struct simplify_type {
933937 typedef SDNode* SimpleType;
934938 static SimpleType getSimplifiedValue(const SDValue &Val) {
935 return static_cast(Val.Val);
939 return static_cast(Val.getNode());
936940 }
937941 };
938942
976980
977981 const SDValue& getSDValue() const { return Operand; }
978982
979 SDNode *&getVal() { return Operand.Val; }
980 SDNode *const &getVal() const { return Operand.Val; }
983 SDValue &getSDValue() { return Operand; }
984 SDNode *getVal() { return Operand.getNode(); }
985 SDNode *getVal() const { return Operand.getNode(); } // FIXME: const correct?
981986
982987 bool operator==(const SDValue &O) const {
983988 return Operand == O;
13221327 for (unsigned i = 0; i != NumOps; ++i) {
13231328 OperandList[i] = Ops[i];
13241329 OperandList[i].setUser(this);
1325 Ops[i].Val->addUse(OperandList[i]);
1330 Ops[i].getNode()->addUse(OperandList[i]);
13261331 }
13271332
13281333 ValueList = VTs.VTs;
13921397 // Define inline functions from the SDValue class.
13931398
13941399 inline unsigned SDValue::getOpcode() const {
1395 return Val->getOpcode();
1400 return Node->getOpcode();
13961401 }
13971402 inline MVT SDValue::getValueType() const {
1398 return Val->getValueType(ResNo);
1403 return Node->getValueType(ResNo);
13991404 }
14001405 inline unsigned SDValue::getNumOperands() const {
1401 return Val->getNumOperands();
1406 return Node->getNumOperands();
14021407 }
14031408 inline const SDValue &SDValue::getOperand(unsigned i) const {
1404 return Val->getOperand(i);
1409 return Node->getOperand(i);
14051410 }
14061411 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1407 return Val->getConstantOperandVal(i);
1412 return Node->getConstantOperandVal(i);
14081413 }
14091414 inline bool SDValue::isTargetOpcode() const {
1410 return Val->isTargetOpcode();
1415 return Node->isTargetOpcode();
14111416 }
14121417 inline bool SDValue::isMachineOpcode() const {
1413 return Val->isMachineOpcode();
1418 return Node->isMachineOpcode();
14141419 }
14151420 inline unsigned SDValue::getMachineOpcode() const {
1416 return Val->getMachineOpcode();
1421 return Node->getMachineOpcode();
14171422 }
14181423 inline bool SDValue::use_empty() const {
1419 return !Val->hasAnyUseOfValue(ResNo);
1424 return !Node->hasAnyUseOfValue(ResNo);
14201425 }
14211426 inline bool SDValue::hasOneUse() const {
1422 return Val->hasNUsesOfValue(1, ResNo);
1427 return Node->hasNUsesOfValue(1, ResNo);
14231428 }
14241429
14251430 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
23202325 }
23212326
23222327 pointer operator*() const {
2323 return Node->getOperand(Operand).Val;
2328 return Node->getOperand(Operand).getNode();
23242329 }
23252330 pointer operator->() const { return operator*(); }
23262331
10851085 static bool CheckTailCallReturnConstraints(SDValue Call, SDValue Ret) {
10861086 unsigned NumOps = Ret.getNumOperands();
10871087 if ((NumOps == 1 &&
1088 (Ret.getOperand(0) == SDValue(Call.Val,1) ||
1089 Ret.getOperand(0) == SDValue(Call.Val,0))) ||
1088 (Ret.getOperand(0) == SDValue(Call.getNode(),1) ||
1089 Ret.getOperand(0) == SDValue(Call.getNode(),0))) ||
10901090 (NumOps > 1 &&
1091 Ret.getOperand(0) == SDValue(Call.Val,Call.Val->getNumValues()-1) &&
1092 Ret.getOperand(1) == SDValue(Call.Val,0)))
1091 Ret.getOperand(0) == SDValue(Call.getNode(),Call.getNode()->getNumValues()-1) &&
1092 Ret.getOperand(1) == SDValue(Call.getNode(),0)))
10931093 return true;
10941094 return false;
10951095 }
147147 // Visitation implementation - Implement dag node combining for different
148148 // node types. The semantics are as follows:
149149 // Return Value:
150 // SDValue.Val == 0 - No change was made
151 // SDValue.Val == N - N was replaced, is dead, and is already handled.
150 // SDValue.getNode() == 0 - No change was made
151 // SDValue.getNode() == N - N was replaced, is dead, and is already handled.
152152 // otherwise - N should be replaced by the returned Operand.
153153 //
154154 SDValue visitTokenFactor(SDNode *N);
490490 // free when it is profitable to do so.
491491 static bool isOneUseSetCC(SDValue N) {
492492 SDValue N0, N1, N2;
493 if (isSetCCEquivalent(N, N0, N1, N2) && N.Val->hasOneUse())
493 if (isSetCCEquivalent(N, N0, N1, N2) && N.getNode()->hasOneUse())
494494 return true;
495495 return false;
496496 }
502502 if (N0.getOpcode() == Opc && isa(N0.getOperand(1))) {
503503 if (isa(N1)) {
504504 SDValue OpNode = DAG.getNode(Opc, VT, N0.getOperand(1), N1);
505 AddToWorkList(OpNode.Val);
505 AddToWorkList(OpNode.getNode());
506506 return DAG.getNode(Opc, VT, OpNode, N0.getOperand(0));
507507 } else if (N0.hasOneUse()) {
508508 SDValue OpNode = DAG.getNode(Opc, VT, N0.getOperand(0), N1);
509 AddToWorkList(OpNode.Val);
509 AddToWorkList(OpNode.getNode());
510510 return DAG.getNode(Opc, VT, OpNode, N0.getOperand(1));
511511 }
512512 }
515515 if (N1.getOpcode() == Opc && isa(N1.getOperand(1))) {
516516 if (isa(N0)) {
517517 SDValue OpNode = DAG.getNode(Opc, VT, N1.getOperand(1), N0);
518 AddToWorkList(OpNode.Val);
518 AddToWorkList(OpNode.getNode());
519519 return DAG.getNode(Opc, VT, OpNode, N1.getOperand(0));
520520 } else if (N1.hasOneUse()) {
521521 SDValue OpNode = DAG.getNode(Opc, VT, N1.getOperand(0), N0);
522 AddToWorkList(OpNode.Val);
522 AddToWorkList(OpNode.getNode());
523523 return DAG.getNode(Opc, VT, OpNode, N1.getOperand(1));
524524 }
525525 }
531531 assert(N->getNumValues() == NumTo && "Broken CombineTo call!");
532532 ++NodesCombined;
533533 DOUT << "\nReplacing.1 "; DEBUG(N->dump(&DAG));
534 DOUT << "\nWith: "; DEBUG(To[0].Val->dump(&DAG));
534 DOUT << "\nWith: "; DEBUG(To[0].getNode()->dump(&DAG));
535535 DOUT << " and " << NumTo-1 << " other values\n";
536536 WorkListRemover DeadNodes(*this);
537537 DAG.ReplaceAllUsesWith(N, To, &DeadNodes);
539539 if (AddTo) {
540540 // Push the new nodes and any users onto the worklist
541541 for (unsigned i = 0, e = NumTo; i != e; ++i) {
542 AddToWorkList(To[i].Val);
543 AddUsersToWorkList(To[i].Val);
542 AddToWorkList(To[i].getNode());
543 AddUsersToWorkList(To[i].getNode());
544544 }
545545 }
546546
563563 return false;
564564
565565 // Revisit the node.
566 AddToWorkList(Op.Val);
566 AddToWorkList(Op.getNode());
567567
568568 // Replace the old value with the new one.
569569 ++NodesCombined;
570 DOUT << "\nReplacing.2 "; DEBUG(TLO.Old.Val->dump(&DAG));
571 DOUT << "\nWith: "; DEBUG(TLO.New.Val->dump(&DAG));
570 DOUT << "\nReplacing.2 "; DEBUG(TLO.Old.getNode()->dump(&DAG));
571 DOUT << "\nWith: "; DEBUG(TLO.New.getNode()->dump(&DAG));
572572 DOUT << '\n';
573573
574574 // Replace all uses. If any nodes become isomorphic to other nodes and
577577 DAG.ReplaceAllUsesOfValueWith(TLO.Old, TLO.New, &DeadNodes);
578578
579579 // Push the new node and any (possibly new) users onto the worklist.
580 AddToWorkList(TLO.New.Val);
581 AddUsersToWorkList(TLO.New.Val);
580 AddToWorkList(TLO.New.getNode());
581 AddUsersToWorkList(TLO.New.getNode());
582582
583583 // Finally, if the node is now dead, remove it from the graph. The node
584584 // may not be dead if the replacement process recursively simplified to
585585 // something else needing this node.
586 if (TLO.Old.Val->use_empty()) {
587 removeFromWorkList(TLO.Old.Val);
586 if (TLO.Old.getNode()->use_empty()) {
587 removeFromWorkList(TLO.Old.getNode());
588588
589589 // If the operands of this node are only used by the node, they will now
590590 // be dead. Make sure to visit them first to delete dead nodes early.
591 for (unsigned i = 0, e = TLO.Old.Val->getNumOperands(); i != e; ++i)
592 if (TLO.Old.Val->getOperand(i).Val->hasOneUse())
593 AddToWorkList(TLO.Old.Val->getOperand(i).Val);
594
595 DAG.DeleteNode(TLO.Old.Val);
591 for (unsigned i = 0, e = TLO.Old.getNode()->getNumOperands(); i != e; ++i)
592 if (TLO.Old.getNode()->getOperand(i).getNode()->hasOneUse())
593 AddToWorkList(TLO.Old.getNode()->getOperand(i).getNode());
594
595 DAG.DeleteNode(TLO.Old.getNode());
596596 }
597597 return true;
598598 }
607607 // reduced number of uses, allowing other xforms.
608608 if (N->use_empty() && N != &Dummy) {
609609 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
610 AddToWorkList(N->getOperand(i).Val);
610 AddToWorkList(N->getOperand(i).getNode());
611611
612612 DAG.DeleteNode(N);
613613 return;
615615
616616 SDValue RV = combine(N);
617617
618 if (RV.Val == 0)
618 if (RV.getNode() == 0)
619619 return;
620620
621621 ++NodesCombined;
624624 // zero, we know that the node must have defined multiple values and
625625 // CombineTo was used. Since CombineTo takes care of the worklist
626626 // mechanics for us, we have no work to do in this case.
627 if (RV.Val == N)
627 if (RV.getNode() == N)
628628 return;
629629
630630 assert(N->getOpcode() != ISD::DELETED_NODE &&
631 RV.Val->getOpcode() != ISD::DELETED_NODE &&
631 RV.getNode()->getOpcode() != ISD::DELETED_NODE &&
632632 "Node was deleted but visit returned new node!");
633633
634634 DOUT << "\nReplacing.3 "; DEBUG(N->dump(&DAG));
635 DOUT << "\nWith: "; DEBUG(RV.Val->dump(&DAG));
635 DOUT << "\nWith: "; DEBUG(RV.getNode()->dump(&DAG));
636636 DOUT << '\n';
637637
638 if (N->getNumValues() == RV.Val->getNumValues())
639 DAG.ReplaceAllUsesWith(N, RV.Val);
638 if (N->getNumValues() == RV.getNode()->getNumValues())
639 DAG.ReplaceAllUsesWith(N, RV.getNode());
640640 else {
641641 assert(N->getValueType(0) == RV.getValueType() &&
642642 N->getNumValues() == 1 && "Type mismatch");
649649 DAG.DeleteNode(N);
650650
651651 // Push the new node and any users onto the worklist
652 AddToWorkList(RV.Val);
653 AddUsersToWorkList(RV.Val);
652 AddToWorkList(RV.getNode());
653 AddUsersToWorkList(RV.getNode());
654654 }
655655
656656 void DAGCombiner::Run(bool RunningAfterLegalize) {
760760 SDValue RV = visit(N);
761761
762762 // If nothing happened, try a target-specific DAG combine.
763 if (RV.Val == 0) {
763 if (RV.getNode() == 0) {
764764 assert(N->getOpcode() != ISD::DELETED_NODE &&
765765 "Node was deleted but visit returned NULL!");
766766
777777
778778 // If N is a commutative binary node, try commuting it to enable more
779779 // sdisel CSE.
780 if (RV.Val == 0 &&
780 if (RV.getNode() == 0 &&
781781 SelectionDAG::isCommutativeBinOp(N->getOpcode()) &&
782782 N->getNumValues() == 1) {
783783 SDValue N0 = N->getOperand(0);
814814 // If N has two operands, where one has an input chain equal to the other,
815815 // the 'other' chain is redundant.
816816 if (N->getNumOperands() == 2) {
817 if (getInputChainForNode(N->getOperand(0).Val) == N->getOperand(1))
817 if (getInputChainForNode(N->getOperand(0).getNode()) == N->getOperand(1))
818818 return N->getOperand(0);
819 if (getInputChainForNode(N->getOperand(1).Val) == N->getOperand(0))
819 if (getInputChainForNode(N->getOperand(1).getNode()) == N->getOperand(0))
820820 return N->getOperand(1);
821821 }
822822
846846
847847 case ISD::TokenFactor:
848848 if ((CombinerAA || Op.hasOneUse()) &&
849 std::find(TFs.begin(), TFs.end(), Op.Val) == TFs.end()) {
849 std::find(TFs.begin(), TFs.end(), Op.getNode()) == TFs.end()) {
850850 // Queue up for processing.
851 TFs.push_back(Op.Val);
851 TFs.push_back(Op.getNode());
852852 // Clean up in case the token factor is removed.
853 AddToWorkList(Op.Val);
853 AddToWorkList(Op.getNode());
854854 Changed = true;
855855 break;
856856 }
858858
859859 default:
860860 // Only add if it isn't already in the list.
861 if (SeenOps.insert(Op.Val))
861 if (SeenOps.insert(Op.getNode()))
862862 Ops.push_back(Op);
863863 else
864864 Changed = true;
904904 SDValue N00 = N0.getOperand(0);
905905 SDValue N01 = N0.getOperand(1);
906906 ConstantSDNode *N01C = dyn_cast(N01);
907 if (N01C && N00.getOpcode() == ISD::ADD && N00.Val->hasOneUse() &&
907 if (N01C && N00.getOpcode() == ISD::ADD && N00.getNode()->hasOneUse() &&
908908 isa(N00.getOperand(1))) {
909909 N0 = DAG.getNode(ISD::ADD, VT,
910910 DAG.getNode(ISD::SHL, VT, N00.getOperand(0), N01),
974974 // fold vector ops
975975 if (VT.isVector()) {
976976 SDValue FoldedVOp = SimplifyVBinOp(N);
977 if (FoldedVOp.Val) return FoldedVOp;
977 if (FoldedVOp.getNode()) return FoldedVOp;
978978 }
979979
980980 // fold (add x, undef) -> undef
10001000 N0.getOperand(1));
10011001 // reassociate add
10021002 SDValue RADD = ReassociateOps(ISD::ADD, N0, N1);
1003 if (RADD.Val != 0)
1003 if (RADD.getNode() != 0)
10041004 return RADD;
10051005 // fold ((0-A) + B) -> B-A
10061006 if (N0.getOpcode() == ISD::SUB && isa(N0.getOperand(0)) &&
10351035 }
10361036
10371037 // fold (add (shl (add x, c1), c2), ) -> (add (add (shl x, c2), c1<
1038 if (N0.getOpcode() == ISD::SHL && N0.Val->hasOneUse()) {
1038 if (N0.getOpcode() == ISD::SHL && N0.getNode()->hasOneUse()) {
10391039 SDValue Result = combineShlAddConstant(N0, N1, DAG);
1040 if (Result.Val) return Result;
1041 }
1042 if (N1.getOpcode() == ISD::SHL && N1.Val->hasOneUse()) {
1040 if (Result.getNode()) return Result;
1041 }
1042 if (N1.getOpcode() == ISD::SHL && N1.getNode()->hasOneUse()) {
10431043 SDValue Result = combineShlAddConstant(N1, N0, DAG);
1044 if (Result.Val) return Result;
1044 if (Result.getNode()) return Result;
10451045 }
10461046
10471047 // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c))
1048 if (N0.getOpcode() == ISD::SELECT && N0.Val->hasOneUse()) {
1048 if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) {
10491049 SDValue Result = combineSelectAndUse(N, N0, N1, DAG);
1050 if (Result.Val) return Result;
1051 }
1052 if (N1.getOpcode() == ISD::SELECT && N1.Val->hasOneUse()) {
1050 if (Result.getNode()) return Result;
1051 }
1052 if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) {
10531053 SDValue Result = combineSelectAndUse(N, N1, N0, DAG);
1054 if (Result.Val) return Result;
1054 if (Result.getNode()) return Result;
10551055 }
10561056
10571057 return SDValue();
11201120 SDValue DAGCombiner::visitSUB(SDNode *N) {
11211121 SDValue N0 = N->getOperand(0);
11221122 SDValue N1 = N->getOperand(1);
1123 ConstantSDNode *N0C = dyn_cast(N0.Val);
1124 ConstantSDNode *N1C = dyn_cast(N1.Val);
1123 ConstantSDNode *N0C = dyn_cast(N0.getNode());
1124 ConstantSDNode *N1C = dyn_cast(N1.getNode());
11251125 MVT VT = N0.getValueType();
11261126
11271127 // fold vector ops
11281128 if (VT.isVector()) {
11291129 SDValue FoldedVOp = SimplifyVBinOp(N);
1130 if (FoldedVOp.Val) return FoldedVOp;
1130 if (FoldedVOp.getNode()) return FoldedVOp;
11311131 }
11321132
11331133 // fold (sub x, x) -> 0
11471147 if (N0.getOpcode() == ISD::ADD && N0.getOperand(1) == N1)
11481148 return N0.getOperand(0);
11491149 // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c))
1150 if (N1.getOpcode() == ISD::SELECT && N1.Val->hasOneUse()) {
1150 if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) {
11511151 SDValue Result = combineSelectAndUse(N, N1, N0, DAG);
1152 if (Result.Val) return Result;
1152 if (Result.getNode()) return Result;
11531153 }
11541154 // If either operand of a sub is undef, the result is undef
11551155 if (N0.getOpcode() == ISD::UNDEF)
11701170 // fold vector ops
11711171 if (VT.isVector()) {
11721172 SDValue FoldedVOp = SimplifyVBinOp(N);
1173 if (FoldedVOp.Val) return FoldedVOp;
1173 if (FoldedVOp.getNode()) return FoldedVOp;
11741174 }
11751175
11761176 // fold (mul x, undef) -> 0
12071207 if (N1C && N0.getOpcode() == ISD::SHL &&
12081208 isa(N0.getOperand(1))) {
12091209 SDValue C3 = DAG.getNode(ISD::SHL, VT, N1, N0.getOperand(1));
1210 AddToWorkList(C3.Val);
1210 AddToWorkList(C3.getNode());
12111211 return DAG.getNode(ISD::MUL, VT, N0.getOperand(0), C3);
12121212 }
12131213
12171217 SDValue Sh(0,0), Y(0,0);
12181218 // Check for both (mul (shl X, C), Y) and (mul Y, (shl X, C)).
12191219 if (N0.getOpcode() == ISD::SHL && isa(N0.getOperand(1)) &&
1220 N0.Val->hasOneUse()) {
1220 N0.getNode()->hasOneUse()) {
12211221 Sh = N0; Y = N1;
12221222 } else if (N1.getOpcode() == ISD::SHL &&
1223 isa(N1.getOperand(1)) && N1.Val->hasOneUse()) {
1223 isa(N1.getOperand(1)) && N1.getNode()->hasOneUse()) {
12241224 Sh = N1; Y = N0;
12251225 }
1226 if (Sh.Val) {
1226 if (Sh.getNode()) {
12271227 SDValue Mul = DAG.getNode(ISD::MUL, VT, Sh.getOperand(0), Y);
12281228 return DAG.getNode(ISD::SHL, VT, Mul, Sh.getOperand(1));
12291229 }
12301230 }
12311231 // fold (mul (add x, c1), c2) -> (add (mul x, c2), c1*c2)
1232 if (N1C && N0.getOpcode() == ISD::ADD && N0.Val->hasOneUse() &&
1232 if (N1C && N0.getOpcode() == ISD::ADD && N0.getNode()->hasOneUse() &&
12331233 isa(N0.getOperand(1))) {
12341234 return DAG.getNode(ISD::ADD, VT,
12351235 DAG.getNode(ISD::MUL, VT, N0.getOperand(0), N1),
12381238
12391239 // reassociate mul
12401240 SDValue RMUL = ReassociateOps(ISD::MUL, N0, N1);
1241 if (RMUL.Val != 0)
1241 if (RMUL.getNode() != 0)
12421242 return RMUL;
12431243
12441244 return SDValue();
12471247 SDValue DAGCombiner::visitSDIV(SDNode *N) {
12481248 SDValue N0 = N->getOperand(0);
12491249 SDValue N1 = N->getOperand(1);
1250 ConstantSDNode *N0C = dyn_cast(N0.Val);
1251 ConstantSDNode *N1C = dyn_cast(N1.Val);
1250 ConstantSDNode *N0C = dyn_cast(N0.getNode());
1251 ConstantSDNode *N1C = dyn_cast(N1.getNode());
12521252 MVT VT = N->getValueType(0);
12531253
12541254 // fold vector ops
12551255 if (VT.isVector()) {
12561256 SDValue FoldedVOp = SimplifyVBinOp(N);
1257 if (FoldedVOp.Val) return FoldedVOp;
1257 if (FoldedVOp.getNode()) return FoldedVOp;
12581258 }
12591259
12601260 // fold (sdiv c1, c2) -> c1/c2
12871287 SDValue SGN = DAG.getNode(ISD::SRA, VT, N0,
12881288 DAG.getConstant(VT.getSizeInBits()-1,
12891289 TLI.getShiftAmountTy()));
1290 AddToWorkList(SGN.Val);
1290 AddToWorkList(SGN.getNode());
12911291 // Add (N0 < 0) ? abs2 - 1 : 0;
12921292 SDValue SRL = DAG.getNode(ISD::SRL, VT, SGN,
12931293 DAG.getConstant(VT.getSizeInBits()-lg2,
12941294 TLI.getShiftAmountTy()));
12951295 SDValue ADD = DAG.getNode(ISD::ADD, VT, N0, SRL);
1296 AddToWorkList(SRL.Val);
1297 AddToWorkList(ADD.Val); // Divide by pow2
1296 AddToWorkList(SRL.getNode());
1297 AddToWorkList(ADD.getNode()); // Divide by pow2
12981298 SDValue SRA = DAG.getNode(ISD::SRA, VT, ADD,
12991299 DAG.getConstant(lg2, TLI.getShiftAmountTy()));
13001300 // If we're dividing by a positive value, we're done. Otherwise, we must
13011301 // negate the result.
13021302 if (pow2 > 0)
13031303 return SRA;
1304 AddToWorkList(SRA.Val);
1304 AddToWorkList(SRA.getNode());
13051305 return DAG.getNode(ISD::SUB, VT, DAG.getConstant(0, VT), SRA);
13061306 }
13071307 // if integer divide is expensive and we satisfy the requirements, emit an
13091309 if (N1C && (N1C->getSignExtended() < -1 || N1C->getSignExtended() > 1) &&
13101310 !TLI.isIntDivCheap()) {
13111311 SDValue Op = BuildSDIV(N);
1312 if (Op.Val) return Op;
1312 if (Op.getNode()) return Op;
13131313 }
13141314
13151315 // undef / X -> 0
13251325 SDValue DAGCombiner::visitUDIV(SDNode *N) {
13261326 SDValue N0 = N->getOperand(0);
13271327 SDValue N1 = N->getOperand(1);
1328 ConstantSDNode *N0C = dyn_cast(N0.Val);
1329 ConstantSDNode *N1C = dyn_cast(N1.Val);
1328 ConstantSDNode *N0C = dyn_cast(N0.getNode());
1329 ConstantSDNode *N1C = dyn_cast(N1.getNode());
13301330 MVT VT = N->getValueType(0);
13311331
13321332 // fold vector ops
13331333 if (VT.isVector()) {
13341334 SDValue FoldedVOp = SimplifyVBinOp(N);
1335 if (FoldedVOp.Val) return FoldedVOp;
1335 if (FoldedVOp.getNode()) return FoldedVOp;
13361336 }
13371337
13381338 // fold (udiv c1, c2) -> c1/c2
13521352 DAG.getConstant(SHC->getAPIntValue()
13531353 .logBase2(),
13541354 ADDVT));
1355 AddToWorkList(Add.Val);
1355 AddToWorkList(Add.getNode());
13561356 return DAG.getNode(ISD::SRL, VT, N0, Add);
13571357 }
13581358 }
13601360 // fold (udiv x, c) -> alternate
13611361 if (N1C && !N1C->isNullValue() && !TLI.isIntDivCheap()) {
13621362 SDValue Op = BuildUDIV(N);
1363 if (Op.Val) return Op;
1363 if (Op.getNode()) return Op;
13641364 }
13651365
13661366 // undef / X -> 0
13941394 // X%C to the equivalent of X-X/C*C.
13951395 if (N1C && !N1C->isNullValue()) {
13961396 SDValue Div = DAG.getNode(ISD::SDIV, VT, N0, N1);
1397 AddToWorkList(Div.Val);
1398 SDValue OptimizedDiv = combine(Div.Val);
1399 if (OptimizedDiv.Val && OptimizedDiv.Val != Div.Val) {
1397 AddToWorkList(Div.getNode());
1398 SDValue OptimizedDiv = combine(Div.getNode());
1399 if (OptimizedDiv.getNode() && OptimizedDiv.getNode() != Div.getNode()) {
14001400 SDValue Mul = DAG.getNode(ISD::MUL, VT, OptimizedDiv, N1);
14011401 SDValue Sub = DAG.getNode(ISD::SUB, VT, N0, Mul);
1402 AddToWorkList(Mul.Val);
1402 AddToWorkList(Mul.getNode());
14031403 return Sub;
14041404 }
14051405 }
14361436 DAG.getNode(ISD::ADD, VT, N1,
14371437 DAG.getConstant(APInt::getAllOnesValue(VT.getSizeInBits()),
14381438 VT));
1439 AddToWorkList(Add.Val);
1439 AddToWorkList(Add.getNode());
14401440 return DAG.getNode(ISD::AND, VT, N0, Add);
14411441 }
14421442 }
14461446 // X%C to the equivalent of X-X/C*C.
14471447 if (N1C && !N1C->isNullValue()) {
14481448 SDValue Div = DAG.getNode(ISD::UDIV, VT, N0, N1);
1449 SDValue OptimizedDiv = combine(Div.Val);
1450 if (OptimizedDiv.Val && OptimizedDiv.Val != Div.Val) {
1449 SDValue OptimizedDiv = combine(Div.getNode());
1450 if (OptimizedDiv.getNode() && OptimizedDiv.getNode() != Div.getNode()) {
14511451 SDValue Mul = DAG.getNode(ISD::MUL, VT, OptimizedDiv, N1);
14521452 SDValue Sub = DAG.getNode(ISD::SUB, VT, N0, Mul);
1453 AddToWorkList(Mul.Val);
1453 AddToWorkList(Mul.getNode());
14541454 return Sub;
14551455 }
14561456 }
15391539 if (LoExists) {
15401540 SDValue Lo = DAG.getNode(LoOp, N->getValueType(0),
15411541 N->op_begin(), N->getNumOperands());
1542 AddToWorkList(Lo.Val);
1543 SDValue LoOpt = combine(Lo.Val);
1544 if (LoOpt.Val && LoOpt.Val != Lo.Val &&
1542 AddToWorkList(Lo.getNode());
1543 SDValue LoOpt = combine(Lo.getNode());
1544 if (LoOpt.getNode() && LoOpt.getNode() != Lo.getNode() &&
15451545 (!AfterLegalize ||
15461546 TLI.isOperationLegal(LoOpt.getOpcode(), LoOpt.getValueType())))
15471547 return CombineTo(N, LoOpt, LoOpt);
15501550 if (HiExists) {
15511551 SDValue Hi = DAG.getNode(HiOp, N->getValueType(1),
15521552 N->op_begin(), N->getNumOperands());
1553 AddToWorkList(Hi.Val);
1554 SDValue HiOpt = combine(Hi.Val);
1555 if (HiOpt.Val && HiOpt != Hi &&
1553 AddToWorkList(Hi.getNode());
1554 SDValue HiOpt = combine(Hi.getNode());
1555 if (HiOpt.getNode() && HiOpt != Hi &&
15561556 (!AfterLegalize ||
15571557 TLI.isOperationLegal(HiOpt.getOpcode(), HiOpt.getValueType())))
15581558 return CombineTo(N, HiOpt, HiOpt);
15621562
15631563 SDValue DAGCombiner::visitSMUL_LOHI(SDNode *N) {
15641564 SDValue Res = SimplifyNodeWithTwoResults(N, ISD::MUL, ISD::MULHS);
1565 if (Res.Val) return Res;
1565 if (Res.getNode()) return Res;
15661566
15671567 return SDValue();
15681568 }
15691569
15701570 SDValue DAGCombiner::visitUMUL_LOHI(SDNode *N) {
15711571 SDValue Res = SimplifyNodeWithTwoResults(N, ISD::MUL, ISD::MULHU);
1572 if (Res.Val) return Res;
1572 if (Res.getNode()) return Res;
15731573
15741574 return SDValue();
15751575 }
15761576
15771577 SDValue DAGCombiner::visitSDIVREM(SDNode *N) {
15781578 SDValue Res = SimplifyNodeWithTwoResults(N, ISD::SDIV, ISD::SREM);
1579 if (Res.Val) return Res;
1579 if (Res.getNode()) return Res;
15801580
15811581 return SDValue();
15821582 }
15831583
15841584 SDValue DAGCombiner::visitUDIVREM(SDNode *N) {
15851585 SDValue Res = SimplifyNodeWithTwoResults(N, ISD::UDIV, ISD::UREM);
1586 if (Res.Val) return Res;
1586 if (Res.getNode()) return Res;
15871587
15881588 return SDValue();
15891589 }
16061606 SDValue ORNode = DAG.getNode(N->getOpcode(),
16071607 N0.getOperand(0).getValueType(),
16081608 N0.getOperand(0), N1.getOperand(0));
1609 AddToWorkList(ORNode.Val);
1609 AddToWorkList(ORNode.getNode());
16101610 return DAG.getNode(N0.getOpcode(), VT, ORNode);
16111611 }
16121612
16201620 SDValue ORNode = DAG.getNode(N->getOpcode(),
16211621 N0.getOperand(0).getValueType(),
16221622 N0.getOperand(0), N1.getOperand(0));
1623 AddToWorkList(ORNode.Val);
1623 AddToWorkList(ORNode.getNode());
16241624 return DAG.getNode(N0.getOpcode(), VT, ORNode, N0.getOperand(1));
16251625 }
16261626
16391639 // fold vector ops
16401640 if (VT.isVector()) {
16411641 SDValue FoldedVOp = SimplifyVBinOp(N);
1642 if (FoldedVOp.Val) return FoldedVOp;
1642 if (FoldedVOp.getNode()) return FoldedVOp;
16431643 }
16441644
16451645 // fold (and x, undef) -> 0
16601660 return DAG.getConstant(0, VT);
16611661 // reassociate and
16621662 SDValue RAND = ReassociateOps(ISD::AND, N0, N1);
1663 if (RAND.Val != 0)
1663 if (RAND.getNode() != 0)
16641664 return RAND;
16651665 // fold (and (or x, 0xFFFF), 0xFF) -> 0xFF
16661666 if (N1C && N0.getOpcode() == ISD::OR)
16821682 // We actually want to replace all uses of the any_extend with the
16831683 // zero_extend, to avoid duplicating things. This will later cause this
16841684 // AND to be folded.
1685 CombineTo(N0.Val, Zext);
1685 CombineTo(N0.getNode(), Zext);
16861686 return SDValue(N, 0); // Return N so it doesn't get rechecked!
16871687 }
16881688 }
16961696 // fold (X == 0) & (Y == 0) -> (X|Y == 0)
16971697 if (cast(LR)->isNullValue() && Op1 == ISD::SETEQ) {
16981698 SDValue ORNode = DAG.getNode(ISD::OR, LR.getValueType(), LL, RL);
1699 AddToWorkList(ORNode.Val);
1699 AddToWorkList(ORNode.getNode());
17001700 return DAG.getSetCC(VT, ORNode, LR, Op1);
17011701 }
17021702 // fold (X == -1) & (Y == -1) -> (X&Y == -1)
17031703 if (cast(LR)->isAllOnesValue() && Op1 == ISD::SETEQ) {
17041704 SDValue ANDNode = DAG.getNode(ISD::AND, LR.getValueType(), LL, RL);
1705 AddToWorkList(ANDNode.Val);
1705 AddToWorkList(ANDNode.getNode());
17061706 return DAG.getSetCC(VT, ANDNode, LR, Op1);
17071707 }
17081708 // fold (X > -1) & (Y > -1) -> (X|Y > -1)
17091709 if (cast(LR)->isAllOnesValue() && Op1 == ISD::SETGT) {
17101710 SDValue ORNode = DAG.getNode(ISD::OR, LR.getValueType(), LL, RL);
1711 AddToWorkList(ORNode.Val);
1711 AddToWorkList(ORNode.getNode());
17121712 return DAG.getSetCC(VT, ORNode, LR, Op1);
17131713 }
17141714 }
17281728 // Simplify: and (op x...), (op y...) -> (op (and x, y))
17291729 if (N0.getOpcode() == N1.getOpcode()) {
17301730 SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N);
1731 if (Tmp.Val) return Tmp;
1731 if (Tmp.getNode()) return Tmp;
17321732 }
17331733
17341734 // fold (and (sign_extend_inreg x, i16 to i32), 1) -> (and x, 1)
17371737 SimplifyDemandedBits(SDValue(N, 0)))
17381738 return SDValue(N, 0);
17391739 // fold (zext_inreg (extload x)) -> (zextload x)
1740 if (ISD::isEXTLoad(N0.Val) && ISD::isUNINDEXEDLoad(N0.Val)) {
1740 if (ISD::isEXTLoad(N0.getNode()) && ISD::isUNINDEXEDLoad(N0.getNode())) {
17411741 LoadSDNode *LN0 = cast(N0);
17421742 MVT EVT = LN0->getMemoryVT();
17431743 // If we zero all the possible extended bits, then we can turn this into
17531753 LN0->isVolatile(),
17541754 LN0->getAlignment());
17551755 AddToWorkList(N);
1756 CombineTo(N0.Val, ExtLoad, ExtLoad.getValue(1));
1756 CombineTo(N0.getNode(), ExtLoad, ExtLoad.getValue(1));
17571757 return SDValue(N, 0); // Return N so it doesn't get rechecked!
17581758 }
17591759 }
17601760 // fold (zext_inreg (sextload x)) -> (zextload x) iff load has one use
1761 if (ISD::isSEXTLoad(N0.Val) && ISD::isUNINDEXEDLoad(N0.Val) &&
1761 if (ISD::isSEXTLoad(N0.getNode()) && ISD::isUNINDEXEDLoad(N0.getNode()) &&
17621762 N0.hasOneUse()) {
17631763 LoadSDNode *LN0 = cast(N0);
17641764 MVT EVT = LN0->getMemoryVT();
17751775 LN0->isVolatile(),
17761776 LN0->getAlignment());
17771777 AddToWorkList(N);
1778 CombineTo(N0.Val, ExtLoad, ExtLoad.getValue(1));
1778 CombineTo(N0.getNode(), ExtLoad, ExtLoad.getValue(1));
17791779 return SDValue(N, 0); // Return N so it doesn't get rechecked!
17801780 }
17811781 }
18121812 DAG.getConstant(PtrOff, PtrType));
18131813 Alignment = MinAlign(Alignment, PtrOff);
18141814 }
1815 AddToWorkList(NewPtr.Val);
1815 AddToWorkList(NewPtr.getNode());
18161816 SDValue Load =
18171817 DAG.getExtLoad(ISD::ZEXTLOAD, VT, LN0->getChain(), NewPtr,
18181818 LN0->getSrcValue(), LN0->getSrcValueOffset(), EVT,
18191819 LN0->isVolatile(), Alignment);
18201820 AddToWorkList(N);
1821 CombineTo(N0.Val, Load, Load.getValue(1));
1821 CombineTo(N0.getNode(), Load, Load.getValue(1));
18221822 return SDValue(N, 0); // Return N so it doesn't get rechecked!
18231823 }
18241824 }
18381838 // fold vector ops
18391839 if (VT.isVector()) {
18401840 SDValue FoldedVOp = SimplifyVBinOp(N);
1841 if (FoldedVOp.Val) return FoldedVOp;
1841 if (FoldedVOp.getNode()) return FoldedVOp;
18421842 }
18431843
18441844 // fold (or x, undef) -> -1
18611861 return N1;
18621862 // reassociate or
18631863 SDValue ROR = ReassociateOps(ISD::OR, N0, N1);
1864 if (ROR.Val != 0)
1864 if (ROR.getNode() != 0)
18651865 return ROR;
18661866 // Canonicalize (or (and X, c1), c2) -> (and (or X, c2), c1|c2)
1867 if (N1C && N0.getOpcode() == ISD::AND && N0.Val->hasOneUse() &&
1867 if (N1C && N0.getOpcode() == ISD::AND && N0.getNode()->hasOneUse() &&
18681868 isa(N0.getOperand(1))) {
18691869 ConstantSDNode *C1 = cast(N0.getOperand(1));
18701870 return DAG.getNode(ISD::AND, VT, DAG.getNode(ISD::OR, VT, N0.getOperand(0),
18841884 if (cast(LR)->isNullValue() &&
18851885 (Op1 == ISD::SETNE || Op1 == ISD::SETLT)) {
18861886 SDValue ORNode = DAG.getNode(ISD::OR, LR.getValueType(), LL, RL);
1887 AddToWorkList(ORNode.Val);
1887 AddToWorkList(ORNode.getNode());
18881888 return DAG.getSetCC(VT, ORNode, LR, Op1);
18891889 }
18901890 // fold (X != -1) | (Y != -1) -> (X&Y != -1)
18921892 if (cast(LR)->isAllOnesValue() &&
18931893 (Op1 == ISD::SETNE || Op1 == ISD::SETGT)) {
18941894 SDValue ANDNode = DAG.getNode(ISD::AND, LR.getValueType(), LL, RL);
1895 AddToWorkList(ANDNode.Val);
1895 AddToWorkList(ANDNode.getNode());
18961896 return DAG.getSetCC(VT, ANDNode, LR, Op1);
18971897 }
18981898 }
19121912 // Simplify: or (op x...), (op y...) -> (op (or x, y))
19131913 if (N0.getOpcode() == N1.getOpcode()) {
19141914 SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N);
1915 if (Tmp.Val) return Tmp;
1915 if (Tmp.getNode()) return Tmp;
19161916 }
19171917
19181918 // (X & C1) | (Y & C2) -> (X|Y) & C3 if possible.
19211921 N0.getOperand(1).getOpcode() == ISD::Constant &&
19221922 N1.getOperand(1).getOpcode() == ISD::Constant &&
19231923 // Don't increase # computations.
1924 (N0.Val->hasOneUse() || N1.Val->hasOneUse())) {
1924 (N0.getNode()->hasOneUse() || N1.getNode()->hasOneUse())) {
19251925 // We can only do this xform if we know that bits from X that are set in C2
19261926 // but not in C1 are already zero. Likewise for Y.
19271927 const APInt &LHSMask =
20222022 Rot = DAG.getNode(ISD::ROTR, VT, LHSShiftArg, RHSShiftAmt);
20232023
20242024 // If there is an AND of either shifted operand, apply it to the result.
2025 if (LHSMask.Val || RHSMask.Val) {
2025 if (LHSMask.getNode() || RHSMask.getNode()) {
20262026 APInt Mask = APInt::getAllOnesValue(OpSizeInBits);
20272027
2028 if (LHSMask.Val) {
2028 if (LHSMask.getNode()) {
20292029 APInt RHSBits = APInt::getLowBitsSet(OpSizeInBits, LShVal);
20302030 Mask &= cast(LHSMask)->getAPIntValue() | RHSBits;
20312031 }
2032 if (RHSMask.Val) {
2032 if (RHSMask.getNode()) {
20332033 APInt LHSBits = APInt::getHighBitsSet(OpSizeInBits, RShVal);
20342034 Mask &= cast(RHSMask)->getAPIntValue() | LHSBits;
20352035 }
20372037 Rot = DAG.getNode(ISD::AND, VT, Rot, DAG.getConstant(Mask, VT));
20382038 }
20392039
2040 return Rot.Val;
2040 return Rot.getNode();
20412041 }
20422042
20432043 // If there is a mask here, and we have a variable shift, we can't be sure
20442044 // that we're masking out the right stuff.
2045 if (LHSMask.Val || RHSMask.Val)
2045 if (LHSMask.getNode() || RHSMask.getNode())
20462046 return 0;
20472047
20482048 // fold (or (shl x, y), (srl x, (sub 32, y))) -> (rotl x, y)
20532053 dyn_cast(RHSShiftAmt.getOperand(0))) {
20542054 if (SUBC->getAPIntValue() == OpSizeInBits) {
20552055 if (HasROTL)
2056 return DAG.getNode(ISD::ROTL, VT, LHSShiftArg, LHSShiftAmt).Val;
2056 return DAG.getNode(ISD::ROTL, VT, LHSShiftArg, LHSShiftAmt).getNode();
20572057 else
2058 return DAG.getNode(ISD::ROTR, VT, LHSShiftArg, RHSShiftAmt).Val;
2058 return DAG.getNode(ISD::ROTR, VT, LHSShiftArg, RHSShiftAmt).getNode();
20592059 }
20602060 }
20612061 }
20682068 dyn_cast(LHSShiftAmt.getOperand(0))) {
20692069 if (SUBC->getAPIntValue() == OpSizeInBits) {
20702070 if (HasROTL)
2071 return DAG.getNode(ISD::ROTL, VT, LHSShiftArg, LHSShiftAmt).Val;
2071 return DAG.getNode(ISD::ROTL, VT, LHSShiftArg, LHSShiftAmt).getNode();
20722072 else
2073 return DAG.getNode(ISD::ROTR, VT, LHSShiftArg, RHSShiftAmt).Val;
2073 return DAG.getNode(ISD::ROTR, VT, LHSShiftArg, RHSShiftAmt).getNode();
20742074 }
20752075 }
20762076 }
20932093 if (ConstantSDNode *SUBC = cast(RExtOp0.getOperand(0))) {
20942094 if (SUBC->getAPIntValue() == OpSizeInBits) {
20952095 if (HasROTL)
2096 return DAG.getNode(ISD::ROTL, VT, LHSShiftArg, LHSShiftAmt).Val;
2096 return DAG.getNode(ISD::ROTL, VT, LHSShiftArg, LHSShiftAmt).getNode();
20972097 else
2098 return DAG.getNode(ISD::ROTR, VT, LHSShiftArg, RHSShiftAmt).Val;
2098 return DAG.getNode(ISD::ROTR, VT, LHSShiftArg, RHSShiftAmt).getNode();
20992099 }
21002100 }
21012101 } else if (LExtOp0.getOpcode() == ISD::SUB &&
21072107 if (ConstantSDNode *SUBC = cast(LExtOp0.getOperand(0))) {
21082108 if (SUBC->getAPIntValue() == OpSizeInBits) {
21092109 if (HasROTL)
2110 return DAG.getNode(ISD::ROTL, VT, LHSShiftArg, RHSShiftAmt).Val;
2110 return DAG.getNode(ISD::ROTL, VT, LHSShiftArg, RHSShiftAmt).getNode();
21112111 else
2112 return DAG.getNode(ISD::ROTL, VT, LHSShiftArg, LHSShiftAmt).Val;
2112 return DAG.getNode(ISD::ROTL, VT, LHSShiftArg, LHSShiftAmt).getNode();
21132113 }
21142114 }
21152115 }
21302130 // fold vector ops
21312131 if (VT.isVector()) {
21322132 SDValue FoldedVOp = SimplifyVBinOp(N);
2133 if (FoldedVOp.Val) return FoldedVOp;
2133 if (FoldedVOp.getNode()) return FoldedVOp;
21342134 }
21352135
21362136 // fold (xor undef, undef) -> 0. This is a common idiom (misuse).
21522152 return N0;
21532153 // reassociate xor
21542154 SDValue RXOR = ReassociateOps(ISD::XOR, N0, N1);
2155 if (RXOR.Val != 0)
2155 if (RXOR.getNode() != 0)
21562156 return RXOR;
21572157 // fold !(x cc y) -> (x !cc y)
21582158 if (N1C && N1C->getAPIntValue() == 1 && isSetCCEquivalent(N0, LHS, RHS, CC)) {
21682168 }
21692169 // fold (not (zext (setcc x, y))) -> (zext (not (setcc x, y)))
21702170 if (N1C && N1C->getAPIntValue() == 1 && N0.getOpcode() == ISD::ZERO_EXTEND &&
2171 N0.Val->hasOneUse() && isSetCCEquivalent(N0.getOperand(0), LHS, RHS, CC)){
2171 N0.getNode()->hasOneUse() && isSetCCEquivalent(N0.getOperand(0), LHS, RHS, CC)){
21722172 SDValue V = N0.getOperand(0);
21732173 V = DAG.getNode(ISD::XOR, V.getValueType(), V,
21742174 DAG.getConstant(1, V.getValueType()));
2175 AddToWorkList(V.Val);
2175 AddToWorkList(V.getNode());
21762176 return DAG.getNode(ISD::ZERO_EXTEND, VT, V);
21772177 }
21782178
21842184 unsigned NewOpcode = N0.getOpcode() == ISD::AND ? ISD::OR : ISD::AND;
21852185 LHS = DAG.getNode(ISD::XOR, VT, LHS, N1); // RHS = ~LHS
21862186 RHS = DAG.getNode(ISD::XOR, VT, RHS, N1); // RHS = ~RHS
2187 AddToWorkList(LHS.Val); AddToWorkList(RHS.Val);
2187 AddToWorkList(LHS.getNode()); AddToWorkList(RHS.getNode());
21882188 return DAG.getNode(NewOpcode, VT, LHS, RHS);
21892189 }
21902190 }
21962196 unsigned NewOpcode = N0.getOpcode() == ISD::AND ? ISD::OR : ISD::AND;
21972197 LHS = DAG.getNode(ISD::XOR, VT, LHS, N1); // RHS = ~LHS
21982198 RHS = DAG.getNode(ISD::XOR, VT, RHS, N1); // RHS = ~RHS
2199 AddToWorkList(LHS.Val); AddToWorkList(RHS.Val);
2199 AddToWorkList(LHS.getNode()); AddToWorkList(RHS.getNode());
22002200 return DAG.getNode(NewOpcode, VT, LHS, RHS);
22012201 }
22022202 }
22282228 // Simplify: xor (op x...), (op y...) -> (op (xor x, y))
22292229 if (N0.getOpcode() == N1.getOpcode()) {
22302230 SDValue Tmp = SimplifyBinOpWithSameOpcodeHands(N);
2231 if (Tmp.Val) return Tmp;
2231 if (Tmp.getNode()) return Tmp;
22322232 }
22332233
22342234 // Simplify the expression using non-local knowledge.
22422242 /// visitShiftByConstant - Handle transforms common to the three shifts, when
22432243 /// the shift amount is a constant.
22442244 SDValue DAGCombiner::visitShiftByConstant(SDNode *N, unsigned Amt) {
2245 SDNode *LHS = N->getOperand(0).Val;
2245 SDNode *LHS = N->getOperand(0).getNode();
22462246 if (!LHS->hasOneUse()) return SDValue();
22472247
22482248 // We want to pull some binops through shifts, so that we have (and (shift))
22772277 //
22782278 //void foo(int *X, int i) { X[i & 1235] = 1; }
22792279 //int bar(int *X, int i) { return X[i & 255]; }
2280 SDNode *BinOpLHSVal = LHS->getOperand(0).Val;
2280 SDNode *BinOpLHSVal = LHS->getOperand(0).getNode();
22812281 if ((BinOpLHSVal->getOpcode() != ISD::SHL &&
22822282 BinOpLHSVal->getOpcode() != ISD::SRA &&
22832283 BinOpLHSVal->getOpcode() != ISD::SRL) ||
25012501 return DAG.getNode(ISD::UNDEF, VT);
25022502
25032503 SDValue SmallShift = DAG.getNode(ISD::SRL, SmallVT, N0.getOperand(0), N1);
2504 AddToWorkList(SmallShift.Val);
2504 AddToWorkList(SmallShift.getNode());
25052505 return DAG.getNode(ISD::ANY_EXTEND, VT, SmallShift);
25062506 }
25072507
25392539 if (ShAmt) {
25402540 Op = DAG.getNode(ISD::SRL, VT, Op,
25412541 DAG.getConstant(ShAmt, TLI.getShiftAmountTy()));
2542 AddToWorkList(Op.Val);
2542 AddToWorkList(Op.getNode());
25432543 }
25442544 return DAG.getNode(ISD::XOR, VT, Op, DAG.getConstant(1, VT));
25452545 }
26112611 SDValue XORNode = DAG.getNode(ISD::XOR, VT0, N0, DAG.getConstant(1, VT0));
26122612 if (VT == VT0)
26132613 return XORNode;
2614 AddToWorkList(XORNode.Val);
2614 AddToWorkList(XORNode.getNode());
26152615 if (VT.bitsGT(VT0))
26162616 return DAG.getNode(ISD::ZERO_EXTEND, VT, XORNode);
26172617 return DAG.getNode(ISD::TRUNCATE, VT, XORNode);
26192619 // fold select C, 0, X -> ~C & X
26202620 if (VT == VT0 && VT == MVT::i1 && N1C && N1C->isNullValue()) {
26212621 SDValue XORNode = DAG.getNode(ISD::XOR, VT, N0, DAG.getConstant(1, VT));
2622 AddToWorkList(XORNode.Val);
2622 AddToWorkList(XORNode.getNode());
26232623 return DAG.getNode(ISD::AND, VT, XORNode, N2);
26242624 }
26252625 // fold select C, X, 1 -> ~C | X
26262626 if (VT == VT0 && VT == MVT::i1 && N2C && N2C->getAPIntValue() == 1) {
26272627 SDValue XORNode = DAG.getNode(ISD::XOR, VT, N0, DAG.getConstant(1, VT));
2628 AddToWorkList(XORNode.Val);
2628 AddToWorkList(XORNode.getNode());
26292629 return DAG.getNode(ISD::OR, VT, XORNode, N1);
26302630 }
26312631 // fold select C, X, 0 -> C & X
26722672
26732673 // Determine if the condition we're dealing with is constant
26742674 SDValue SCC = SimplifySetCC(TLI.getSetCCResultType(N0), N0, N1, CC, false);
2675 if (SCC.Val) AddToWorkList(SCC.Val);
2676
2677 if (ConstantSDNode *SCCC = dyn_cast_or_null(SCC.Val)) {
2675 if (SCC.getNode()) AddToWorkList(SCC.getNode());
2676
2677 if (ConstantSDNode *SCCC = dyn_cast_or_null(SCC.getNode())) {
26782678 if (!SCCC->isNullValue())
26792679 return N2; // cond always true -> true val
26802680 else
26822682 }
26832683
26842684 // Fold to a simpler select_cc
2685 if (SCC.Val && SCC.getOpcode() == ISD::SETCC)
2685 if (SCC.getNode() && SCC.getOpcode() == ISD::SETCC)
26862686 return DAG.getNode(ISD::SELECT_CC, N2.getValueType(),
26872687 SCC.getOperand(0), SCC.getOperand(1), N2, N3,
26882688 SCC.getOperand(2));
27102710 TargetLowering &TLI) {
27112711 bool HasCopyToRegUses = false;
27122712 bool isTruncFree = TLI.isTruncateFree(N->getValueType(0), N0.getValueType());
2713 for (SDNode::use_iterator UI = N0.Val->use_begin(), UE = N0.Val->use_end();
2713 for (SDNode::use_iterator UI = N0.getNode()->use_begin(), UE = N0.getNode()->use_end();
27142714 UI != UE; ++UI) {
27152715 SDNode *User = *UI;
27162716 if (User == N)
27542754 SDNode *User = *UI;
27552755 for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) {
27562756 SDValue UseOp = User->getOperand(i);
2757 if (UseOp.Val == N && UseOp.getResNo() == 0) {
2757 if (UseOp.getNode() == N && UseOp.getResNo() == 0) {
27582758 BothLiveOut = true;
27592759 break;
27602760 }
27842784 if (N0.getOpcode() == ISD::TRUNCATE) {
27852785 // fold (sext (truncate (load x))) -> (sext (smaller load x))
27862786 // fold (sext (truncate (srl (load x), c))) -> (sext (smaller load (x+c/n)))
2787 SDValue NarrowLoad = ReduceLoadWidth(N0.Val);
2788 if (NarrowLoad.Val) {
2789 if (NarrowLoad.Val != N0.Val)
2790 CombineTo(N0.Val, NarrowLoad);
2787 SDValue NarrowLoad = ReduceLoadWidth(N0.getNode());
2788 if (NarrowLoad.getNode()) {
2789 if (NarrowLoad.getNode() != N0.getNode())
2790 CombineTo(N0.getNode(), NarrowLoad);
27912791 return DAG.getNode(ISD::SIGN_EXTEND, VT, NarrowLoad);
27922792 }
27932793
28292829 }
28302830
28312831 // fold (sext (load x)) -> (sext (truncate (sextload x)))
2832 if (ISD::isNON_EXTLoad(N0.Val) &&
2832 if (ISD::isNON_EXTLoad(N0.getNode()) &&
28332833 ((!AfterLegalize && !cast(N0)->isVolatile()) ||
28342834 TLI.isLoadXLegal(ISD::SEXTLOAD, N0.getValueType()))) {
28352835 bool DoXform = true;
28462846 LN0->getAlignment());
28472847 CombineTo(N, ExtLoad);
28482848 SDValue Trunc = DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad);
2849 CombineTo(N0.Val, Trunc, ExtLoad.getValue(1));
2849 CombineTo(N0.getNode(), Trunc, ExtLoad.getValue(1));
28502850 // Extend SetCC uses if necessary.
28512851 for (unsigned i = 0, e = SetCCs.size(); i != e; ++i) {
28522852 SDNode *SetCC = SetCCs[i];
28682868
28692869 // fold (sext (sextload x)) -> (sext (truncate (sextload x)))
28702870 // fold (sext ( extload x)) -> (sext (truncate (sextload x)))
2871 if ((ISD::isSEXTLoad(N0.Val) || ISD::isEXTLoad(N0.Val)) &&
2872 ISD::isUNINDEXEDLoad(N0.Val) && N0.hasOneUse()) {
2871 if ((ISD::isSEXTLoad(N0.getNode()) || ISD::isEXTLoad(N0.getNode())) &&
2872 ISD::isUNINDEXEDLoad(N0.getNode()) && N0.hasOneUse()) {
28732873 LoadSDNode *LN0 = cast(N0);
28742874 MVT EVT = LN0->getMemoryVT();
28752875 if ((!AfterLegalize && !LN0->isVolatile()) ||
28802880 LN0->isVolatile(),
28812881 LN0->getAlignment());
28822882 CombineTo(N, ExtLoad);
2883 CombineTo(N0.Val, DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
2883 CombineTo(N0.getNode(), DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
28842884 ExtLoad.getValue(1));
28852885 return SDValue(N, 0); // Return N so it doesn't get rechecked!
28862886 }
28922892 SimplifySelectCC(N0.getOperand(0), N0.getOperand(1),
28932893 DAG.getConstant(~0ULL, VT), DAG.getConstant(0, VT),
28942894 cast(N0.getOperand(2))->get(), true);
2895 if (SCC.Val) return SCC;
2895 if (SCC.getNode()) return SCC;
28962896 }
28972897
28982898 // fold (sext x) -> (zext x) if the sign bit is known zero.
29182918 // fold (zext (truncate (load x))) -> (zext (smaller load x))
29192919 // fold (zext (truncate (srl (load x), c))) -> (zext (small load (x+c/n)))
29202920 if (N0.getOpcode() == ISD::TRUNCATE) {
2921 SDValue NarrowLoad = ReduceLoadWidth(N0.Val);
2922 if (NarrowLoad.Val) {
2923 if (NarrowLoad.Val != N0.Val)
2924 CombineTo(N0.Val, NarrowLoad);
2921 SDValue NarrowLoad = ReduceLoadWidth(N0.getNode());
2922 if (NarrowLoad.getNode()) {
2923 if (NarrowLoad.getNode() != N0.getNode())
2924 CombineTo(N0.getNode(), NarrowLoad);
29252925 return DAG.getNode(ISD::ZERO_EXTEND, VT, NarrowLoad);
29262926 }
29272927 }
29542954 }
29552955
29562956 // fold (zext (load x)) -> (zext (truncate (zextload x)))
2957 if (ISD::isNON_EXTLoad(N0.Val) &&
2957 if (ISD::isNON_EXTLoad(N0.getNode()) &&
29582958 ((!AfterLegalize && !cast(N0)->isVolatile()) ||
29592959 TLI.isLoadXLegal(ISD::ZEXTLOAD, N0.getValueType()))) {
29602960 bool DoXform = true;
29712971 LN0->getAlignment());
29722972 CombineTo(N, ExtLoad);
29732973 SDValue Trunc = DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad);
2974 CombineTo(N0.Val, Trunc, ExtLoad.getValue(1));
2974 CombineTo(N0.getNode(), Trunc, ExtLoad.getValue(1));
29752975 // Extend SetCC uses if necessary.
29762976 for (unsigned i = 0, e = SetCCs.size(); i != e; ++i) {
29772977 SDNode *SetCC = SetCCs[i];
29932993
29942994 // fold (zext (zextload x)) -> (zext (truncate (zextload x)))
29952995 // fold (zext ( extload x)) -> (zext (truncate (zextload x)))
2996 if ((ISD::isZEXTLoad(N0.Val) || ISD::isEXTLoad(N0.Val)) &&
2997 ISD::isUNINDEXEDLoad(N0.Val) && N0.hasOneUse()) {
2996 if ((ISD::isZEXTLoad(N0.getNode()) || ISD::isEXTLoad(N0.getNode())) &&
2997 ISD::isUNINDEXEDLoad(N0.getNode()) && N0.hasOneUse()) {
29982998 LoadSDNode *LN0 = cast(N0);
29992999 MVT EVT = LN0->getMemoryVT();
30003000 if ((!AfterLegalize && !LN0->isVolatile()) ||
30053005 LN0->isVolatile(),
30063006 LN0->getAlignment());
30073007 CombineTo(N, ExtLoad);
3008 CombineTo(N0.Val, DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
3008 CombineTo(N0.getNode(), DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
30093009 ExtLoad.getValue(1));
30103010 return SDValue(N, 0); // Return N so it doesn't get rechecked!
30113011 }
30173017 SimplifySelectCC(N0.getOperand(0), N0.getOperand(1),
30183018 DAG.getConstant(1, VT), DAG.getConstant(0, VT),
30193019 cast(N0.getOperand(2))->get(), true);
3020 if (SCC.Val) return SCC;
3020 if (SCC.getNode()) return SCC;
30213021 }
30223022
30233023 return SDValue();
30413041 // fold (aext (truncate (load x))) -> (aext (smaller load x))
30423042 // fold (aext (truncate (srl (load x), c))) -> (aext (small load (x+c/n)))
30433043 if (N0.getOpcode() == ISD::TRUNCATE) {
3044 SDValue NarrowLoad = ReduceLoadWidth(N0.Val);
3045 if (NarrowLoad.Val) {
3046 if (NarrowLoad.Val != N0.Val)
3047 CombineTo(N0.Val, NarrowLoad);
3044 SDValue NarrowLoad = ReduceLoadWidth(N0.getNode());
3045 if (NarrowLoad.getNode()) {
3046 if (NarrowLoad.getNode() != N0.getNode())
3047 CombineTo(N0.getNode(), NarrowLoad);
30483048 return DAG.getNode(ISD::ANY_EXTEND, VT, NarrowLoad);
30493049 }
30503050 }
30753075 }
30763076
30773077 // fold (aext (load x)) -> (aext (truncate (extload x)))
3078 if (ISD::isNON_EXTLoad(N0.Val) && N0.hasOneUse() &&
3078 if (ISD::isNON_EXTLoad(N0.getNode()) && N0.hasOneUse() &&
30793079 ((!AfterLegalize && !cast(N0)->isVolatile()) ||
30803080 TLI.isLoadXLegal(ISD::EXTLOAD, N0.getValueType()))) {
30813081 LoadSDNode *LN0 = cast(N0);
30873087 LN0->getAlignment());
30883088 CombineTo(N, ExtLoad);
30893089 // Redirect any chain users to the new load.
3090 DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), SDValue(ExtLoad.Val, 1));
3090 DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), SDValue(ExtLoad.getNode(), 1));
30913091 // If any node needs the original loaded value, recompute it.
30923092 if (!LN0->use_empty())
30933093 CombineTo(LN0, DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
30993099 // fold (aext (sextload x)) -> (aext (truncate (sextload x)))
31003100 // fold (aext ( extload x)) -> (aext (truncate (extload x)))
31013101 if (N0.getOpcode() == ISD::LOAD &&
3102 !ISD::isNON_EXTLoad(N0.Val) && ISD::isUNINDEXEDLoad(N0.Val) &&
3102 !ISD::isNON_EXTLoad(N0.getNode()) && ISD::isUNINDEXEDLoad(N0.getNode()) &&
31033103 N0.hasOneUse()) {
31043104 LoadSDNode *LN0 = cast(N0);
31053105 MVT EVT = LN0->getMemoryVT();
31103110 LN0->isVolatile(),
31113111 LN0->getAlignment());
31123112 CombineTo(N, ExtLoad);
3113 CombineTo(N0.Val, DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
3113 CombineTo(N0.getNode(), DAG.getNode(ISD::TRUNCATE, N0.getValueType(), ExtLoad),
31143114 ExtLoad.getValue(1));
31153115 return SDValue(N, 0); // Return N so it doesn't get rechecked!
31163116 }
31213121 SimplifySelectCC(N0.getOperand(0), N0.getOperand(1),
31223122 DAG.getConstant(1, VT), DAG.getConstant(0, VT),
31233123 cast(N0.getOperand(2))->get(), true);
3124 if (SCC.Val)
3124 if (SCC.getNode())
31253125 return SCC;
31263126 }
31273127
31443144 break;
31453145 case ISD::SRL:
31463146 // Only look at single-use SRLs.
3147 if (!V.Val->hasOneUse())
3147 if (!V.getNode()->hasOneUse())
31483148 break;
31493149 if (ConstantSDNode *RHSC = dyn_cast(V.getOperand(1))) {
31503150 // See if we can recursively simplify the LHS.
31513151 unsigned Amt = RHSC->getValue();
31523152 APInt NewMask = Mask << Amt;
31533153 SDValue SimplifyLHS = GetDemandedBits(V.getOperand(0), NewMask);
3154 if (SimplifyLHS.Val) {
3154 if (SimplifyLHS.getNode()) {
31553155 return DAG.getNode(ISD::SRL, V.getValueType(),
31563156 SimplifyLHS, V.getOperand(1));
31573157 }
32203220 unsigned NewAlign = MinAlign(LN0->getAlignment(), PtrOff);
32213221 SDValue NewPtr = DAG.getNode(ISD::ADD, PtrType, LN0->getBasePtr(),
32223222 DAG.getConstant(PtrOff, PtrType));
3223 AddToWorkList(NewPtr.Val);
3223 AddToWorkList(NewPtr.getNode());
32243224 SDValue Load = (ExtType == ISD::NON_EXTLOAD)
32253225 ? DAG.getLoad(VT, LN0->getChain(), NewPtr,
32263226 LN0->getSrcValue(), LN0->getSrcValueOffset() + PtrOff,
32333233 WorkListRemover DeadNodes(*this);
32343234 DAG.ReplaceAllUsesOfValueWith(N0.getValue(1), Load.getValue(1),
32353235 &DeadNodes);
3236 CombineTo(N->getOperand(0).Val, Load);
3236 CombineTo(N->getOperand(0).getNode(), Load);
32373237 } else
3238 CombineTo(N0.Val, Load, Load.getValue(1));
3238 CombineTo(N0.getNode(), Load, Load.getValue(1));
32393239 if (ShAmt) {
32403240 if (Opc == ISD::SIGN_EXTEND_INREG)
32413241 return DAG.getNode(Opc, VT, Load, N->getOperand(1));
32923292 // fold (sext_in_reg (load x)) -> (smaller sextload x)
32933293 // fold (sext_in_reg (srl (load x), c)) -> (smaller sextload (x+c/evtbits))
32943294 SDValue NarrowLoad = ReduceLoadWidth(N);
3295 if (NarrowLoad.Val)
3295 if (NarrowLoad.getNode())
32963296 return NarrowLoad;
32973297
32983298 // fold (sext_in_reg (srl X, 24), i8) -> sra X, 24
33103310 }
33113311
33123312 // fold (sext_inreg (extload x)) -> (sextload x)
3313 if (ISD::isEXTLoad(N0.Val) &&
3314 ISD::isUNINDEXEDLoad(N0.Val) &&
3313 if (ISD::isEXTLoad(N0.getNode()) &&
3314 ISD::isUNINDEXEDLoad(N0.getNode()) &&
33153315 EVT == cast(N0)->getMemoryVT() &&
33163316 ((!AfterLegalize && !cast(N0)->isVolatile()) ||
33173317 TLI.isLoadXLegal(ISD::SEXTLOAD, EVT))) {
33223322 LN0->isVolatile(),
33233323 LN0->getAlignment());
33243324 CombineTo(N, ExtLoad);
3325 CombineTo(N0.Val, ExtLoad, ExtLoad.getValue(1));
3325 CombineTo(N0.getNode(), ExtLoad, ExtLoad.getValue(1));
33263326 return SDValue(N, 0); // Return N so it doesn't get rechecked!
33273327 }
33283328 // fold (sext_inreg (zextload x)) -> (sextload x) iff load has one use
3329 if (ISD::isZEXTLoad(N0.Val) && ISD::isUNINDEXEDLoad(N0.Val) &&
3329 if (ISD::isZEXTLoad(N0.getNode()) && ISD::isUNINDEXEDLoad(N0.getNode()) &&
33303330 N0.hasOneUse() &&
33313331 EVT == cast(N0)->getMemoryVT() &&
33323332 ((!AfterLegalize && !cast(N0)->isVolatile()) ||
33383338 LN0->isVolatile(),
33393339 LN0->getAlignment());
33403340 CombineTo(N, ExtLoad);
3341 CombineTo(N0.Val, ExtLoad, ExtLoad.getValue(1));
3341 CombineTo(N0.getNode(), ExtLoad, ExtLoad.getValue(1));
33423342 return SDValue(N, 0); // Return N so it doesn't get rechecked!
33433343 }
33443344 return SDValue();
33783378 SDValue Shorter =
33793379 GetDemandedBits(N0, APInt::getLowBitsSet(N0.getValueSizeInBits(),
33803380 VT.getSizeInBits()));
3381 if (Shorter.Val)
3381 if (Shorter.getNode())
33823382 return DAG.getNode(ISD::TRUNCATE, VT, Shorter);
33833383
33843384 // fold (truncate (load x)) -> (smaller load x)
33893389 static SDNode *getBuildPairElt(SDNode *N, unsigned i) {
33903390 SDValue Elt = N->getOperand(i);
33913391 if (Elt.getOpcode() != ISD::MERGE_VALUES)
3392 return Elt.Val;
3393 return Elt.getOperand(Elt.getResNo()).Val;
3392 return Elt.getNode();
3393 return Elt.getOperand(Elt.getResNo()).getNode();
33943394 }
33953395
33963396 /// CombineConsecutiveLoads - build_pair (load, load) -> load
34333433 // on the bitconvert.
34343434 // First check to see if this is all constant.
34353435 if (!AfterLegalize &&
3436 N0.getOpcode() == ISD::BUILD_VECTOR && N0.Val->hasOneUse() &&
3436 N0.getOpcode() == ISD::BUILD_VECTOR && N0.getNode()->hasOneUse() &&
34373437 VT.isVector()) {
34383438 bool isSimple = true;
34393439 for (unsigned i = 0, e = N0.getNumOperands(); i != e; ++i)
34483448 assert(!DestEltVT.isVector() &&
34493449 "Element type of vector ValueType must not be vector!");
34503450 if (isSimple) {
3451 return ConstantFoldBIT_CONVERTofBUILD_VECTOR(N0.Val, DestEltVT);
3451 return ConstantFoldBIT_CONVERTofBUILD_VECTOR(N0.getNode(), DestEltVT);
34523452 }
34533453 }
34543454
34553455 // If the input is a constant, let getNode() fold it.
34563456 if (isa(N0) || isa(N0)) {
34573457 SDValue Res = DAG.getNode(ISD::BIT_CONVERT, VT, N0);
3458 if (Res.Val != N) return Res;
3458 if (Res.getNode() != N) return Res;
34593459 }
34603460
34613461 if (N0.getOpcode() == ISD::BIT_CONVERT) // conv(conv(x,t1),t2) -> conv(x,t2)
34633463
34643464 // fold (conv (load x)) -> (load (conv*)x)
34653465 // If the resultant load doesn't need a higher alignment than the original!
3466 if (ISD::isNormalLoad(N0.Val) && N0.hasOneUse() &&
3466 if (ISD::isNormalLoad(N0.getNode()) && N0.hasOneUse() &&
34673467 // Do not change the width of a volatile load.
34683468 !cast(N0)->isVolatile() &&
34693469 (!AfterLegalize || TLI.isOperationLegal(ISD::LOAD, VT))) {
34763476 LN0->getSrcValue(), LN0->getSrcValueOffset(),
34773477 LN0->isVolatile(), OrigAlign);
34783478 AddToWorkList(N);
3479 CombineTo(N0.Val, DAG.getNode(ISD::BIT_CONVERT, N0.getValueType(), Load),
3479 CombineTo(N0.getNode(), DAG.getNode(ISD::BIT_CONVERT, N0.getValueType(), Load),
34803480 Load.getValue(1));
34813481 return Load;
34823482 }
34863486 // Fold bitconvert(fabs(x)) -> and(bitconvert(x), ~signbit)
34873487 // This often reduces constant pool loads.
34883488 if ((N0.getOpcode() == ISD::FNEG || N0.getOpcode() == ISD::FABS) &&
3489 N0.Val->hasOneUse() && VT.isInteger() && !VT.isVector()) {
3489 N0.getNode()->hasOneUse() && VT.isInteger() && !VT.isVector()) {
34903490 SDValue NewConv = DAG.getNode(ISD::BIT_CONVERT, VT, N0.getOperand(0));
3491 AddToWorkList(NewConv.Val);
3491 AddToWorkList(NewConv.getNode());
34923492
34933493 APInt SignBit = APInt::getSignBit(VT.getSizeInBits());
34943494 if (N0.getOpcode() == ISD::FNEG)
35003500 // Fold bitconvert(fcopysign(cst, x)) -> bitconvert(x)&sign | cst&~sign'
35013501 // Note that we don't handle copysign(x,cst) because this can always be folded
35023502 // to an fneg or fabs.
3503 if (N0.getOpcode() == ISD::FCOPYSIGN && N0.Val->hasOneUse() &&
3503 if (N0.getOpcode() == ISD::FCOPYSIGN && N0.getNode()->hasOneUse() &&
35043504 isa(N0.getOperand(0)) &&
35053505 VT.isInteger() && !VT.isVector()) {
35063506 unsigned OrigXWidth = N0.getOperand(1).getValueType().getSizeInBits();
35073507 SDValue X = DAG.getNode(ISD::BIT_CONVERT,
35083508 MVT::getIntegerVT(OrigXWidth),
35093509 N0.getOperand(1));
3510 AddToWorkList(X.Val);
3510 AddToWorkList(X.getNode());
35113511
35123512 // If X has a different width than the result/lhs, sext it or truncate it.
35133513 unsigned VTWidth = VT.getSizeInBits();
35143514 if (OrigXWidth < VTWidth) {
35153515 X = DAG.getNode(ISD::SIGN_EXTEND, VT, X);
3516 AddToWorkList(X.Val);
3516 AddToWorkList(X.getNode());
35173517 } else if (OrigXWidth > VTWidth) {
35183518 // To get the sign bit in the right place, we have to shift it right
35193519 // before truncating.
35203520 X = DAG.getNode(ISD::SRL, X.getValueType(), X,
35213521 DAG.getConstant(OrigXWidth-VTWidth, X.getValueType()));
3522 AddToWorkList(X.Val);
3522 AddToWorkList(X.getNode());
35233523 X = DAG.getNode(ISD::TRUNCATE, VT, X);
3524 AddToWorkList(X.Val);
3524 AddToWorkList(X.getNode());
35253525 }
35263526
35273527 APInt SignBit = APInt::getSignBit(VT.getSizeInBits());
35283528 X = DAG.getNode(ISD::AND, VT, X, DAG.getConstant(SignBit, VT));
3529 AddToWorkList(X.Val);
3529 AddToWorkList(X.getNode());
35303530
35313531 SDValue Cst = DAG.getNode(ISD::BIT_CONVERT, VT, N0.getOperand(0));
35323532 Cst = DAG.getNode(ISD::AND, VT, Cst, DAG.getConstant(~SignBit, VT));
3533 AddToWorkList(Cst.Val);
3533 AddToWorkList(Cst.getNode());
35343534
35353535 return DAG.getNode(ISD::OR, VT, X, Cst);
35363536 }
35373537
35383538 // bitconvert(build_pair(ld, ld)) -> ld iff load locations are consecutive.
35393539 if (N0.getOpcode() == ISD::BUILD_PAIR) {
3540 SDValue CombineLD = CombineConsecutiveLoads(N0.Val, VT);
3541 if (CombineLD.Val)
3540 SDValue CombineLD = CombineConsecutiveLoads(N0.getNode(), VT);
3541 if (CombineLD.getNode())
35423542 return CombineLD;
35433543 }
35443544
35693569 SmallVector Ops;
35703570 for (unsigned i = 0, e = BV->getNumOperands(); i != e; ++i) {
35713571 Ops.push_back(DAG.getNode(ISD::BIT_CONVERT, DstEltVT, BV->getOperand(i)));
3572 AddToWorkList(Ops.back().Val);
3572 AddToWorkList(Ops.back().getNode());
35733573 }
35743574 MVT VT = MVT::getVectorVT(DstEltVT,
35753575 BV->getValueType(0).getVectorNumElements());
35843584 // same sizes.
35853585 assert((SrcEltVT == MVT::f32 || SrcEltVT == MVT::f64) && "Unknown FP VT!");
35863586 MVT IntVT = MVT::getIntegerVT(SrcEltVT.getSizeInBits());
3587 BV = ConstantFoldBIT_CONVERTofBUILD_VECTOR(BV, IntVT).Val;
3587 BV = ConstantFoldBIT_CONVERTofBUILD_VECTOR(BV, IntVT).getNode();
35883588 SrcEltVT = IntVT;
35893589 }
35903590
35933593 if (DstEltVT.isFloatingPoint()) {
35943594 assert((DstEltVT == MVT::f32 || DstEltVT == MVT::f64) && "Unknown FP VT!");
35953595 MVT TmpVT = MVT::getIntegerVT(DstEltVT.getSizeInBits());
3596 SDNode *Tmp = ConstantFoldBIT_CONVERTofBUILD_VECTOR(BV, TmpVT).Val;
3596 SDNode *Tmp = ConstantFoldBIT_CONVERTofBUILD_VECTOR(BV, TmpVT).getNode();
35973597
35983598 // Next, convert to FP elements of the same size.
35993599 return ConstantFoldBIT_CONVERTofBUILD_VECTOR(Tmp, DstEltVT);
36733673 // fold vector ops
36743674 if (VT.isVector()) {
36753675 SDValue FoldedVOp = SimplifyVBinOp(N);
3676 if (FoldedVOp.Val) return FoldedVOp;
3676 if (FoldedVOp.getNode()) return FoldedVOp;
36773677 }
36783678
36793679 // fold (fadd c1, c2) -> c1+c2
36933693
36943694 // If allowed, fold (fadd (fadd x, c1), c2) -> (fadd x, (fadd c1, c2))
36953695 if (UnsafeFPMath && N1CFP && N0.getOpcode() == ISD::FADD &&
3696 N0.Val->hasOneUse() && isa(N0.getOperand(1)))
3696 N0.getNode()->hasOneUse() && isa(N0.getOperand(1)))
36973697 return DAG.getNode(ISD::FADD, VT, N0.getOperand(0),
36983698 DAG.getNode(ISD::FADD, VT, N0.getOperand(1), N1));
36993699
37103710 // fold vector ops
37113711 if (VT.isVector()) {
37123712 SDValue FoldedVOp = SimplifyVBinOp(N);
3713 if (FoldedVOp.Val) return FoldedVOp;
3713 if (FoldedVOp.getNode()) return FoldedVOp;
37143714 }
37153715
37163716 // fold (fsub c1, c2) -> c1-c2
37403740 // fold vector ops
37413741 if (VT.isVector()) {
37423742 SDValue FoldedVOp = SimplifyVBinOp(N);
3743 if (FoldedVOp.Val) return FoldedVOp;
3743 if (FoldedVOp.getNode()) return FoldedVOp;
37443744 }
37453745
37463746 // fold (fmul c1, c2) -> c1*c2
37703770
37713771 // If allowed, fold (fmul (fmul x, c1), c2) -> (fmul x, (fmul c1, c2))
37723772 if (UnsafeFPMath && N1CFP && N0.getOpcode() == ISD::FMUL &&
3773 N0.Val->hasOneUse() && isa(N0.getOperand(1)))
3773 N0.getNode()->hasOneUse() && isa(N0.getOperand(1)))
37743774 return DAG.getNode(ISD::FMUL, VT, N0.getOperand(0),
37753775 DAG.getNode(ISD::FMUL, VT, N0.getOperand(1), N1));
37763776
37873787 // fold vector ops
37883788 if (VT.isVector()) {
37893789 SDValue FoldedVOp = SimplifyVBinOp(N);
3790 if (FoldedVOp.Val) return FoldedVOp;
3790 if (FoldedVOp.getNode()) return FoldedVOp;
37913791 }
37923792
37933793 // fold (fdiv c1, c2) -> c1/c2
39543954 if (N0.getOpcode() == ISD::FP_ROUND) {
39553955 // This is a value preserving truncation if both round's are.
39563956 bool IsTrunc = N->getConstantOperandVal(1) == 1 &&
3957 N0.Val->getConstantOperandVal(1) == 1;
3957 N0.getNode()->getConstantOperandVal(1) == 1;
39583958 return DAG.getNode(ISD::FP_ROUND, VT, N0.getOperand(0),
39593959 DAG.getIntPtrConstant(IsTrunc));
39603960 }
39613961
39623962 // fold (fp_round (copysign X, Y)) -> (copysign (fp_round X), Y)
3963 if (N0.getOpcode() == ISD::FCOPYSIGN && N0.Val->hasOneUse()) {
3963 if (N0.getOpcode() == ISD::FCOPYSIGN && N0.getNode()->hasOneUse()) {
39643964 SDValue Tmp = DAG.getNode(ISD::FP_ROUND, VT, N0.getOperand(0), N1);
3965 AddToWorkList(Tmp.Val);
3965 AddToWorkList(Tmp.getNode());
39663966 return DAG.getNode(ISD::FCOPYSIGN, VT, Tmp, N0.getOperand(1));
39673967 }
39683968
39993999
40004000 // Turn fp_extend(fp_round(X, 1)) -> x since the fp_round doesn't affect the
40014001 // value of X.
4002 if (N0.getOpcode() == ISD::FP_ROUND && N0.Val->getConstantOperandVal(1) == 1){
4002 if (N0.getOpcode() == ISD::FP_ROUND && N0.getNode()->getConstantOperandVal(1) == 1){
40034003 SDValue In = N0.getOperand(0);
40044004 if (In.getValueType() == VT) return In;
40054005 if (VT.bitsLT(In.getValueType()))
40084008 }
40094009
40104010 // fold (fpext (load x)) -> (fpext (fptrunc (extload x)))
4011 if (ISD::isNON_EXTLoad(N0.Val) && N0.hasOneUse() &&
4011 if (ISD::isNON_EXTLoad(N0.getNode()) && N0.hasOneUse() &&
40124012 ((!AfterLegalize && !cast(N0)->isVolatile()) ||
40134013 TLI.isLoadXLegal(ISD::EXTLOAD, N0.getValueType()))) {
40144014 LoadSDNode *LN0 = cast(N0);
40194019 LN0->isVolatile(),
40204020 LN0->getAlignment());
40214021 CombineTo(N, ExtLoad);
4022 CombineTo(N0.Val, DAG.getNode(ISD::FP_ROUND, N0.getValueType(), ExtLoad,
4022 CombineTo(N0.getNode(), DAG.getNode(ISD::FP_ROUND, N0.getValueType(), ExtLoad,
40234023 DAG.getIntPtrConstant(1)),
40244024 ExtLoad.getValue(1));
40254025 return SDValue(N, 0); // Return N so it doesn't get rechecked!
40364036
40374037 // Transform fneg(bitconvert(x)) -> bitconvert(x^sign) to avoid loading
40384038 // constant pool values.
4039 if (N0.getOpcode() == ISD::BIT_CONVERT && N0.Val->hasOneUse() &&
4039 if (N0.getOpcode() == ISD::BIT_CONVERT && N0.getNode()->hasOneUse() &&
40404040 N0.getOperand(0).getValueType().isInteger() &&
40414041 !N0.getOperand(0).getValueType().isVector()) {
40424042 SDValue Int = N0.getOperand(0);
40444044 if (IntVT.isInteger() && !IntVT.isVector()) {
40454045 Int = DAG.getNode(ISD::XOR, IntVT, Int,
40464046 DAG.getConstant(IntVT.getIntegerVTSignBit(), IntVT));
4047 AddToWorkList(Int.Val);
4047 AddToWorkList(Int.getNode());
40484048 return DAG.getNode(ISD::BIT_CONVERT, N->getValueType(0), Int);
40494049 }
40504050 }
40704070
40714071 // Transform fabs(bitconvert(x)) -> bitconvert(x&~sign) to avoid loading
40724072 // constant pool values.
4073 if (N0.getOpcode() == ISD::BIT_CONVERT && N0.Val->hasOneUse() &&
4073 if (N0.getOpcode() == ISD::BIT_CONVERT && N0.getNode()->hasOneUse() &&
40744074 N0.getOperand(0).getValueType().isInteger() &&
40754075 !N0.getOperand(0).getValueType().isVector()) {
40764076 SDValue Int = N0.getOperand(0);
40784078 if (IntVT.isInteger() && !IntVT.isVector()) {
40794079 Int = DAG.getNode(ISD::AND, IntVT, Int,
40804080 DAG.getConstant(~IntVT.getIntegerVTSignBit(), IntVT));
4081 AddToWorkList(Int.Val);
4081 AddToWorkList(Int.getNode());
40824082 return DAG.getNode(ISD::BIT_CONVERT, N->getValueType(0), Int);
40834083 }
40844084 }
41164116
41174117 // Use SimplifySetCC to simplify SETCC's.
41184118 SDValue Simp = SimplifySetCC(MVT::i1, CondLHS, CondRHS, CC->get(), false);
4119 if (Simp.Val) AddToWorkList(Simp.Val);
4120
4121 ConstantSDNode *SCCC = dyn_cast_or_null(Simp.Val);
4119 if (Simp.getNode()) AddToWorkList(Simp.getNode());
4120
4121 ConstantSDNode *SCCC = dyn_cast_or_null(Simp.getNode());
41224122
41234123 // fold br_cc true, dest -> br dest (unconditional branch)
41244124 if (SCCC && !SCCC->isNullValue())
41294129 return N->getOperand(0);
41304130
41314131 // fold to a simpler setcc
4132 if (Simp.Val && Simp.getOpcode() == ISD::SETCC)
4132 if (Simp.getNode() && Simp.getOpcode() == ISD::SETCC)
41334133 return DAG.getNode(ISD::BR_CC, MVT::Other, N->getOperand(0),
41344134 Simp.getOperand(2), Simp.getOperand(0),
41354135 Simp.getOperand(1), N->getOperand(4));
41734173 // If the pointer is not an add/sub, or if it doesn't have multiple uses, bail
41744174 // out. There is no reason to make this a preinc/predec.
41754175 if ((Ptr.getOpcode() != ISD::ADD && Ptr.getOpcode() != ISD::SUB) ||
4176 Ptr.Val->hasOneUse())
4176 Ptr.getNode()->hasOneUse())
41774177 return false;
41784178
41794179 // Ask the target to do addressing mode selection.
42034203 // Check #2.
42044204 if (!isLoad) {
42054205 SDValue Val = cast(N)->getValue();
4206 if (Val == BasePtr || BasePtr.Val->isPredecessorOf(Val.Val))
4206 if (Val == BasePtr || BasePtr.getNode()->isPredecessorOf(Val.getNode()))
42074207 return false;
42084208 }
42094209
42104210 // Now check for #3 and #4.
42114211 bool RealUse = false;
4212 for (SDNode::use_iterator I = Ptr.Val->use_begin(),
4213 E = Ptr.Val->use_end(); I != E; ++I) {
4212 for (SDNode::use_iterator I = Ptr.getNode()->use_begin(),
4213 E = Ptr.getNode()->use_end(); I != E; ++I) {
42144214 SDNode *Use = *I;
42154215 if (Use == N)
42164216 continue;
42344234 ++PreIndexedNodes;
42354235 ++NodesCombined;
42364236 DOUT << "\nReplacing.4 "; DEBUG(N->dump(&DAG));
4237 DOUT << "\nWith: "; DEBUG(Result.Val->dump(&DAG));
4237 DOUT << "\nWith: "; DEBUG(Result.getNode()->dump(&DAG));
42384238 DOUT << '\n';
42394239 WorkListRemover DeadNodes(*this);
42404240 if (isLoad) {
42534253 // Replace the uses of Ptr with uses of the updated base value.
42544254 DAG.ReplaceAllUsesOfValueWith(Ptr, Result.getValue(isLoad ? 1 : 0),
42554255 &DeadNodes);
4256 removeFromWorkList(Ptr.Val);
4257 DAG.DeleteNode(Ptr.Val);
4256 removeFromWorkList(Ptr.getNode());
4257 DAG.DeleteNode(Ptr.getNode());
42584258
42594259 return true;
42604260 }
42914291 } else
42924292 return false;
42934293
4294 if (Ptr.Val->hasOneUse())
4294 if (Ptr.getNode()->hasOneUse())
42954295 return false;
42964296
4297 for (SDNode::use_iterator I = Ptr.Val->use_begin(),
4298 E = Ptr.Val->use_end(); I != E; ++I) {
4297 for (SDNode::use_iterator I = Ptr.getNode()->use_begin(),
4298 E = Ptr.getNode()->use_end(); I != E; ++I) {
42994299 SDNode *Op = *I;
43004300 if (Op == N ||
43014301 (Op->getOpcode() != ISD::ADD && Op->getOpcode() != ISD::SUB))
43224322
43234323 // Check for #1.
43244324 bool TryNext = false;
4325 for (SDNode::use_iterator II = BasePtr.Val->use_begin(),
4326 EE = BasePtr.Val->use_end(); II != EE; ++II) {
4325 for (SDNode::use_iterator II = BasePtr.getNode()->use_begin(),
4326 EE = BasePtr.getNode()->use_end(); II != EE; ++II) {
43274327 SDNode *Use = *II;
4328 if (Use == Ptr.Val)
4328 if (Use == Ptr.getNode())
43294329 continue;
43304330
43314331 // If all the uses are load / store addresses, then don't do the
43364336 EEE = Use->use_end(); III != EEE; ++III) {
43374337 SDNode *UseUse = *III;
43384338 if (!((UseUse->getOpcode() == ISD::LOAD &&
4339 cast(UseUse)->getBasePtr().Val == Use) ||
4339 cast(UseUse)->getBasePtr().getNode() == Use) ||
43404340 (UseUse->getOpcode() == ISD::STORE &&
4341 cast(UseUse)->getBasePtr().Val == Use)))
4341 cast(UseUse)->getBasePtr().getNode() == Use)))
43424342 RealUse = true;
43434343 }
43444344
43594359 ++PostIndexedNodes;
43604360 ++NodesCombined;
43614361 DOUT << "\nReplacing.5 "; DEBUG(N->dump(&DAG));
4362 DOUT << "\nWith: "; DEBUG(Result.Val->dump(&DAG));
4362 DOUT << "\nWith: "; DEBUG(Result.getNode()->dump(&DAG));
43634363 DOUT << '\n';
43644364 WorkListRemover DeadNodes(*this);
43654365 if (isLoad) {
44624462 // Now we replace use of chain2 with chain1. This makes the second load
44634463 // isomorphic to the one we are deleting, and thus makes this load live.
44644464 DOUT << "\nReplacing.6 "; DEBUG(N->dump(&DAG));
4465 DOUT << "\nWith chain: "; DEBUG(Chain.Val->dump(&DAG));
4465 DOUT << "\nWith chain: "; DEBUG(Chain.getNode()->dump(&DAG));
44664466 DOUT << "\n";
44674467 WorkListRemover DeadNodes(*this);
44684468 DAG.ReplaceAllUsesOfValueWith(SDValue(N, 1), Chain, &DeadNodes);
44784478 if (N->hasNUsesOfValue(0, 0) && N->hasNUsesOfValue(0, 1)) {
44794479 SDValue Undef = DAG.getNode(ISD::UNDEF, N->getValueType(0));
44804480 DOUT << "\nReplacing.6 "; DEBUG(N->dump(&DAG));
4481 DOUT << "\nWith: "; DEBUG(Undef.Val->dump(&DAG));
4481 DOUT << "\nWith: "; DEBUG(Undef.getNode()->dump(&DAG));
44824482 DOUT << " and 2 other values\n";
44834483 WorkListRemover DeadNodes(*this);
44844484 DAG.ReplaceAllUsesOfValueWith(SDValue(N, 0), Undef, &DeadNodes);
44994499 // TODO: Handle TRUNCSTORE/LOADEXT
45004500 if (LD->getExtensionType() == ISD::NON_EXTLOAD &&
45014501 !LD->isVolatile()) {
4502 if (ISD::isNON_TRUNCStore(Chain.Val)) {
4502 if (ISD::isNON_TRUNCStore(Chain.getNode())) {
45034503 StoreSDNode *PrevST = cast(Chain);
45044504 if (PrevST->getBasePtr() == Ptr &&
45054505 PrevST->getValue().getValueType() == N->getValueType(0))
46834683 GetDemandedBits(Value,
46844684 APInt::getLowBitsSet(Value.getValueSizeInBits(),
46854685 ST->getMemoryVT().getSizeInBits()));
4686 AddToWorkList(Value.Val);
4687 if (Shorter.Val)
4686 AddToWorkList(Value.getNode());
4687 if (Shorter.getNode())
46884688 return DAG.getTruncStore(Chain, Shorter, Ptr, ST->getSrcValue(),
46894689 ST->getSrcValueOffset(), ST->getMemoryVT(),
46904690 ST->isVolatile(), ST->getAlignment());
47144714 // If this is an FP_ROUND or TRUNC followed by a store, fold this into a
47154715 // truncating store. We can do this even if this is already a truncstore.
47164716 if ((Value.getOpcode() == ISD::FP_ROUND || Value.getOpcode() == ISD::TRUNCATE)
4717 && Value.Val->hasOneUse() && ST->isUnindexed() &&
4717 && Value.getNode()->hasOneUse() && ST->isUnindexed() &&
47184718 TLI.isTruncStoreLegal(Value.getOperand(0).getValueType(),
47194719 ST->getMemoryVT())) {
47204720 return DAG.getTruncStore(Chain, Value.getOperand(0), Ptr, ST->getSrcValue(),
47344734 // vector with the inserted element.
47354735 if (InVec.getOpcode() == ISD::BUILD_VECTOR && isa(EltNo)) {
47364736 unsigned Elt = cast(EltNo)->getValue();
4737 SmallVector Ops(InVec.Val->op_begin(), InVec.Val->op_end());
4737 SmallVector Ops(InVec.getNode()->op_begin(), InVec.getNode()->op_end());
47384738 if (Elt < Ops.size())
47394739 Ops[Elt] = InVal;
47404740 return DAG.getNode(ISD::BUILD_VECTOR, InVec.getValueType(),
47724772 }
47734773
47744774 LoadSDNode *LN0 = NULL;
4775 if (ISD::isNormalLoad(InVec.Val))
4775 if (ISD::isNormalLoad(InVec.getNode()))
47764776 LN0 = cast(InVec);
47774777 else if (InVec.getOpcode() == ISD::SCALAR_TO_VECTOR &&
47784778 InVec.getOperand(0).getValueType() == EVT &&
4779 ISD::isNormalLoad(InVec.getOperand(0).Val)) {
4779 ISD::isNormalLoad(InVec.getOperand(0).getNode())) {
47804780 LN0 = cast(InVec.getOperand(0));
47814781 } else if (InVec.getOpcode() == ISD::VECTOR_SHUFFLE) {
47824782 // (vextract (vector_shuffle (load $addr), v2, <1, u, u, u>), 1)
47884788 InVec = (Idx < NumElems) ? InVec.getOperand(0) : InVec.getOperand(1);
47894789 if (InVec.getOpcode() == ISD::BIT_CONVERT)
47904790 InVec = InVec.getOperand(0);
4791 if (ISD::isNormalLoad(InVec.Val)) {
4791 if (ISD::isNormalLoad(InVec.getNode())) {
47924792 LN0 = cast(InVec);
47934793 Elt = (Idx < NumElems) ? Idx : Idx - NumElems;
47944794 }
48584858 if (ExtractedFromVec == VecIn1 || ExtractedFromVec == VecIn2)
48594859 continue;
48604860
4861 if (VecIn1.Val == 0) {
4861 if (VecIn1.getNode() == 0) {
48624862 VecIn1 = ExtractedFromVec;
4863 } else if (VecIn2.Val == 0) {
4863 } else if (VecIn2.getNode() == 0) {
48644864 VecIn2 = ExtractedFromVec;
48654865 } else {
48664866 // Too many inputs.
48704870 }
48714871
48724872 // If everything is good, we can make a shuffle operation.
4873 if (VecIn1.Val) {
4873 if (VecIn1.getNode()) {
48744874 SmallVector BuildVecIndices;
48754875 for (unsigned i = 0; i != NumInScalars; ++i) {
48764876 if (N->getOperand(i).getOpcode() == ISD::UNDEF) {
48974897 // Return the new VECTOR_SHUFFLE node.
48984898 SDValue Ops[5];
48994899 Ops[0] = VecIn1;
4900 if (VecIn2.Val) {
4900 if (VecIn2.getNode()) {
49014901 Ops[1] = VecIn2;
49024902 } else {
49034903 // Use an undef build_vector as input for the second operand.
49064906 EltType));
49074907 Ops[1] = DAG.getNode(ISD::BUILD_VECTOR, VT,
49084908 &UnOps[0], UnOps.size());
4909 AddToWorkList(Ops[1].Val);
4909 AddToWorkList(Ops[1].getNode());
49104910 }
49114911 Ops[2] = DAG.getNode(ISD::BUILD_VECTOR, BuildVecVT,
49124912 &BuildVecIndices[0], BuildVecIndices.size());
49884988 // If it is a splat, check if the argument vector is a build_vector with
49894989 // all scalar elements the same.
49904990 if (isSplat) {
4991 SDNode *V = N0.Val;
4991 SDNode *V = N0.getNode();
49924992
49934993 // If this is a bit convert that changes the element type of the vector but
49944994 // not the number of vector elements, look through it. Be careful not to
49974997 SDValue ConvInput = V->getOperand(0);
49984998 if (ConvInput.getValueType().isVector() &&
49994999 ConvInput.getValueType().getVectorNumElements() == NumElts)
5000 V = ConvInput.Val;
5000 V = ConvInput.getNode();
50015001 }
50025002
50035003 if (V->getOpcode() == ISD::BUILD_VECTOR) {
50125012 }
50135013 }
50145014 // Splat of , return
5015 if (!Base.Val)
5015 if (!Base.getNode())
50165016 return N0;
50175017 for (unsigned i = 0; i != NumElems; ++i) {
50185018 if (V->getOperand(i) != Base) {
50465046 }
50475047 ShufMask = DAG.getNode(ISD::BUILD_VECTOR, ShufMask.getValueType(),
50485048 &MappedOps[0], MappedOps.size());
5049 AddToWorkList(ShufMask.Val);
5049 AddToWorkList(ShufMask.getNode());
50505050 return DAG.getNode(ISD::VECTOR_SHUFFLE, N->getValueType(0),
50515051 N0,
50525052 DAG.getNode(ISD::UNDEF, N->getValueType(0)),
50925092 std::vector Ops;
50935093 LHS = DAG.getNode(ISD::BIT_CONVERT, VT, LHS);
50945094 Ops.push_back(LHS);
5095 AddToWorkList(LHS.Val);
5095 AddToWorkList(LHS.getNode());
50965096 std::vector ZeroOps(NumElts, DAG.getConstant(0, EVT));
50975097 Ops.push_back(DAG.getNode(ISD::BUILD_VECTOR, VT,
50985098 &ZeroOps[0], ZeroOps.size()));
51225122 SDValue LHS = N->getOperand(0);
51235123 SDValue RHS = N->getOperand(1);
51245124 SDValue Shuffle = XformToShuffleWithZero(N);
5125 if (Shuffle.Val) return Shuffle;
5125 if (Shuffle.getNode()) return Shuffle;
51265126
51275127 // If the LHS and RHS are BUILD_VECTOR nodes, see if we can constant fold
51285128 // this operation.
51445144 if (N->getOpcode() == ISD::SDIV || N->getOpcode() == ISD::UDIV ||
51455145 N->getOpcode() == ISD::FDIV) {
51465146 if ((RHSOp.getOpcode() == ISD::Constant &&
5147 cast(RHSOp.Val)->isNullValue()) ||
5147 cast(RHSOp.getNode())->isNullValue()) ||
51485148 (RHSOp.getOpcode() == ISD::ConstantFP &&
5149 cast(RHSOp.Val)->getValueAPF().isZero()))
5149 cast(RHSOp.getNode())->getValueAPF().isZero()))
51505150 break;
51515151 }
51525152 Ops.push_back(DAG.getNode(N->getOpcode(), EltType, LHSOp, RHSOp));
5153 AddToWorkList(Ops.back().Val);
5153 AddToWorkList(Ops.back().getNode());
51545154 assert((Ops.back().getOpcode() == ISD::UNDEF ||
51555155 Ops.back().getOpcode() == ISD::Constant ||
51565156 Ops.back().getOpcode() == ISD::ConstantFP) &&
51745174 // If we got a simplified select_cc node back from SimplifySelectCC, then
51755175 // break it down into a new SETCC node, and a new SELECT node, and then return
51765176 // the SELECT node, since we were called with a SELECT node.
5177 if (SCC.Val) {
5177 if (SCC.getNode()) {
51785178 // Check to see if we got a select_cc back (to turn into setcc/select).
51795179 // Otherwise, just return whatever node we got back, like fabs.
51805180 if (SCC.getOpcode() == ISD::SELECT_CC) {
51815181 SDValue SETCC = DAG.getNode(ISD::SETCC, N0.getValueType(),
51825182 SCC.getOperand(0), SCC.getOperand(1),
51835183 SCC.getOperand(4));
5184 AddToWorkList(SETCC.Val);
5184 AddToWorkList(SETCC.getNode());
51855185 return DAG.getNode(ISD::SELECT, SCC.getValueType(), SCC.getOperand(2),
51865186 SCC.getOperand(3), SETCC);
51875187 }
52255225 if (TheSelect->getOpcode() == ISD::SELECT) {
52265226 // Check that the condition doesn't reach either load. If so, folding
52275227 // this will induce a cycle into the DAG.
5228 if (!LLD->isPredecessorOf(TheSelect->getOperand(0).Val) &&
5229 !RLD->isPredecessorOf(TheSelect->getOperand(0).Val)) {
5228 if (!LLD->isPredecessorOf(TheSelect->getOperand(0).getNode()) &&
5229 !RLD->isPredecessorOf(TheSelect->getOperand(0).getNode())) {
52305230 Addr = DAG.getNode(ISD::SELECT, LLD->getBasePtr().getValueType(),
52315231 TheSelect->getOperand(0), LLD->getBasePtr(),
52325232 RLD->getBasePtr());
52345234 } else {
52355235 // Check that the condition doesn't reach either load. If so, folding
52365236 // this will induce a cycle into the DAG.
5237 if (!LLD->isPredecessorOf(TheSelect->getOperand(0).Val) &&
5238 !RLD->isPredecessorOf(TheSelect->getOperand(0).Val) &&
5239 !LLD->isPredecessorOf(TheSelect->getOperand(1).Val) &&
5240 !RLD->isPredecessorOf(TheSelect->getOperand(1).Val)) {
5237 if (!LLD->isPredecessorOf(TheSelect->getOperand(0).getNode()) &&
5238 !RLD->isPredecessorOf(TheSelect->getOperand(0).getNode()) &&
5239 !LLD->isPredecessorOf(TheSelect->getOperand(1).getNode()) &&
5240 !RLD->isPredecessorOf(TheSelect->getOperand(1).getNode())) {
52415241 Addr = DAG.getNode(ISD::SELECT_CC, LLD->getBasePtr().getValueType(),
52425242 TheSelect->getOperand(0),
52435243 TheSelect->getOperand(1),
52465246 }
52475247 }
52485248
5249 if (Addr.Val) {
5249 if (Addr.getNode()) {
52505250 SDValue Load;
52515251 if (LLD->getExtensionType() == ISD::NON_EXTLOAD)
52525252 Load = DAG.getLoad(TheSelect->getValueType(0), LLD->getChain(),
52685268
52695269 // Users of the old loads now use the new load's chain. We know the
52705270 // old-load value is dead now.
5271 CombineTo(LHS.Val, Load.getValue(0), Load.getValue(1));
5272 CombineTo(RHS.Val, Load.getValue(0), Load.getValue(1));
5271 CombineTo(LHS.getNode(), Load.getValue(0), Load.getValue(1));
5272 CombineTo(RHS.getNode(), Load.getValue(0), Load.getValue(1));
52735273 return true;
52745274 }
52755275 }
52845284 ISD::CondCode CC, bool NotExtCompare) {
52855285
52865286 MVT VT = N2.getValueType();
5287 ConstantSDNode *N1C = dyn_cast(N1.Val);
5288 ConstantSDNode *N2C = dyn_cast(N2.Val);
5289 ConstantSDNode *N3C = dyn_cast(N3.Val);
5287 ConstantSDNode *N1C = dyn_cast(N1.getNode());
5288 ConstantSDNode *N2C = dyn_cast(N2.getNode());
5289 ConstantSDNode *N3C = dyn_cast(N3.getNode());
52905290
52915291 // Determine if the condition we're dealing with is constant
52925292 SDValue SCC = SimplifySetCC(TLI.getSetCCResultType(N0), N0, N1, CC, false);
5293 if (SCC.Val) AddToWorkList(SCC.Val);
5294 ConstantSDNode *SCCC = dyn_cast_or_null(SCC.Val);
5293 if (SCC.getNode()) AddToWorkList(SCC.getNode());
5294 ConstantSDNode *SCCC = dyn_cast_or_null(SCC.getNode());
52955295
52965296 // fold select_cc true, x, y -> x
52975297 if (SCCC && !SCCC->isNullValue())
53355335 ShCtV = XType.getSizeInBits()-ShCtV-1;
53365336 SDValue ShCt = DAG.getConstant(ShCtV, TLI.getShiftAmountTy());
53375337 SDValue Shift = DAG.getNode(ISD::SRL, XType, N0, ShCt);
5338 AddToWorkList(Shift.Val);
5338 AddToWorkList(Shift.getNode());
53395339 if (XType.bitsGT(AType)) {
53405340 Shift = DAG.getNode(ISD::TRUNCATE, AType, Shift);
5341 AddToWorkList(Shift.Val);
5341 AddToWorkList(Shift.getNode());
53425342 }
53435343 return DAG.getNode(ISD::AND, AType, Shift, N2);
53445344 }
53455345 SDValue Shift = DAG.getNode(ISD::SRA, XType, N0,
53465346 DAG.getConstant(XType.getSizeInBits()-1,
53475347 TLI.getShiftAmountTy()));
5348 AddToWorkList(Shift.Val);
5348 AddToWorkList(Shift.getNode());
53495349 if (XType.bitsGT(AType)) {
53505350 Shift = DAG.getNode(ISD::TRUNCATE, AType, Shift);
5351 AddToWorkList(Shift.Val);
5351 AddToWorkList(Shift.getNode());
53525352 }
53535353 return DAG.getNode(ISD::AND, AType, Shift, N2);
53545354 }
53785378 SCC = DAG.getSetCC(MVT::i1, N0, N1, CC);
53795379 Temp = DAG.getNode(ISD::ZERO_EXTEND, N2.getValueType(), SCC);
53805380 }
5381 AddToWorkList(SCC.Val);
5382 AddToWorkList(Temp.Val);
5381 AddToWorkList(SCC.getNode());
5382 AddToWorkList(Temp.getNode());
53835383
53845384 if (N2C->getAPIntValue() == 1)
53855385 return Temp;
54415441 DAG.getConstant(XType.getSizeInBits()-1,
54425442 TLI.getShiftAmountTy()));
54435443 SDValue Add = DAG.getNode(ISD::ADD, XType, N0, Shift);
5444 AddToWorkList(Shift.Val);
5445 AddToWorkList(Add.Val);
5444 AddToWorkList(Shift.getNode());
5445 AddToWorkList(Add.getNode());
54465446 return DAG.getNode(ISD::XOR, XType, Add, Shift);
54475447 }
54485448 // Check to see if this is an integer abs. select_cc setgt X, -1, X, -X ->
54565456 DAG.getConstant(XType.getSizeInBits()-1,
54575457 TLI.getShiftAmountTy()));
54585458 SDValue Add = DAG.getNode(ISD::ADD, XType, N0, Shift);
5459 AddToWorkList(Shift.Val);
5460 AddToWorkList(Add.Val);
5459 AddToWorkList(Shift.getNode());
5460 AddToWorkList(Add.getNode());
54615461 return DAG.getNode(ISD::XOR, XType, Add, Shift);
54625462 }
54635463 }
56115611 Chains.pop_back();
56125612
56135613 // Don't bother if we've been before.
5614 if (Visited.find(Chain.Val) != Visited.end()) continue;
5615 Visited.insert(Chain.Val);
5614 if (Visited.find(Chain.getNode()) != Visited.end()) continue;
5615 Visited.insert(Chain.getNode());
56165616
56175617 switch (Chain.getOpcode()) {
56185618 case ISD::EntryToken:
56265626 int64_t OpSize;
56275627 const Value *OpSrcValue;
56285628 int OpSrcValueOffset;
5629 bool IsOpLoad = FindAliasInfo(Chain.Val, OpPtr, OpSize,
5629 bool IsOpLoad = FindAliasInfo(Chain.getNode(), OpPtr, OpSize,
56305630 OpSrcValue, OpSrcValueOffset);
56315631
56325632 // If chain is alias then stop here.
56385638 // Look further up the chain.
56395639 Chains.push_back(Chain.getOperand(0));
56405640 // Clean up old chain.
5641 AddToWorkList(Chain.Val);
5641 AddToWorkList(Chain.getNode());
56425642 }
56435643 break;
56445644 }
56515651 for (unsigned n = Chain.getNumOperands(); n;)
56525652 Chains.push_back(Chain.getOperand(--n));
56535653 // Eliminate the token factor if we can.
5654 AddToWorkList(Chain.Val);
5654 AddToWorkList(Chain.getNode());
56555655 break;
56565656
56575657 default:
56835683 &Aliases[0], Aliases.size());
56845684
56855685 // Make sure the old chain gets cleaned up.
5686 if (NewChain != OldChain) AddToWorkList(OldChain.Val);
5686 if (NewChain != OldChain) AddToWorkList(OldChain.getNode());
56875687
56885688 return NewChain;
56895689 }
259259 break;
260260 }
261261 }
262 return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.Val : 0;
262 return TLI.isShuffleMaskLegal(Mask, VT) ? Mask.getNode() : 0;
263263 }
264264
265265 SelectionDAGLegalize::SelectionDAGLegalize(SelectionDAG &dag)
349349
350350 assert(Node->getOperand(0).getValueType() == MVT::Other &&
351351 "Node doesn't have a token chain argument!");
352 return FindCallStartFromCallEnd(Node->getOperand(0).Val);
352 return FindCallStartFromCallEnd(Node->getOperand(0).getNode());
353353 }
354354
355355 /// LegalizeAllNodesNotLeadingTo - Recursively walk the uses of N, looking to
386386 bool OperandsLeadToDest = false;
387387 for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i)
388388 OperandsLeadToDest |= // If an operand leads to Dest, so do we.
389 LegalizeAllNodesNotLeadingTo(N->getOperand(i).Val, Dest, NodesLeadingTo);
389 LegalizeAllNodesNotLeadingTo(N->getOperand(i).getNode(), Dest, NodesLeadingTo);
390390
391391 if (OperandsLeadToDest) {
392392 NodesLeadingTo.insert(N);
666666 MVT VT = Op.getValueType();
667667 assert(isTypeLegal(VT) &&
668668 "Caller should expand or promote operands that are not legal!");
669 assert(Op.Val->getNumValues() == 1 &&
669 assert(Op.getNode()->getNumValues() == 1 &&
670670 "Can't unroll a vector with multiple results!");
671671 unsigned NE = VT.getVectorNumElements();
672672 MVT EltVT = VT.getVectorElementType();
732732 MVT PtrVT = TLI.getPointerTy();
733733 SDValue StackPtr = DAG.CreateStackTemporary(VT);
734734
735 int SPFI = cast(StackPtr.Val)->getIndex();
735 int SPFI = cast(StackPtr.getNode())->getIndex();
736736
737737 // Store the vector.
738738 SDValue Ch = DAG.getStore(DAG.getEntryNode(), Tmp1, StackPtr,
763763
764764 assert(isTypeLegal(Op.getValueType()) &&
765765 "Caller should expand or promote operands that are not legal!");
766 SDNode *Node = Op.Val;
766 SDNode *Node = Op.getNode();
767767
768768 // If this operation defines any values that cannot be represented in a
769769 // register on this target, make sure to expand or promote them.
838838 default: assert(0 && "This action is not supported yet!");
839839 case TargetLowering::Custom:
840840 Tmp1 = TLI.LowerOperation(Op, DAG);
841 if (Tmp1.Val) Result = Tmp1;
841 if (Tmp1.getNode()) Result = Tmp1;
842842 // FALLTHROUGH if the target doesn't want to lower this op after all.
843843 case TargetLowering::Legal:
844844 break;
849849 // The only option for these nodes is to custom lower them. If the target
850850 // does not custom lower them, then return zero.
851851 Tmp1 = TLI.LowerOperation(Op, DAG);
852 if (Tmp1.Val)
852 if (Tmp1.getNode())
853853 Result = Tmp1;
854854 else
855855 Result = DAG.getConstant(0, TLI.getPointerTy());
860860 default: assert(0 && "This action is not supported yet!");
861861 case TargetLowering::Custom:
862862 Result = TLI.LowerOperation(Op, DAG);
863 if (Result.Val) break;
863 if (Result.getNode()) break;
864864 // Fall Thru
865865 case TargetLowering::Legal:
866866 Result = DAG.getConstant(0, VT);
880880 break;
881881 case TargetLowering::Custom:
882882 Result = TLI.LowerOperation(Op, DAG);
883 if (Result.Val) break;
883 if (Result.getNode()) break;
884884 // Fall Thru
885885 case TargetLowering::Legal: {
886886 SDValue Ops[] = { DAG.getConstant(0, VT), Tmp1 };
889889 }
890890 }
891891 }
892 if (Result.Val->getNumValues() == 1) break;
893
894 assert(Result.Val->getNumValues() == 2 &&
892 if (Result.getNode()->getNumValues() == 1) break;
893
894 assert(Result.getNode()->getNumValues() == 2 &&
895895 "Cannot return more than two values!");
896896
897897 // Since we produced two values, make sure to remember that we
914914 break;
915915 case TargetLowering::Custom:
916916 Result = TLI.LowerOperation(Op, DAG);
917 if (Result.Val) break;
917 if (Result.getNode()) break;
918918 // Fall Thru
919919 case TargetLowering::Legal: {
920920 SDValue Ops[] = { DAG.getConstant(0, VT), Tmp2 };
923923 }
924924 }
925925 }
926 if (Result.Val->getNumValues() == 1) break;
927
928 assert(Result.Val->getNumValues() == 2 &&
926 if (Result.getNode()->getNumValues() == 1) break;
927
928 assert(Result.getNode()->getNumValues() == 2 &&
929929 "Cannot return more than two values!");
930930
931931 // Since we produced two values, make sure to remember that we
942942 default: assert(0 && "This action is not supported at all!");
943943 case TargetLowering::Custom:
944944 Result = TLI.LowerOperation(Op, DAG);
945 if (Result.Val) break;
945 if (Result.getNode()) break;
946946 // Fall Thru
947947 case TargetLowering::Legal:
948948 // Target does not know, how to lower this, lower to noop
10111011 if (TLI.getOperationAction(Node->getOpcode(), MVT::Other) ==
10121012 TargetLowering::Custom) {
10131013 Tmp3 = TLI.LowerOperation(Result, DAG);
1014 if (Tmp3.Val) Result = Tmp3;
1015 }
1016
1017 if (Result.Val->getNumValues() == 1) break;
1014 if (Tmp3.getNode()) Result = Tmp3;
1015 }
1016
1017 if (Result.getNode()->getNumValues() == 1) break;
10181018
10191019 // Must have return value and chain result.
1020 assert(Result.Val->getNumValues() == 2 &&
1020 assert(Result.getNode()->getNumValues() == 2 &&
10211021 "Cannot return more than two values!");
10221022
10231023 // Since loads produce two values, make sure to remember that we
12601260 Result = TLI.LowerOperation(Result, DAG);
12611261 break;
12621262 case TargetLowering::Expand:
1263 Result = SDValue(TLI.ReplaceNodeResults(Op.Val, DAG),0);
1263 Result = SDValue(TLI.ReplaceNodeResults(Op.getNode(), DAG),0);
12641264 break;
12651265 case TargetLowering::Legal:
12661266 break;
12791279
12801280 if (opAction == TargetLowering::Custom) {
12811281 Tmp1 = TLI.LowerOperation(Result, DAG);
1282 if (Tmp1.Val)
1282 if (Tmp1.getNode())
12831283 Result = Tmp1;
12841284 }
12851285 break;
12971297 break;
12981298 case TargetLowering::Custom:
12991299 Tmp3 = TLI.LowerOperation(Result, DAG);
1300 if (Tmp3.Val) {
1300 if (Tmp3.getNode()) {
13011301 Result = Tmp3;
13021302 break;
13031303 }
13431343 case ISD::CALL:
13441344 // The only option for this is to custom lower it.
13451345 Tmp3 = TLI.LowerOperation(Result.getValue(0), DAG);
1346 assert(Tmp3.Val && "Target didn't custom lower this node!");
1346 assert(Tmp3.getNode() && "Target didn't custom lower this node!");
13471347 // A call within a calling sequence must be legalized to something
13481348 // other than the normal CALLSEQ_END. Violating this gets Legalize
13491349 // into an infinite loop.
13501350 assert ((!IsLegalizingCall ||
13511351 Node->getOpcode() != ISD::CALL ||
1352 Tmp3.Val->getOpcode() != ISD::CALLSEQ_END) &&
1352 Tmp3.getNode()->getOpcode() != ISD::CALLSEQ_END) &&
13531353 "Nested CALLSEQ_START..CALLSEQ_END not supported.");
13541354
13551355 // The number of incoming and outgoing values should match; unless the final
13561356 // outgoing value is a flag.
1357 assert((Tmp3.Val->getNumValues() == Result.Val->getNumValues() ||
1358 (Tmp3.Val->getNumValues() == Result.Val->getNumValues() + 1 &&
1359 Tmp3.Val->getValueType(Tmp3.Val->getNumValues() - 1) ==
1357 assert((Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() ||
1358 (Tmp3.getNode()->getNumValues() == Result.getNode()->getNumValues() + 1 &&
1359 Tmp3.getNode()->getValueType(Tmp3.getNode()->getNumValues() - 1) ==
13601360 MVT::Flag)) &&
13611361 "Lowering call/formal_arguments produced unexpected # results!");
13621362
13631363 // Since CALL/FORMAL_ARGUMENTS nodes produce multiple values, make sure to
13641364 // remember that we legalized all of them, so it doesn't get relegalized.
1365 for (unsigned i = 0, e = Tmp3.Val->getNumValues(); i != e; ++i) {
1366 if (Tmp3.Val->getValueType(i) == MVT::Flag)
1365 for (unsigned i = 0, e = Tmp3.getNode()->getNumValues(); i != e; ++i) {
1366 if (Tmp3.getNode()->getValueType(i) == MVT::Flag)
13671367 continue;
13681368 Tmp1 = LegalizeOp(Tmp3.getValue(i));
13691369 if (Op.getResNo() == i)
13931393 default: assert(0 && "This action is not supported yet!");
13941394 case TargetLowering::Custom:
13951395 Tmp3 = TLI.LowerOperation(Result, DAG);
1396 if (Tmp3.Val) {
1396 if (Tmp3.getNode()) {
13971397 Result = Tmp3;
13981398 break;
13991399 }
14001400 // FALLTHROUGH
14011401 case TargetLowering::Expand:
1402 Result = ExpandBUILD_VECTOR(Result.Val);
1402 Result = ExpandBUILD_VECTOR(Result.getNode());
14031403 break;
14041404 }
14051405 break;
14241424 break;
14251425 case TargetLowering::Custom:
14261426 Tmp4 = TLI.LowerOperation(Result, DAG);
1427 if (Tmp4.Val) {
1427 if (Tmp4.getNode()) {
14281428 Result = Tmp4;
14291429 break;
14301430 }
14841484 break;
14851485 case TargetLowering::Custom:
14861486 Tmp3 = TLI.LowerOperation(Result, DAG);
1487 if (Tmp3.Val) {
1487 if (Tmp3.getNode()) {
14881488 Result = Tmp3;
14891489 break;
14901490 }
15081508 break;
15091509 case TargetLowering::Custom:
15101510 Tmp3 = TLI.LowerOperation(Result, DAG);
1511 if (Tmp3.Val) {
1511 if (Tmp3.getNode()) {
15121512 Result = Tmp3;
15131513 break;
15141514 }
15491549
15501550 // Convert the shuffle mask to the right # elements.
15511551 Tmp3 = SDValue(isShuffleLegal(OVT, Node->getOperand(2)), 0);
1552 assert(Tmp3.Val && "Shuffle not legal?");
1552 assert(Tmp3.getNode() && "Shuffle not legal?");
15531553 Result = DAG.getNode(ISD::VECTOR_SHUFFLE, NVT, Tmp1, Tmp2, Tmp3);
15541554 Result = DAG.getNode(ISD::BIT_CONVERT, OVT, Result);
15551555 break;
15791579 // are inserted *before* the CALLSEQ_START.
15801580 {SmallPtrSet NodesLeadingTo;
15811581 for (unsigned i = 0, e = CallEnd->getNumOperands(); i != e; ++i)
1582 LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).Val, Node,
1582 LegalizeAllNodesNotLeadingTo(CallEnd->getOperand(i).getNode(), Node,
15831583 NodesLeadingTo);
15841584 }
15851585
16231623 case ISD::CALLSEQ_END:
16241624 // If the CALLSEQ_START node hasn't been legalized first, legalize it. This
16251625 // will cause this node to be legalized as well as handling libcalls right.
1626 if (LastCALLSEQ_END.Val != Node) {
1626 if (LastCALLSEQ_END.getNode() != Node) {
16271627 LegalizeOp(SDValue(FindCallStartFromCallEnd(Node), 0));
16281628 DenseMap::iterator I = LegalizedNodes.find(Op);
16291629 assert(I != LegalizedNodes.end() &&
17071707 }
17081708 case TargetLowering::Custom:
17091709 Tmp3 = TLI.LowerOperation(Tmp1, DAG);
1710 if (Tmp3.Val) {
1710 if (Tmp3.getNode()) {
17111711 Tmp1 = LegalizeOp(Tmp3);
17121712 Tmp2 = LegalizeOp(Tmp3.getValue(1));
17131713 }
17961796 case TargetLowering::Legal: break;
17971797 case TargetLowering::Custom:
17981798 Tmp1 = TLI.LowerOperation(Result, DAG);
1799 if (Tmp1.Val) Result = Tmp1;
1799 if (Tmp1.getNode()) Result = Tmp1;
18001800 break;
18011801 case TargetLowering::Expand: {
18021802 SDValue Chain = Result.getOperand(0);
18651865 case TargetLowering::Legal: break;
18661866 case TargetLowering::Custom:
18671867 Tmp1 = TLI.LowerOperation(Result, DAG);
1868 if (Tmp1.Val) Result = Tmp1;
1868 if (Tmp1.getNode()) Result = Tmp1;
18691869 break;
18701870 case TargetLowering::Expand:
18711871 // Expand brcond's setcc into its constituent parts and create a BR_CC
18981898 // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands,
18991899 // the LHS is a legal SETCC itself. In this case, we need to compare
19001900 // the result against zero to select between true and false values.
1901 if (Tmp3.Val == 0) {
1901 if (Tmp3.getNode() == 0) {
19021902 Tmp3 = DAG.getConstant(0, Tmp2.getValueType());
19031903 Tmp4 = DAG.getCondCode(ISD::SETNE);
19041904 }
19111911 case TargetLowering::Legal: break;
19121912 case TargetLowering::Custom:
19131913 Tmp4 = TLI.LowerOperation(Result, DAG);
1914 if (Tmp4.Val) Result = Tmp4;
1914 if (Tmp4.getNode()) Result = Tmp4;
19151915 break;
19161916 }
19171917 break;
19361936 unsigned ABIAlignment = TLI.getTargetData()->
19371937 getABITypeAlignment(LD->getMemoryVT().getTypeForMVT());
19381938 if (LD->getAlignment() < ABIAlignment){
1939 Result = ExpandUnalignedLoad(cast(Result.Val), DAG,
1939 Result = ExpandUnalignedLoad(cast(Result.getNode()), DAG,
19401940 TLI);
19411941 Tmp3 = Result.getOperand(0);
19421942 Tmp4 = Result.getOperand(1);
19471947 break;
19481948 case TargetLowering::Custom:
19491949 Tmp1 = TLI.LowerOperation(Tmp3, DAG);
1950 if (Tmp1.Val) {
1950 if (Tmp1.getNode()) {
19511951 Tmp3 = LegalizeOp(Tmp1);
19521952 Tmp4 = LegalizeOp(Tmp1.getValue(1));
19531953 }
21042104
21052105 if (isCustom) {
21062106 Tmp3 = TLI.LowerOperation(Result, DAG);
2107 if (Tmp3.Val) {
2107 if (Tmp3.getNode()) {
21082108 Tmp1 = LegalizeOp(Tmp3);
21092109 Tmp2 = LegalizeOp(Tmp3.getValue(1));
21102110 }
21152115 unsigned ABIAlignment = TLI.getTargetData()->
21162116 getABITypeAlignment(LD->getMemoryVT().getTypeForMVT());
21172117 if (LD->getAlignment() < ABIAlignment){
2118 Result = ExpandUnalignedLoad(cast(Result.Val), DAG,
2118 Result = ExpandUnalignedLoad(cast(Result.getNode()), DAG,
21192119 TLI);
21202120 Tmp1 = Result.getOperand(0);
21212121 Tmp2 = Result.getOperand(1);
22432243 if (TLI.isBigEndian())
22442244 std::swap(Lo, Hi);
22452245
2246 if (Hi.Val)
2246 if (Hi.getNode())
22472247 Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3, Hi,Tmp3);
22482248 else
22492249 Result = DAG.getNode(ISD::RET, MVT::Other, Tmp1, Lo, Tmp3);
22502250 Result = LegalizeOp(Result);
22512251 } else {
2252 SDNode *InVal = Tmp2.Val;
2252 SDNode *InVal = Tmp2.getNode();
22532253 int InIx = Tmp2.getResNo();
22542254 unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements();
22552255 MVT EVT = InVal->getValueType(InIx).getVectorElementType();
23092309 ExpandOp(Node->getOperand(i), Lo, Hi);
23102310 NewValues.push_back(Lo);
23112311 NewValues.push_back(Node->getOperand(i+1));
2312 if (Hi.Val) {
2312 if (Hi.getNode()) {
23132313 NewValues.push_back(Hi);
23142314 NewValues.push_back(Node->getOperand(i+1));
23152315 }
23342334 case TargetLowering::Legal: break;
23352335 case TargetLowering::Custom:
23362336 Tmp1 = TLI.LowerOperation(Result, DAG);
2337 if (Tmp1.Val) Result = Tmp1;
2337 if (Tmp1.getNode()) Result = Tmp1;
23382338 break;
23392339 }
23402340 }
24102410 unsigned ABIAlignment = TLI.getTargetData()->
24112411 getABITypeAlignment(ST->getMemoryVT().getTypeForMVT());
24122412 if (ST->getAlignment() < ABIAlignment)
2413 Result = ExpandUnalignedStore(cast(Result.Val), DAG,
2413 Result = ExpandUnalignedStore(cast(Result.getNode()), DAG,
24142414 TLI);
24152415 }
24162416 break;
24172417 case TargetLowering::Custom:
24182418 Tmp1 = TLI.LowerOperation(Result, DAG);
2419 if (Tmp1.Val) Result = Tmp1;
2419 if (Tmp1.getNode()) Result = Tmp1;
24202420 break;
24212421 case TargetLowering::Promote:
24222422 assert(VT.isVector() && "Unknown legal promote case!");
24452445 // the product of the element size in bytes, and the number of elements
24462446 // in the high half of the vector.
24472447 if (ST->getValue().getValueType().isVector()) {
2448 SDNode *InVal = ST->getValue().Val;
2448 SDNode *InVal = ST->getValue().getNode();
24492449 int InIx = ST->getValue().getResNo();
24502450 MVT InVT = InVal->getValueType(InIx);
24512451 unsigned NumElems = InVT.getVectorNumElements();
24722472 break;
24732473 } else {
24742474 SplitVectorOp(ST->getValue(), Lo, Hi);
2475 IncrementSize = Lo.Val->getValueType(0).getVectorNumElements() *
2475 IncrementSize = Lo.getNode()->getValueType(0).getVectorNumElements() *
24762476 EVT.getSizeInBits()/8;
24772477 }
24782478 } else {
24792479 ExpandOp(ST->getValue(), Lo, Hi);
2480 IncrementSize = Hi.Val ? Hi.getValueType().getSizeInBits()/8 : 0;
2480 IncrementSize = Hi.getNode() ? Hi.getValueType().getSizeInBits()/8 : 0;
24812481
24822482 if (TLI.isBigEndian())
24832483 std::swap(Lo, Hi);
24862486 Lo = DAG.getStore(Tmp1, Lo, Tmp2, ST->getSrcValue(),
24872487 SVOffset, isVolatile, Alignment);
24882488
2489 if (Hi.Val == NULL) {
2489 if (Hi.getNode() == NULL) {
24902490 // Must be int <-> float one-to-one expansion.
24912491 Result = Lo;
24922492 break;
25972597 unsigned ABIAlignment = TLI.getTargetData()->
25982598 getABITypeAlignment(ST->getMemoryVT().getTypeForMVT());
25992599 if (ST->getAlignment() < ABIAlignment)
2600 Result = ExpandUnalignedStore(cast(Result.Val), DAG,
2600 Result = ExpandUnalignedStore(cast(Result.getNode()), DAG,
26012601 TLI);
26022602 }
26032603 break;
26312631 case TargetLowering::Legal: break;
26322632 case TargetLowering::Custom:
26332633 Tmp3 = TLI.LowerOperation(Result, DAG);
2634 if (Tmp3.Val) {
2634 if (Tmp3.getNode()) {
26352635 Tmp1 = LegalizeOp(Tmp3);
26362636 Tmp2 = LegalizeOp(Tmp3.getValue(1));
26372637 }
26662666 case TargetLowering::Legal: break;
26672667 case TargetLowering::Custom:
26682668 Tmp1 = TLI.LowerOperation(Result, DAG);
2669 if (Tmp1.Val) Result = Tmp1;
2669 if (Tmp1.getNode()) Result = Tmp1;
26702670 break;
26712671 case TargetLowering::Expand:
26722672 // Expand to CopyToReg if the target set
27292729 case TargetLowering::Legal: break;
27302730 case TargetLowering::Custom: {
27312731 Tmp1 = TLI.LowerOperation(Result, DAG);
2732 if (Tmp1.Val) Result = Tmp1;
2732 if (Tmp1.getNode()) Result = Tmp1;
27332733 break;
27342734 }
27352735 case TargetLowering::Expand:
27832783 // If we didn't get both a LHS and RHS back from LegalizeSetCCOperands,
27842784 // the LHS is a legal SETCC itself. In this case, we need to compare
27852785 // the result against zero to select between true and false values.
2786 if (Tmp2.Val == 0) {
2786 if (Tmp2.getNode() == 0) {
27872787 Tmp2 = DAG.getConstant(0, Tmp1.getValueType());
27882788 CC = DAG.getCondCode(ISD::SETNE);
27892789 }
27952795 case TargetLowering::Legal: break;
27962796 case TargetLowering::Custom:
27972797 Tmp1 = TLI.LowerOperation(Result, DAG);
2798 if (Tmp1.Val) Result = Tmp1;
2798 if (Tmp1.getNode()) Result = Tmp1;
27992799 break;
28002800 }
28012801 break;
28092809 // If we had to Expand the SetCC operands into a SELECT node, then it may
28102810 // not always be possible to return a true LHS & RHS. In this case, just
28112811 // return the value we legalized, returned in the LHS
2812 if (Tmp2.Val == 0) {
2812 if (Tmp2.getNode() == 0) {
28132813 Result = Tmp1;
28142814 break;
28152815 }
28232823 Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Tmp3);
28242824 if (isCustom) {
28252825 Tmp4 = TLI.LowerOperation(Result, DAG);
2826 if (Tmp4.Val) Result = Tmp4;
2826 if (Tmp4.getNode()) Result = Tmp4;
28272827 }
28282828 break;
28292829 case TargetLowering::Promote: {
28812881 case TargetLowering::Legal: break;
28822882 case TargetLowering::Custom:
28832883 Tmp1 = TLI.LowerOperation(Result, DAG);
2884 if (Tmp1.Val) Result = Tmp1;
2884 if (Tmp1.getNode()) Result = Tmp1;
28852885 break;
28862886 }
28872887 break;
29052905 case TargetLowering::Legal: break;
29062906 case TargetLowering::Custom:
29072907 Tmp1 = TLI.LowerOperation(Result, DAG);
2908 if (Tmp1.Val) {
2908 if (Tmp1.getNode()) {
29092909 SDValue Tmp2, RetVal(0, 0);
29102910 for (unsigned i = 0, e = Node->getNumValues(); i != e; ++i) {
29112911 Tmp2 = LegalizeOp(Tmp1.getValue(i));
29132913 if (i == Op.getResNo())
29142914 RetVal = Tmp2;
29152915 }
2916 assert(RetVal.Val && "Illegal result number");
2916 assert(RetVal.getNode() && "Illegal result number");
29172917 return RetVal;
29182918 }
29192919 break;
29732973 case TargetLowering::Legal: break;
29742974 case TargetLowering::Custom:
29752975 Tmp1 = TLI.LowerOperation(Result, DAG);
2976 if (Tmp1.Val) {
2976 if (Tmp1.getNode()) {
29772977 Result = Tmp1;
29782978 break;
29792979 }
30033003 OpToUse = ISD::UMUL_LOHI;
30043004 }
30053005 if (OpToUse) {
3006 Result = SDValue(DAG.getNode(OpToUse, VTs, Tmp1, Tmp2).Val, 0);
3006 Result = SDValue(DAG.getNode(OpToUse, VTs, Tmp1, Tmp2).getNode(), 0);
30073007 break;
30083008 }
30093009 }
30103010 if (Node->getOpcode() == ISD::MULHS &&
30113011 TLI.isOperationLegal(ISD::SMUL_LOHI, VT)) {
3012 Result = SDValue(DAG.getNode(ISD::SMUL_LOHI, VTs, Tmp1, Tmp2).Val, 1);
3012 Result = SDValue(DAG.getNode(ISD::SMUL_LOHI, VTs, Tmp1, Tmp2).getNode(), 1);
30133013 break;
30143014 }
30153015 if (Node->getOpcode() == ISD::MULHU &&
30163016 TLI.isOperationLegal(ISD::UMUL_LOHI, VT)) {
3017 Result = SDValue(DAG.getNode(ISD::UMUL_LOHI, VTs, Tmp1, Tmp2).Val, 1);
3017 Result = SDValue(DAG.getNode(ISD::UMUL_LOHI, VTs, Tmp1, Tmp2).getNode(), 1);
30183018 break;
30193019 }
30203020 if (Node->getOpcode() == ISD::SDIV &&
30213021 TLI.isOperationLegal(ISD::SDIVREM, VT)) {
3022 Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).Val, 0);
3022 Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).getNode(), 0);
30233023 break;
30243024 }
30253025 if (Node->getOpcode() == ISD::UDIV &&
30263026 TLI.isOperationLegal(ISD::UDIVREM, VT)) {
3027 Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).Val, 0);
3027 Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).getNode(), 0);
30283028 break;
30293029 }
30303030
31123112 default: assert(0 && "Operation not supported");
31133113 case TargetLowering::Custom:
31143114 Tmp1 = TLI.LowerOperation(Result, DAG);
3115 if (Tmp1.Val) Result = Tmp1;
3115 if (Tmp1.getNode()) Result = Tmp1;
31163116 break;
31173117 case TargetLowering::Legal: break;
31183118 case TargetLowering::Expand: {
32153215 Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2);
32163216 if (isCustom) {
32173217 Tmp1 = TLI.LowerOperation(Result, DAG);
3218 if (Tmp1.Val) Result = Tmp1;
3218 if (Tmp1.getNode()) Result = Tmp1;
32193219 }
32203220 break;
32213221 case TargetLowering::Expand: {
32273227 SDVTList VTs = DAG.getVTList(VT, VT);
32283228 if (Node->getOpcode() == ISD::SREM &&
32293229 TLI.isOperationLegal(ISD::SDIVREM, VT)) {
3230 Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).Val, 1);
3230 Result = SDValue(DAG.getNode(ISD::SDIVREM, VTs, Tmp1, Tmp2).getNode(), 1);
32313231 break;
32323232 }
32333233 if (Node->getOpcode() == ISD::UREM &&
32343234 TLI.isOperationLegal(ISD::UDIVREM, VT)) {
3235 Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).Val, 1);
3235 Result = SDValue(DAG.getNode(ISD::UDIVREM, VTs, Tmp1, Tmp2).getNode(), 1);
32363236 break;
32373237 }
32383238
32873287
32883288 if (isCustom) {
32893289 Tmp2 = TLI.LowerOperation(Result, DAG);
3290 if (Tmp2.Val) {
3290 if (Tmp2.getNode()) {
32913291 Result = LegalizeOp(Tmp2);
32923292 Tmp1 = LegalizeOp(Tmp2.getValue(1));
32933293 }
33313331 Node->getOperand(3), Node->getOperand(4));
33323332 if (isCustom) {
33333333 Tmp1 = TLI.LowerOperation(Result, DAG);
3334 if (Tmp1.Val) Result = Tmp1;
3334 if (Tmp1.getNode()) Result = Tmp1;
33353335 }
33363336 break;
33373337 case TargetLowering::Expand:
33583358 Result = DAG.UpdateNodeOperands(Result, Tmp1, Tmp2, Node->getOperand(2));
33593359 if (isCustom) {
33603360 Tmp1 = TLI.LowerOperation(Tmp1, DAG);
3361 if (Tmp1.Val) Result = Tmp1;
3361 if (Tmp1.getNode()) Result = Tmp1;
33623362 }
33633363 break;
33643364 case TargetLowering::Expand:
33783378 case TargetLowering::Legal: break;
33793379 case TargetLowering::Custom:
33803380 Tmp1 = TLI.LowerOperation(Result, DAG);
3381 if (Tmp1.Val) Result = Tmp1;
3381 if (Tmp1.getNode()) Result = Tmp1;
33823382 break;
33833383 }
33843384 break;
33963396 break;
33973397 case TargetLowering::Custom:
33983398 Tmp1 = TLI.LowerOperation(Result, DAG);
3399 if (Tmp1.Val) Result = Tmp1;
3399 if (Tmp1.getNode()) Result = Tmp1;
34003400 break;
34013401 case TargetLowering::Promote:
34023402 assert(0 && "Do not know how to promote ROTL/ROTR");
34433443 if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) ==
34443444 TargetLowering::Custom) {
34453445 Tmp1 = TLI.LowerOperation(Result, DAG);
3446 if (Tmp1.Val) {
3446 if (Tmp1.getNode()) {
34473447 Result = Tmp1;
34483448 }
34493449 }
35043504 Result = DAG.UpdateNodeOperands(Result, Tmp1);
35053505 if (isCustom) {
35063506 Tmp1 = TLI.LowerOperation(Result, DAG);
3507 if (Tmp1.Val) Result = Tmp1;
3507 if (Tmp1.getNode()) Result = Tmp1;
35083508 }
35093509 break;
35103510 case TargetLowering::Expand:
36083608 } else if (Op.getOperand(0).getValueType().isVector()) {
36093609 // The input has to be a vector type, we have to either scalarize it, pack
36103610 // it, or convert it based on whether the input vector type is legal.
3611 SDNode *InVal = Node->getOperand(0).Val;
3611 SDNode *InVal = Node->getOperand(0).getNode();
36123612 int InIx = Node->getOperand(0).getResNo();
36133613 unsigned NumElems = InVal->getValueType(InIx).getVectorNumElements();
36143614 MVT EVT = InVal->getValueType(InIx).getVectorElementType();
36893689 Result = DAG.UpdateNodeOperands(Result, Tmp1);
36903690 if (isCustom) {
36913691 Tmp1 = TLI.LowerOperation(Result, DAG);
3692 if (Tmp1.Val) Result = Tmp1;
3692 if (Tmp1.getNode()) Result = Tmp1;
36933693 }
36943694 break;
36953695 case TargetLowering::Promote:
38313831 if (TLI.getOperationAction(Node->getOpcode(), Node->getValueType(0)) ==
38323832 TargetLowering::Custom) {
38333833 Tmp1 = TLI.LowerOperation(Result, DAG);
3834 if (Tmp1.Val) Result = Tmp1;
3834 if (Tmp1.getNode()) Result = Tmp1;
38353835 }
38363836 break;
38373837 case Promote:
39033903 Result = DAG.UpdateNodeOperands(Result, Ops, 6);
39043904 // The only option for this node is to custom lower it.
39053905 Result = TLI.LowerOperation(Result, DAG);
3906 assert(Result.Val && "Should always custom lower!");
3906 assert(Result.getNode() && "Should always custom lower!");
39073907
39083908 // Since trampoline produces two values, make sure to remember that we
39093909 // legalized both of them.
39193919 default: assert(0 && "This action not supported for this op yet!");
39203920 case TargetLowering::Custom:
39213921 Result = TLI.LowerOperation(Op, DAG);
3922 if (Result.Val) break;
3922 if (Result.getNode()) break;
39233923 // Fall Thru
39243924 case TargetLowering::Legal:
39253925 // If this operation is not supported, lower it to constant 1
39383938 break;
39393939 case TargetLowering::Custom:
39403940 Result = TLI.LowerOperation(Op, DAG);
3941 if (Result.Val) break;
3941 if (Result.getNode()) break;
39423942 // Fall Thru
39433943 case TargetLowering::Expand:
39443944 // If this operation is not supported, lower it to 'abort()' call
39833983
39843984 SDValue Tmp1, Tmp2, Tmp3;
39853985 SDValue Result;
3986 SDNode *Node = Op.Val;
3986 SDNode *Node = Op.getNode();
39873987
39883988 DenseMap::iterator I = PromotedNodes.find(Op);
39893989 if (I != PromotedNodes.end()) return I->second;
44604460 break;
44614461 }
44624462
4463 assert(Result.Val && "Didn't set a result!");
4463 assert(Result.getNode() && "Didn't set a result!");
44644464
44654465 // Make sure the result is itself legal.
44664466 Result = LegalizeOp(Result);
44904490 Vec = LegalizeOp(Vec);
44914491 Op = DAG.UpdateNodeOperands(Op, Vec, Idx);
44924492 SDValue Tmp3 = TLI.LowerOperation(Op, DAG);
4493 if (Tmp3.Val)
4493 if (Tmp3.getNode())
44944494 return Tmp3;
44954495 break;
44964496 }
46964696
46974697 SDValue Dummy;
46984698 SDValue Ops[2] = { LHS, RHS };
4699 Tmp1 = ExpandLibCall(LC1, DAG.getMergeValues(Ops, 2).Val,
4699 Tmp1 = ExpandLibCall(LC1, DAG.getMergeValues(Ops, 2).getNode(),
47004700 false /*sign irrelevant*/, Dummy);
47014701 Tmp2 = DAG.getConstant(0, MVT::i32);
47024702 CC = DAG.getCondCode(TLI.getCmpLibcallCC(LC1));
47034703 if (LC2 != RTLIB::UNKNOWN_LIBCALL) {
47044704 Tmp1 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(Tmp1), Tmp1, Tmp2,
47054705 CC);
4706 LHS = ExpandLibCall(LC2, DAG.getMergeValues(Ops, 2).Val,
4706 LHS = ExpandLibCall(LC2, DAG.getMergeValues(Ops, 2).getNode(),
47074707 false /*sign irrelevant*/, Dummy);
47084708 Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(LHS), LHS, Tmp2,
47094709 DAG.getCondCode(TLI.getCmpLibcallCC(LC2)));
47904790 TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL);
47914791 Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo,
47924792 LowCC, false, DagCombineInfo);
4793 if (!Tmp1.Val)
4793 if (!Tmp1.getNode())
47944794 Tmp1 = DAG.getSetCC(TLI.getSetCCResultType(LHSLo), LHSLo, RHSLo, LowCC);
47954795 Tmp2 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi,
47964796 CCCode, false, DagCombineInfo);
4797 if (!Tmp2.Val)
4797 if (!Tmp2.getNode())
47984798 Tmp2 = DAG.getNode(ISD::SETCC, TLI.getSetCCResultType(LHSHi), LHSHi,
47994799 RHSHi,CC);
48004800
4801 ConstantSDNode *Tmp1C = dyn_cast(Tmp1.Val);
4802 ConstantSDNode *Tmp2C = dyn_cast(Tmp2.Val);
4801 ConstantSDNode *Tmp1C = dyn_cast(Tmp1.getNode());
4802 ConstantSDNode *Tmp2C = dyn_cast(Tmp2.getNode());
48034803 if ((Tmp1C && Tmp1C->isNullValue()) ||
48044804 (Tmp2C && Tmp2C->isNullValue() &&
48054805 (CCCode == ISD::SETLE || CCCode == ISD::SETGE ||
48154815 } else {
48164816 Result = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi,
48174817 ISD::SETEQ, false, DagCombineInfo);
4818 if (!Result.Val)
4818 if (!Result.getNode())
48194819 Result=DAG.getSetCC(TLI.getSetCCResultType(LHSHi), LHSHi, RHSHi,
48204820 ISD::SETEQ);
48214821 Result = LegalizeOp(DAG.getNode(ISD::SELECT, Tmp1.getValueType(),
49574957 PseudoSourceValue::getConstantPool(), 0);
49584958 }
49594959
4960 if (SplatValue.Val) { // Splat of one value?
4960 if (SplatValue.getNode()) { // Splat of one value?
49614961 // Build the shuffle constant vector: <0, 0, 0, 0>
49624962 MVT MaskVT = MVT::getIntVectorWithNumElements(NumElems);
49634963 SDValue Zero = DAG.getConstant(0, MaskVT.getVectorElementType());
50945094 unsigned NVTBits = NVT.getSizeInBits();
50955095
50965096 // Handle the case when Amt is an immediate.
5097 if (ConstantSDNode *CN = dyn_cast(Amt.Val)) {
5097 if (ConstantSDNode *CN = dyn_cast(Amt.getNode())) {
50985098 unsigned Cst = CN->getValue();
50995099 // Expand the incoming operand to be shifted, so that we have its parts
51005100 SDValue InL, InH;
52915291 // FALLTHROUGH
52925292 case TargetLowering::Legal:
52935293 Tmp1 = LegalizeOp(Op);
5294 if (Result.Val)
5294 if (Result.getNode())
52955295 Result = DAG.UpdateNodeOperands(Result, Tmp1);
52965296 else
52975297 Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP,
52985298 DestTy, Tmp1);
52995299 if (isCustom) {
53005300 Tmp1 = TLI.LowerOperation(Result, DAG);
5301 if (Tmp1.Val) Result = Tmp1;
5301 if (Tmp1.getNode()) Result = Tmp1;
53025302 }
53035303 break;
53045304 case TargetLowering::Expand:
53215321 Tmp1 = DAG.getZeroExtendInReg(Tmp1,
53225322 Op.getValueType());
53235323 }
5324 if (Result.Val)
5324 if (Result.getNode())
53255325 Result = DAG.UpdateNodeOperands(Result, Tmp1);
53265326 else
53275327 Result = DAG.getNode(isSigned ? ISD::SINT_TO_FP : ISD::UINT_TO_FP,
54265426 case TargetLowering::Custom: {
54275427 SDValue NV = TLI.LowerOperation(DAG.getNode(ISD::SINT_TO_FP, DestTy,
54285428 Source), DAG);
5429 if (NV.Val)
5429 if (NV.getNode())
54305430 return LegalizeOp(NV);
54315431 break; // The target decided this was legal after all
54325432 }
54475447
54485448 Source = DAG.getNode(ISD::SINT_TO_FP, DestTy, Source);
54495449 SDValue HiPart;
5450 SDValue Result = ExpandLibCall(LC, Source.Val, isSigned, HiPart);
5451 if (Result.getValueType() != DestTy && HiPart.Val)
5450 SDValue Result = ExpandLibCall(LC, Source.getNode(), isSigned, HiPart);
5451 if (Result.getValueType() != DestTy && HiPart.getNode())
54525452 Result = DAG.getNode(ISD::BUILD_PAIR, DestTy, Result, HiPart);
54535453 return Result;
54545454 }
56645664 // the target lowering hooks to expand it. Just keep the low part of the
56655665 // expanded operation, we know that we're truncating anyway.
56665666 if (getTypeAction(NewOutTy) == Expand) {
5667 Operation = SDValue(TLI.ReplaceNodeResults(Operation.Val, DAG), 0);
5668 assert(Operation.Val && "Didn't return anything");
5667 Operation = SDValue(TLI.ReplaceNodeResults(Operation.getNode(), DAG), 0);
5668 assert(Operation.getNode() && "Didn't return anything");
56695669 }
56705670
56715671 // Truncate the result of the extended FP_TO_*INT operation to the desired
57935793 void SelectionDAGLegalize::ExpandOp(SDValue Op, SDValue &Lo, SDValue &Hi){
57945794 MVT VT = Op.getValueType();
57955795 MVT NVT = TLI.getTypeToTransformTo(VT);
5796 SDNode *Node = Op.Val;
5796 SDNode *Node = Op.getNode();
57975797 assert(getTypeAction(VT) == Expand && "Not an expanded type!");
57985798 assert(((NVT.isInteger() && NVT.bitsLT(VT)) || VT.isFloatingPoint() ||
57995799 VT.isVector()) && "Cannot expand to FP value or to larger int value!");
58195819 Src = DAG.getNode(ISD::BUILD_PAIR, VT, SrcLo, SrcHi);
58205820 SDValue Result = TLI.LowerOperation(
58215821 DAG.getNode(ISD::FP_ROUND_INREG, VT, Src, Op.getOperand(1)), DAG);
5822 assert(Result.Val->getOpcode() == ISD::BUILD_PAIR);
5823 Lo = Result.Val->getOperand(0);
5824 Hi = Result.Val->getOperand(1);
5822 assert(Result.getNode()->getOpcode() == ISD::BUILD_PAIR);
5823 Lo = Result.getNode()->getOperand(0);
5824 Hi = Result.getNode()->getOperand(1);
58255825 break;
58265826 }
58275827 // fall through
61446144 }
61456145
61466146 // Turn this into a load/store pair by default.
6147 if (Tmp.Val == 0)
6147 if (Tmp.getNode() == 0)
61486148 Tmp = EmitStackConvert(Node->getOperand(0), VT, VT);
61496149
61506150 ExpandOp(Tmp, Lo, Hi);
61566156 TargetLowering::Custom &&
61576157 "Must custom expand ReadCycleCounter");
61586158 SDValue Tmp = TLI.LowerOperation(Op, DAG);
6159 assert(Tmp.Val && "Node must be custom expanded!");
6159 assert(Tmp.getNode() && "Node must be custom expanded!");
61606160 ExpandOp(Tmp.getValue(0), Lo, Hi);
61616161 AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain.
61626162 LegalizeOp(Tmp.getValue(1)));
61696169 case ISD::ATOMIC_CMP_SWAP_32:
61706170 case ISD::ATOMIC_CMP_SWAP_64: {
61716171 SDValue Tmp = TLI.LowerOperation(Op, DAG);
6172 assert(Tmp.Val && "Node must be custom expanded!");
6172 assert(Tmp.getNode() && "Node must be custom expanded!");
61736173 ExpandOp(Tmp.getValue(0), Lo, Hi);
61746174 AddLegalizedOperand(SDValue(Node, 1), // Remember we legalized the chain.
61756175 LegalizeOp(Tmp.getValue(1)));
61936193
61946194 // Now that the custom expander is done, expand the result, which is still
61956195 // VT.
6196 if (Op.Val) {
6196 if (Op.getNode()) {
61976197 ExpandOp(Op, Lo, Hi);
61986198 break;
61996199 }
62186218 Op = TLI.LowerOperation(DAG.getNode(ISD::FP_TO_UINT, VT, Op), DAG);
62196219
62206220 // Now that the custom expander is done, expand the result.
6221 if (Op.Val) {
6221 if (Op.getNode()) {
62226222 ExpandOp(Op, Lo, Hi);
62236223 break;
62246224 }
62376237 if (TLI.getOperationAction(ISD::SHL, VT) == TargetLowering::Custom) {
62386238 SDValue Op = DAG.getNode(ISD::SHL, VT, Node->getOperand(0), ShiftAmt);
62396239 Op = TLI.LowerOperation(Op, DAG);
6240 if (Op.Val) {
6240 if (Op.getNode()) {
62416241 // Now that the custom expander is done, expand the result, which is
62426242 // still VT.
62436243 ExpandOp(Op, Lo, Hi);
62876287 if (TLI.getOperationAction(ISD::SRA, VT) == TargetLowering::Custom) {
62886288 SDValue Op = DAG.getNode(ISD::SRA, VT, Node->getOperand(0), ShiftAmt);
62896289 Op = TLI.LowerOperation(Op, DAG);
6290 if (Op.Val) {
6290 if (Op.getNode()) {