[llvm] [LoopInterchange] Improve profitability check for vectorization (PR #133672)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 4 04:51:54 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:
[serious] Both of these have positive dependence distance, jsut the first is a WAR (anti-)dependence, the second is a RAW (flow)-dependence.
The `i`-loop variable is irrelevant here since always the same, so the dependence distance can only be non-negative.
https://github.com/llvm/llvm-project/pull/133672
More information about the llvm-commits
mailing list