[llvm] [LoopInterchange] Improve profitability check for vectorization (PR #133672)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 21 05:12:36 PDT 2025
================
@@ -1197,27 +1209,57 @@ LoopInterchangeProfitability::isProfitablePerInstrOrderCost() {
return std::nullopt;
}
+static char flipDirection(char Dir) {
+ switch (Dir) {
+ case '<':
+ return '>';
+ case '>':
+ return '<';
+ case '=':
+ case 'I':
+ case '*':
+ return Dir;
+ default:
+ llvm_unreachable("Unknown direction");
+ }
+}
+
/// Return true if we can vectorize the loop specified by \p LoopId.
-static bool canVectorize(const CharMatrix &DepMatrix, unsigned LoopId) {
+static bool canVectorize(const CharMatrix &DepMatrix,
+ const BitVector &IsNegatedVec, unsigned LoopId) {
+ // The loop can be vectorized if there are no negative dependencies. Consider
+ // the dependency of `j` in the following example.
+ //
+ // Positive: ... = A[i][j] Negative: ... = A[i][j-1]
+ // A[i][j-1] = ... A[i][j] = ...
----------------
Meinersbur wrote:
> (This is probably off-topic, but seeing this made me realize that I was almost confusing the "lexicographical order" in the context of direction vectors with the "lexical forward/backward" in LAA.)
They are related:
* [lexical](https://en.wikipedia.org/wiki/Lexical_analysis) (in opposition to [semantics](https://en.wikipedia.org/wiki/Semantic_analysis_(computational))): Order within a text (not well established, confusingly also used as synonym of lexicographic)
* [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order): Order within a [dictionary](https://en.wikipedia.org/wiki/Lexicon)
https://github.com/llvm/llvm-project/pull/133672
More information about the llvm-commits
mailing list