[PATCH] D157196: [SelectionDAG] Add Opc_CheckPatternPredicate2 to support targets with more than 256 predicates.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 5 13:23:47 PDT 2023


craig.topper created this revision.
craig.topper added reviewers: bogner, zixuan-wu, kparzysz.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: LLVM.

This is an alternative to D156967 <https://reviews.llvm.org/D156967> where I suggested the author
could use a VBR type.

This patch takes inspirations from Opc_EmitRegister2 that is used
for two byte registers.

I'm assuming 1 or 2 byte predicates should be enough so we don't
need the fully generality of VBR.

This avoids impacting the table size on targets that have more than
128 predicates already like X86.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157196

Files:
  llvm/include/llvm/CodeGen/SelectionDAGISel.h
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  llvm/utils/TableGen/DAGISelMatcherEmitter.cpp


Index: llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
===================================================================
--- llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -472,12 +472,16 @@
     return 2;
 
   case Matcher::CheckPatternPredicate: {
-    StringRef Pred =cast<CheckPatternPredicateMatcher>(N)->getPredicate();
-    OS << "OPC_CheckPatternPredicate, " << getPatternPredicate(Pred) << ',';
+    StringRef Pred = cast<CheckPatternPredicateMatcher>(N)->getPredicate();
+    unsigned PredNo = getPatternPredicate(Pred);
+    if (PredNo > 255)
+      OS << "OPC_CheckPatternPredicate2, TARGET_VAL(" << PredNo << "),";
+    else
+      OS << "OPC_CheckPatternPredicate, " << PredNo << ',';
     if (!OmitComments)
       OS << " // " << Pred;
     OS << '\n';
-    return 2;
+    return 2 + (PredNo > 255);
   }
   case Matcher::CheckPredicate: {
     TreePredicateFn Pred = cast<CheckPredicateMatcher>(N)->getPredicate();
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -2639,8 +2639,11 @@
 /// CheckPatternPredicate - Implements OP_CheckPatternPredicate.
 LLVM_ATTRIBUTE_ALWAYS_INLINE static bool
 CheckPatternPredicate(const unsigned char *MatcherTable, unsigned &MatcherIndex,
-                      const SelectionDAGISel &SDISel) {
-  return SDISel.CheckPatternPredicate(MatcherTable[MatcherIndex++]);
+                      const SelectionDAGISel &SDISel, bool TwoBytePredNo) {
+  unsigned PredNo = MatcherTable[MatcherIndex++];
+  if (TwoBytePredNo)
+    PredNo |= MatcherTable[MatcherIndex++] << 8;
+  return SDISel.CheckPatternPredicate(PredNo);
 }
 
 /// CheckNodePredicate - Implements OP_CheckNodePredicate.
@@ -2788,7 +2791,10 @@
                         Table[Index-1] - SelectionDAGISel::OPC_CheckChild0Same);
     return Index;
   case SelectionDAGISel::OPC_CheckPatternPredicate:
-    Result = !::CheckPatternPredicate(Table, Index, SDISel);
+  case SelectionDAGISel::OPC_CheckPatternPredicate2:
+    Result = !::CheckPatternPredicate(
+        Table, Index, SDISel,
+        Table[Index - 1] == SelectionDAGISel::OPC_CheckPatternPredicate2);
     return Index;
   case SelectionDAGISel::OPC_CheckPredicate:
     Result = !::CheckNodePredicate(Table, Index, SDISel, N.getNode());
@@ -3198,7 +3204,10 @@
       continue;
 
     case OPC_CheckPatternPredicate:
-      if (!::CheckPatternPredicate(MatcherTable, MatcherIndex, *this)) break;
+    case OPC_CheckPatternPredicate2:
+      if (!::CheckPatternPredicate(MatcherTable, MatcherIndex, *this,
+                                   Opcode == OPC_CheckPatternPredicate2))
+        break;
       continue;
     case OPC_CheckPredicate:
       if (!::CheckNodePredicate(MatcherTable, MatcherIndex, *this,
Index: llvm/include/llvm/CodeGen/SelectionDAGISel.h
===================================================================
--- llvm/include/llvm/CodeGen/SelectionDAGISel.h
+++ llvm/include/llvm/CodeGen/SelectionDAGISel.h
@@ -128,6 +128,7 @@
     OPC_CheckChild0Same, OPC_CheckChild1Same,
     OPC_CheckChild2Same, OPC_CheckChild3Same,
     OPC_CheckPatternPredicate,
+    OPC_CheckPatternPredicate2,
     OPC_CheckPredicate,
     OPC_CheckPredicateWithOperands,
     OPC_CheckOpcode,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157196.547507.patch
Type: text/x-patch
Size: 3404 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230805/fe1861c8/attachment.bin>


More information about the llvm-commits mailing list