1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[SelectionDAG] Add a OPC_CheckChild2CondCode to SelectionDAGISel to remove a MoveChild and MoveParent pair.

OPC_CheckCondCode is always used as operand 2 of a setcc. And its always surrounded by a MoveChild2 and a MoveParent. By having a dedicated opcode for this case we can reduce the number of bytes needed for this pattern from 4 bytes to 2.

This saves ~3000 bytes in the X86 table.

llvm-svn: 354763
This commit is contained in:
Craig Topper 2019-02-25 03:11:44 +00:00
parent 0eb8d477e2
commit b506464ecb
6 changed files with 55 additions and 3 deletions

View File

@ -143,7 +143,7 @@ public:
OPC_CheckInteger,
OPC_CheckChild0Integer, OPC_CheckChild1Integer, OPC_CheckChild2Integer,
OPC_CheckChild3Integer, OPC_CheckChild4Integer,
OPC_CheckCondCode,
OPC_CheckCondCode, OPC_CheckChild2CondCode,
OPC_CheckValueType,
OPC_CheckComplexPat,
OPC_CheckAndImm, OPC_CheckOrImm,

View File

@ -2756,6 +2756,14 @@ CheckCondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
(ISD::CondCode)MatcherTable[MatcherIndex++];
}
LLVM_ATTRIBUTE_ALWAYS_INLINE static inline bool
CheckChild2CondCode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
SDValue N) {
if (2 >= N.getNumOperands())
return false;
return ::CheckCondCode(MatcherTable, MatcherIndex, N.getOperand(2));
}
LLVM_ATTRIBUTE_ALWAYS_INLINE static inline bool
CheckValueType(const unsigned char *MatcherTable, unsigned &MatcherIndex,
SDValue N, const TargetLowering *TLI, const DataLayout &DL) {
@ -2871,6 +2879,9 @@ static unsigned IsPredicateKnownToFail(const unsigned char *Table,
case SelectionDAGISel::OPC_CheckCondCode:
Result = !::CheckCondCode(Table, Index, N);
return Index;
case SelectionDAGISel::OPC_CheckChild2CondCode:
Result = !::CheckChild2CondCode(Table, Index, N);
return Index;
case SelectionDAGISel::OPC_CheckValueType:
Result = !::CheckValueType(Table, Index, N, SDISel.TLI,
SDISel.CurDAG->getDataLayout());
@ -3359,6 +3370,9 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
case OPC_CheckCondCode:
if (!::CheckCondCode(MatcherTable, MatcherIndex, N)) break;
continue;
case OPC_CheckChild2CondCode:
if (!::CheckChild2CondCode(MatcherTable, MatcherIndex, N)) break;
continue;
case OPC_CheckValueType:
if (!::CheckValueType(MatcherTable, MatcherIndex, N, TLI,
CurDAG->getDataLayout()))

View File

@ -211,6 +211,11 @@ void CheckCondCodeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckCondCode ISD::" << CondCodeName << '\n';
}
void CheckChild2CondCodeMatcher::printImpl(raw_ostream &OS,
unsigned indent) const {
OS.indent(indent) << "CheckChild2CondCode ISD::" << CondCodeName << '\n';
}
void CheckValueTypeMatcher::printImpl(raw_ostream &OS, unsigned indent) const {
OS.indent(indent) << "CheckValueType MVT::" << TypeName << '\n';
}

View File

@ -66,6 +66,7 @@ public:
CheckInteger, // Fail if wrong val.
CheckChildInteger, // Fail if child is wrong val.
CheckCondCode, // Fail if not condcode.
CheckChild2CondCode, // Fail if child is wrong condcode.
CheckValueType,
CheckComplexPat,
CheckAndImm,
@ -121,6 +122,7 @@ public:
case CheckInteger:
case CheckChildInteger:
case CheckCondCode:
case CheckChild2CondCode:
case CheckValueType:
case CheckAndImm:
case CheckOrImm:
@ -625,6 +627,27 @@ private:
}
};
/// CheckChild2CondCodeMatcher - This checks to see if child 2 node is a
/// CondCodeSDNode with the specified condition, if not it fails to match.
class CheckChild2CondCodeMatcher : public Matcher {
StringRef CondCodeName;
public:
CheckChild2CondCodeMatcher(StringRef condcodename)
: Matcher(CheckChild2CondCode), CondCodeName(condcodename) {}
StringRef getCondCodeName() const { return CondCodeName; }
static bool classof(const Matcher *N) {
return N->getKind() == CheckChild2CondCode;
}
private:
void printImpl(raw_ostream &OS, unsigned indent) const override;
bool isEqualImpl(const Matcher *M) const override {
return cast<CheckChild2CondCodeMatcher>(M)->CondCodeName == CondCodeName;
}
};
/// CheckValueTypeMatcher - This checks to see if the current node is a
/// VTSDNode with the specified type, if not it fails to match.
class CheckValueTypeMatcher : public Matcher {

View File

@ -554,6 +554,11 @@ EmitMatcher(const Matcher *N, unsigned Indent, unsigned CurrentIdx,
<< cast<CheckCondCodeMatcher>(N)->getCondCodeName() << ",\n";
return 2;
case Matcher::CheckChild2CondCode:
OS << "OPC_CheckChild2CondCode, ISD::"
<< cast<CheckChild2CondCodeMatcher>(N)->getCondCodeName() << ",\n";
return 2;
case Matcher::CheckValueType:
OS << "OPC_CheckValueType, MVT::"
<< cast<CheckValueTypeMatcher>(N)->getTypeName() << ",\n";
@ -995,6 +1000,7 @@ static StringRef getOpcodeString(Matcher::KindTy Kind) {
case Matcher::CheckInteger: return "OPC_CheckInteger"; break;
case Matcher::CheckChildInteger: return "OPC_CheckChildInteger"; break;
case Matcher::CheckCondCode: return "OPC_CheckCondCode"; break;
case Matcher::CheckChild2CondCode: return "OPC_CheckChild2CondCode"; break;
case Matcher::CheckValueType: return "OPC_CheckValueType"; break;
case Matcher::CheckComplexPat: return "OPC_CheckComplexPat"; break;
case Matcher::CheckAndImm: return "OPC_CheckAndImm"; break;

View File

@ -55,9 +55,13 @@ static void ContractNodes(std::unique_ptr<Matcher> &MatcherPtr,
if (MC->getChildNo() < 4) // Only have CheckChildSame0...3
New = new CheckChildSameMatcher(MC->getChildNo(), CS->getMatchNumber());
if (CheckIntegerMatcher *CS = dyn_cast<CheckIntegerMatcher>(MC->getNext()))
if (CheckIntegerMatcher *CI = dyn_cast<CheckIntegerMatcher>(MC->getNext()))
if (MC->getChildNo() < 5) // Only have CheckChildInteger0...4
New = new CheckChildIntegerMatcher(MC->getChildNo(), CS->getValue());
New = new CheckChildIntegerMatcher(MC->getChildNo(), CI->getValue());
if (auto *CCC = dyn_cast<CheckCondCodeMatcher>(MC->getNext()))
if (MC->getChildNo() == 2) // Only have CheckChild2CondCode
New = new CheckChild2CondCodeMatcher(CCC->getCondCodeName());
if (New) {
// Insert the new node.