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

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 9 05:39:30 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())
+      return false;
+    auto MMO = **(MI.memoperands_begin());
+    if (MMO.isAtomic() || MMO.isVolatile())
+      return false;
+
+    // Ensure instructions between MI and IntoMI sare not affected when combined
+    for (unsigned i = 1; i < 15 && CurrMI != IntoMI.getIterator(); i++) {
----------------
chuongg3 wrote:

> Why 15 exactly?

This was just an arbitrary limit, open to any suggestions. I have changed it to 20 to match `matchCombineExtractedVectorLoad` which @tschuett mentioned in a thread below

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


More information about the llvm-commits mailing list