Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/transform/loop_vectorize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class VectorizePlanner : public arith::IRMutatorWithAnalyzer {
}
// vector_size may be greater than local/fragment buffers' vector_size.
// In such case, we need to re-validate if the indices are invariant
// or is vectorizable at the new vector_size boundary
// at the new vector_size boundary. If not invariant, take GCD.
for (const auto &info : local_fragment_buffers) {
if (vector_size_ > info.vector_size && !info.indices.empty()) {
Expand All @@ -289,8 +290,12 @@ class VectorizePlanner : public arith::IRMutatorWithAnalyzer {
for (size_t i = 0; i < info.indices.size(); ++i) {
elem_offset += info.indices[i] * strides[i];
}
if (!IsExprInvariantInVectorBoundary(
elem_offset, inner_for_->loop_var, vector_size_, analyzer_)) {
if (!(IsExprInvariantInVectorBoundary(elem_offset,
inner_for_->loop_var,
vector_size_, analyzer_) ||
IndiceCanVectorize(elem_offset, inner_for_->loop_var,
loop_extent_vector_size_, vector_size_,
analyzer_))) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
// Not invariant at this vector_size, need to take GCD
int old_vector_size = vector_size_;
vector_size_ = arith::ZeroAwareGCD(vector_size_, info.vector_size);
Expand Down Expand Up @@ -529,18 +534,14 @@ class VectorizePlanner : public arith::IRMutatorWithAnalyzer {
return initial_vector_size_;

int buffer_vec_size = loop_extent_vector_size_;

// Transform indices using layout_map if present
auto transformed_indices = TransformIndices(indices, buffer);

// 1. Compute raw element offset
Array<PrimExpr> strides = GetBufferStrides(buffer);

PrimExpr elem_offset = 0;
for (size_t i = 0; i < transformed_indices.size(); ++i) {
elem_offset += transformed_indices[i] * strides[i];
}

// 2. Check if current buffer_vec_size works with invariant boundary check
// In some cases, buffer_vec_size is max (e.g. 128), but
// IsExprInvariantInVectorBoundary may only be true at a smaller size (e.g.
Expand Down
Loading