[llvm] [GlobalISel] Look between instructions to be matched (PR #101675)

Thorsten Schütt via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 2 10:47:38 PDT 2024


================
@@ -70,6 +70,35 @@ bool GIMatchTableExecutor::isObviouslySafeToFold(MachineInstr &MI,
   if (MI.isConvergent() && MI.getParent() != IntoMI.getParent())
     return false;
 
-  return !MI.mayLoadOrStore() && !MI.mayRaiseFPException() &&
-         !MI.hasUnmodeledSideEffects() && MI.implicit_operands().empty();
+  if (!MI.mayLoadOrStore() && !MI.mayRaiseFPException() &&
+      !MI.hasUnmodeledSideEffects() && MI.implicit_operands().empty()) {
+    return true;
+  }
+
+  // If the load is simple, check instructions between MI and IntoMI
+  auto CurrMI = MI.getIterator();
+  if (MI.mayLoad() && MI.getParent() == IntoMI.getParent()) {
+    if (MI.memoperands_empty())
----------------
tschuett wrote:

```
  const unsigned MaxIter = 20;
  unsigned Iter = 0;
  for (auto II = LoadMI->getIterator(), IE = MI.getIterator(); II != IE; ++II) {
    if (II->isLoadFoldBarrier())
      return false;
    if (Iter++ == MaxIter)
      return false;
  }
```

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


More information about the llvm-commits mailing list