[llvm] [TableGen][SubtargetEmitter] Early exit from loop in FindWriteResources and FindReadAdvance (PR #92202)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 10:41:09 PDT 2024


================
@@ -902,8 +902,15 @@ SubtargetEmitter::FindWriteResources(const CodeGenSchedRW &SchedWrite,
   for (Record *WR : ProcModel.WriteResDefs) {
     if (!WR->isSubClassOf("WriteRes"))
       continue;
-    if (AliasDef == WR->getValueAsDef("WriteType") ||
-        SchedWrite.TheDef == WR->getValueAsDef("WriteType")) {
+    // If there is no AliasDef and we find a match, we can early exit since
+    // there is no need to verify whether there are resources defined for both
+    // SchedWrite and its alias.
+    Record *WRDef = WR->getValueAsDef("WriteType");
+    if (!AliasDef && SchedWrite.TheDef == WRDef) {
----------------
topperc wrote:

What if AliasDef is non-null. We won't update ResDef if SchedWrite.TheDef == WRDef.

```suggestion
Record *WRDef = WR->getValueAsDef("WriteType");
if (AliasDef == WRDef || SchedWrite.TheDef == WRDef) {
  if (ResDef)
    PrintFatalError...
   ResDef = WR;
   // If there is no AliasDef and we find a match, we can early exit...
   if (!AliasDef)
     break;
```

https://github.com/llvm/llvm-project/pull/92202


More information about the llvm-commits mailing list