[llvm] [GlobalISel] Make sure to check for load barriers when merging G_EXTRACT_VECTOR_ELT into G_LOAD. (PR #82306)

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 19 21:29:30 PST 2024


================
@@ -1198,6 +1198,18 @@ bool CombinerHelper::matchCombineExtractedVectorLoad(MachineInstr &MI,
   if (!VecEltTy.isByteSized())
     return false;
 
+  // Check for load fold barriers between the extraction and the load.
+  if (MI.getParent() != LoadMI->getParent())
+    return false;
+  const unsigned MaxIter = 20;
+  unsigned Iter = 0;
+  for (auto II = LoadMI->getIterator(), IE = MI.getIterator(); II != IE; ++II) {
----------------
ornata wrote:

random aside: I didn't look too hard, but I'm surprised I couldn't find anything in STLExtras that automates this "do a think for a maximum number of iterations over a range" pattern

Like it would be cool to be able to write something like

```
if (any_of(make_bounded_range(LoadMI->getIterator(), MI.getIterator(), 20)
                              [const MachineInstr &Btwn]{
                                 return Btwn.isLoadFoldBarrier();
                              })
  return false;
```

But I don't know if that exists today.

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


More information about the llvm-commits mailing list