[llvm] [SLP] More OOP to simplify vectorizeStores() (NFC) (PR #134605)

Gaƫtan Bossu via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 10 04:01:12 PDT 2025


================
@@ -20341,9 +20341,15 @@ namespace {
 /// A group of stores that we'll try to bundle together using vector ops.
 /// They are ordered using the signed distance of their address operand to the
 /// address of this group's BaseInstr.
-struct RelatedStoreInsts {
-  RelatedStoreInsts(unsigned BaseInstrIdx) { reset(BaseInstrIdx); }
+class RelatedStoreInsts {
+public:
+  RelatedStoreInsts(unsigned BaseInstrIdx, ArrayRef<StoreInst *> AllStores)
+      : AllStores(AllStores) {
----------------
gbossu wrote:

Correct, the lifetime of that storage exceeds the one of the `RelatedStoreInsts` object, and it does not change.

The main reason (I think) that there are indices everywhere is that it helps to quickly check the insertion order of the stores. E.g. for the code touched in this PR: if a store at `Id=4` is aliasing with one of the previously collected stores, then one can easily try to vectorize the stores with `0<=Id<4`, and start collecting stores again from `Id>=4`.

But TLDR, I agree it would be a lot clearer to directly manipulate `StoreInst *`. I'll have a quick look how much work it would be, I just assume it will be a bit too much for this patch. Good news is that once more things are abstracted in `RelatedStoreInsts`, further refactorings will probably be less painful.

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


More information about the llvm-commits mailing list