Skip to content

[SelectionDAG] Add instantiated OPC_CheckType #73283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/include/llvm/CodeGen/SelectionDAGISel.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class SelectionDAGISel : public MachineFunctionPass {
OPC_CheckOpcode,
OPC_SwitchOpcode,
OPC_CheckType,
// Space-optimized forms that implicitly encode VT.
OPC_CheckTypeI32,
OPC_CheckTypeI64,
OPC_CheckTypeRes,
OPC_SwitchType,
OPC_CheckChild0Type,
Expand Down
81 changes: 55 additions & 26 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2711,11 +2711,10 @@ CheckOpcode(const unsigned char *MatcherTable, unsigned &MatcherIndex,
return N->getOpcode() == Opc;
}

LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
CheckType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
const TargetLowering *TLI, const DataLayout &DL) {
MVT::SimpleValueType VT =
static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
LLVM_ATTRIBUTE_ALWAYS_INLINE static bool CheckType(MVT::SimpleValueType VT,
SDValue N,
const TargetLowering *TLI,
const DataLayout &DL) {
if (N.getValueType() == VT)
return true;

Expand All @@ -2724,13 +2723,11 @@ CheckType(const unsigned char *MatcherTable, unsigned &MatcherIndex, SDValue N,
}

LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
CheckChildType(const unsigned char *MatcherTable, unsigned &MatcherIndex,
SDValue N, const TargetLowering *TLI, const DataLayout &DL,
unsigned ChildNo) {
CheckChildType(MVT::SimpleValueType VT, SDValue N, const TargetLowering *TLI,
const DataLayout &DL, unsigned ChildNo) {
if (ChildNo >= N.getNumOperands())
return false; // Match fails if out of range child #.
return ::CheckType(MatcherTable, MatcherIndex, N.getOperand(ChildNo), TLI,
DL);
return false; // Match fails if out of range child #.
return ::CheckType(VT, N.getOperand(ChildNo), TLI, DL);
}

LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
Expand Down Expand Up @@ -2829,7 +2826,8 @@ static unsigned IsPredicateKnownToFail(const unsigned char *Table,
bool &Result,
const SelectionDAGISel &SDISel,
SmallVectorImpl<std::pair<SDValue, SDNode*>> &RecordedNodes) {
switch (Table[Index++]) {
unsigned Opcode = Table[Index++];
switch (Opcode) {
default:
Result = false;
return Index-1; // Could not evaluate this predicate.
Expand All @@ -2856,12 +2854,27 @@ static unsigned IsPredicateKnownToFail(const unsigned char *Table,
Result = !::CheckOpcode(Table, Index, N.getNode());
return Index;
case SelectionDAGISel::OPC_CheckType:
Result = !::CheckType(Table, Index, N, SDISel.TLI,
SDISel.CurDAG->getDataLayout());
case SelectionDAGISel::OPC_CheckTypeI32:
case SelectionDAGISel::OPC_CheckTypeI64: {
MVT::SimpleValueType VT;
switch (Opcode) {
case SelectionDAGISel::OPC_CheckTypeI32:
VT = MVT::i32;
break;
case SelectionDAGISel::OPC_CheckTypeI64:
VT = MVT::i64;
break;
default:
VT = static_cast<MVT::SimpleValueType>(Table[Index++]);
break;
}
Result = !::CheckType(VT, N, SDISel.TLI, SDISel.CurDAG->getDataLayout());
return Index;
}
case SelectionDAGISel::OPC_CheckTypeRes: {
unsigned Res = Table[Index++];
Result = !::CheckType(Table, Index, N.getValue(Res), SDISel.TLI,
Result = !::CheckType(static_cast<MVT::SimpleValueType>(Table[Index++]),
N.getValue(Res), SDISel.TLI,
SDISel.CurDAG->getDataLayout());
return Index;
}
Expand All @@ -2872,11 +2885,13 @@ static unsigned IsPredicateKnownToFail(const unsigned char *Table,
case SelectionDAGISel::OPC_CheckChild4Type:
case SelectionDAGISel::OPC_CheckChild5Type:
case SelectionDAGISel::OPC_CheckChild6Type:
case SelectionDAGISel::OPC_CheckChild7Type:
Result = !::CheckChildType(
Table, Index, N, SDISel.TLI, SDISel.CurDAG->getDataLayout(),
Table[Index - 1] - SelectionDAGISel::OPC_CheckChild0Type);
case SelectionDAGISel::OPC_CheckChild7Type: {
Result =
!::CheckChildType(static_cast<MVT::SimpleValueType>(Table[Index++]), N,
SDISel.TLI, SDISel.CurDAG->getDataLayout(),
Opcode - SelectionDAGISel::OPC_CheckChild0Type);
return Index;
}
case SelectionDAGISel::OPC_CheckCondCode:
Result = !::CheckCondCode(Table, Index, N);
return Index;
Expand Down Expand Up @@ -3306,15 +3321,29 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
continue;

case OPC_CheckType:
if (!::CheckType(MatcherTable, MatcherIndex, N, TLI,
CurDAG->getDataLayout()))
case OPC_CheckTypeI32:
case OPC_CheckTypeI64:
MVT::SimpleValueType VT;
switch (Opcode) {
case OPC_CheckTypeI32:
VT = MVT::i32;
break;
case OPC_CheckTypeI64:
VT = MVT::i64;
break;
default:
VT = static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]);
break;
}
if (!::CheckType(VT, N, TLI, CurDAG->getDataLayout()))
break;
continue;

case OPC_CheckTypeRes: {
unsigned Res = MatcherTable[MatcherIndex++];
if (!::CheckType(MatcherTable, MatcherIndex, N.getValue(Res), TLI,
CurDAG->getDataLayout()))
if (!::CheckType(
static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]),
N.getValue(Res), TLI, CurDAG->getDataLayout()))
break;
continue;
}
Expand Down Expand Up @@ -3387,9 +3416,9 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
case OPC_CheckChild2Type: case OPC_CheckChild3Type:
case OPC_CheckChild4Type: case OPC_CheckChild5Type:
case OPC_CheckChild6Type: case OPC_CheckChild7Type:
if (!::CheckChildType(MatcherTable, MatcherIndex, N, TLI,
CurDAG->getDataLayout(),
Opcode - OPC_CheckChild0Type))
if (!::CheckChildType(
static_cast<MVT::SimpleValueType>(MatcherTable[MatcherIndex++]),
N, TLI, CurDAG->getDataLayout(), Opcode - OPC_CheckChild0Type))
break;
continue;
case OPC_CheckCondCode:
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/TableGen/dag-isel-complexpattern.td
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def CP32 : ComplexPattern<i32, 0, "SelectCP32">;
// (CP32) still worked.
def INSTR : Instruction {
// CHECK-LABEL: OPC_CheckOpcode, TARGET_VAL(ISD::STORE)
// CHECK: OPC_CheckType, MVT::i32
// CHECK: OPC_CheckTypeI32
// CHECK: OPC_CheckComplexPat, /*CP*/0, /*#*/1, // SelectCP32:$
// CHECK: Src: (st (add:{ *:[i32] } (CP32:{ *:[i32] }), (CP32:{ *:[i32] })), i64:{ *:[i64] }:$addr)
let OutOperandList = (outs);
Expand Down
13 changes: 10 additions & 3 deletions llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,16 @@ EmitMatcher(const Matcher *N, const unsigned Indent, unsigned CurrentIdx,

case Matcher::CheckType:
if (cast<CheckTypeMatcher>(N)->getResNo() == 0) {
OS << "OPC_CheckType, "
<< getEnumName(cast<CheckTypeMatcher>(N)->getType()) << ",\n";
return 2;
MVT::SimpleValueType VT = cast<CheckTypeMatcher>(N)->getType();
switch (VT) {
case MVT::i32:
case MVT::i64:
OS << "OPC_CheckTypeI" << MVT(VT).getSizeInBits() << ",\n";
return 1;
default:
OS << "OPC_CheckType, " << getEnumName(VT) << ",\n";
return 2;
}
}
OS << "OPC_CheckTypeRes, " << cast<CheckTypeMatcher>(N)->getResNo()
<< ", " << getEnumName(cast<CheckTypeMatcher>(N)->getType()) << ",\n";
Expand Down