[llvm] [LSV] Insert casts to vectorize mismatched types (PR #134436)

Anshil Gandhi via llvm-commits llvm-commits at lists.llvm.org
Mon May 26 07:44:58 PDT 2025


================
@@ -1495,7 +1629,7 @@ Vectorizer::collectEquivalenceClasses(BasicBlock::iterator Begin,
          /*IsLoad=*/LI != nullptr}]
         .emplace_back(&I);
   }
-
+  insertCastsToMergeClasses(Ret);
----------------
gandhi56 wrote:

I took a deep dive into inserting casts before `vectorizeChain`.
- Firstly, all gathered chains are guaranteed to be vectorized except if the chain only has one element.
- `gatherChains` is responsible for calculating offsets. The `splitChain` functions further splits the gathered chains based on the legality of prospective vectorization. Inserting casts after these functions may break the legality of these chains as the offsets may no longer be correct. There are two ways to tackle this challenge:
    - Recompute the offsets and re-run the split chain functions - sounds like too much of an overhead to me.
    - Store chains in a heap-based data structure which can preserve legality, further demanding a lot of bookkeeping in order to replace the `splitChain` functions - this approach seems quite inscalable for longer chains.

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


More information about the llvm-commits mailing list