From 7a4d0b9a1047b859d6af346e473437576d2790ba Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 15 Dec 2018 01:07:16 +0000 Subject: [PATCH] [X86] Make hasNoCarryFlagUses/hasNoSignedComparisonUses take an SDValue that indicates which result is the flag result. NFCI hasNoCarryFlagUses hardcoded that the flag result is 1 and used that to filter which uses were of interest. hasNoSignedComparisonUses just assumes the only result is flags and checks whether any user of the node is a CopyToReg instruction. After this patch we now do a result number check in both and rely on the caller to provide the result number. This shouldn't change behavior it was just an odd difference between the two functions that I noticed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349222 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ISelDAGToDAG.cpp | 39 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp index ba8a8a8035e..67de43ec492 100644 --- a/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -2193,16 +2193,16 @@ bool X86DAGToDAGISel::isSExtAbsoluteSymbolRef(unsigned Width, SDNode *N) const { /// Test whether the given X86ISD::CMP node has any uses which require the SF /// or OF bits to be accurate. -static bool hasNoSignedComparisonUses(SDNode *N) { +static bool hasNoSignedComparisonUses(SDValue Flags) { // Examine each user of the node. - for (SDNode::use_iterator UI = N->use_begin(), - UE = N->use_end(); UI != UE; ++UI) { - // Only examine CopyToReg uses. - if (UI->getOpcode() != ISD::CopyToReg) - return false; + for (SDNode::use_iterator UI = Flags->use_begin(), UE = Flags->use_end(); + UI != UE; ++UI) { + // Only check things that use the flags. + if (UI.getUse().getResNo() != Flags.getResNo()) + continue; // Only examine CopyToReg uses that copy to EFLAGS. - if (cast(UI->getOperand(1))->getReg() != - X86::EFLAGS) + if (UI->getOpcode() != ISD::CopyToReg || + cast(UI->getOperand(1))->getReg() != X86::EFLAGS) return false; // Examine each user of the CopyToReg use. for (SDNode::use_iterator FlagUI = UI->use_begin(), @@ -2255,18 +2255,16 @@ static bool hasNoSignedComparisonUses(SDNode *N) { /// Test whether the given node which sets flags has any uses which require the /// CF flag to be accurate. -static bool hasNoCarryFlagUses(SDNode *N) { +static bool hasNoCarryFlagUses(SDValue Flags) { // Examine each user of the node. - for (SDNode::use_iterator UI = N->use_begin(), UE = N->use_end(); UI != UE; - ++UI) { + for (SDNode::use_iterator UI = Flags->use_begin(), UE = Flags->use_end(); + UI != UE; ++UI) { // Only check things that use the flags. - if (UI.getUse().getResNo() != 1) + if (UI.getUse().getResNo() != Flags.getResNo()) continue; - // Only examine CopyToReg uses. - if (UI->getOpcode() != ISD::CopyToReg) - return false; // Only examine CopyToReg uses that copy to EFLAGS. - if (cast(UI->getOperand(1))->getReg() != X86::EFLAGS) + if (UI->getOpcode() != ISD::CopyToReg || + cast(UI->getOperand(1))->getReg() != X86::EFLAGS) return false; // Examine each user of the CopyToReg use. for (SDNode::use_iterator FlagUI = UI->use_begin(), FlagUE = UI->use_end(); @@ -2631,7 +2629,7 @@ bool X86DAGToDAGISel::foldLoadStoreIntoMemOperand(SDNode *Node) { (-OperandV).getMinSignedBits() <= 8) || (MemVT == MVT::i64 && OperandV.getMinSignedBits() > 32 && (-OperandV).getMinSignedBits() <= 32)) && - hasNoCarryFlagUses(StoredVal.getNode())) { + hasNoCarryFlagUses(StoredVal.getValue(1))) { OperandV = -OperandV; Opc = Opc == X86ISD::ADD ? X86ISD::SUB : X86ISD::ADD; } @@ -3717,7 +3715,7 @@ void X86DAGToDAGISel::Select(SDNode *Node) { if (isUInt<8>(Mask) && (!(Mask & 0x80) || CmpVT == MVT::i8 || - hasNoSignedComparisonUses(Node))) { + hasNoSignedComparisonUses(SDValue(Node, 0)))) { // For example, convert "testl %eax, $8" to "testb %al, $8" VT = MVT::i8; SubRegOp = X86::sub_8bit; @@ -3725,7 +3723,7 @@ void X86DAGToDAGISel::Select(SDNode *Node) { MOpc = X86::TEST8mi; } else if (OptForMinSize && isUInt<16>(Mask) && (!(Mask & 0x8000) || CmpVT == MVT::i16 || - hasNoSignedComparisonUses(Node))) { + hasNoSignedComparisonUses(SDValue(Node, 0)))) { // For example, "testl %eax, $32776" to "testw %ax, $32776". // NOTE: We only want to form TESTW instructions if optimizing for // min size. Otherwise we only save one byte and possibly get a length @@ -3739,7 +3737,8 @@ void X86DAGToDAGISel::Select(SDNode *Node) { // Without minsize 16-bit Cmps can get here so we need to // be sure we calculate the correct sign flag if needed. (CmpVT != MVT::i16 || !(Mask & 0x8000))) || - CmpVT == MVT::i32 || hasNoSignedComparisonUses(Node))) { + CmpVT == MVT::i32 || + hasNoSignedComparisonUses(SDValue(Node, 0)))) { // For example, "testq %rax, $268468232" to "testl %eax, $268468232". // NOTE: We only want to run that transform if N0 is 32 or 64 bits. // Otherwize, we find ourselves in a position where we have to do -- 2.11.0