[llvm] [LoadStoreVectorizer] Fill gaps in load/store chains to enable vectorization (PR #159388)

Drew Kersnar via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 25 09:20:44 PDT 2025


================
@@ -817,6 +817,12 @@ class TargetTransformInfo {
   LLVM_ABI bool isLegalMaskedLoad(Type *DataType, Align Alignment,
                                   unsigned AddressSpace) const;
 
+  /// Return true if it is legal to widen loads beyond their current width,
+  /// assuming the result is still well-aligned. For example, converting a load
+  /// i32 to a load i64, or vectorizing three continuous load i32s into a load
+  /// <4 x i32>.
+  LLVM_ABI bool isLegalToWidenLoads() const;
----------------
dakersnar wrote:

Got it. I was unsure what we may want to check because for NVPTX the answer is "true" under any conditions, and I'm not familiar enough with other architectures to know what they may want to check.

`Address space` and `(Element?) Type` sound reasonable enough, but `Alignment` would make this less ergonomic to use. The use case of this API is to check whether widening loads is generally allowed for a given target, and the result is used to answer the question "can we attempt to widen loads?" As documented in the comment, there is an assumption that the answer spit out by the API depends on the resulting widened load being sufficient aligned. In this case, at the first point in the code we call this API (`splitChainByContiguity`), we do not know the alignment of the resulting load, as `splitChainByAlignment` happens later.

What we would have to do to incorporate an alignment argument into the API is something similar to how I'm using the existing `isLegalMaskedStore`, which is this not-so-clean helper function: https://github.com/llvm/llvm-project/pull/159388/files#diff-e0eab10050c9ef433cb0d7bc38e32e8d7fe44cdb0cf7422ae7a98966bff53672R1865-R1892. The helper is essentially converting the answers to "is this specific masked store legal" to the more general "are masked stores generally legal on this target", which is what we need to know at that point in the code. If you think that is best, I'm ok with it, but it feels a little hacky to me, so I was trying to come up with something better for this new API.

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


More information about the llvm-commits mailing list