[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 08:33:46 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++) {
----------------
tschuett wrote:

Could you hoist `IntoMI.getIterator()`before the loop or does it change semantics?

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


More information about the llvm-commits mailing list