Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slice IRMatcher should only match on slices #7772

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/IRMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,7 @@ struct SliceOp {
}
const Shuffle &v = (const Shuffle &)e;
return v.vectors.size() == 1 &&
v.is_slice() &&
vec.template match<bound>(*v.vectors[0].get(), state) &&
base.template match<bound | bindings<Vec>::mask>(v.slice_begin(), state) &&
stride.template match<bound | bindings<Vec>::mask | bindings<Base>::mask>(v.slice_stride(), state) &&
Expand Down
19 changes: 19 additions & 0 deletions test/correctness/simplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ Expr slice(const Expr &e, int begin, int stride, int w) {
return Shuffle::make_slice(e, begin, stride, w);
}

// An arbitrary fixed permutation of the lanes of a single vector that isn't one
// of the classes above. Requires a power of two number of lanes.
Expr permute_lanes(const Expr &e) {
std::vector<int> mask(e.type().lanes());
for (int i = 0; i < e.type().lanes(); i++) {
mask[i] = i;
// Some arbitrary permutation
if (i & 1) {
std::swap(mask[i], mask[i / 2]);
}
}
return Shuffle::make({e}, std::move(mask));
}

Expr ramp(const Expr &base, const Expr &stride, int w) {
return Ramp::make(base, stride, w);
}
Expand Down Expand Up @@ -159,6 +173,11 @@ void check_casts() {
check(slice(cast(UInt(64, 8), some_vector), 2, 1, 3),
cast(UInt(64, 3), slice(some_vector, 2, 1, 3)));

// But we currently have no logic for pulling things outside of shuffles
// other than slices.
check(permute_lanes(some_vector) + permute_lanes(some_vector + 1),
permute_lanes(some_vector) + permute_lanes(some_vector + 1));

std::vector<int> indices(18);
for (int i = 0; i < 18; i++) {
indices[i] = i & 3;
Expand Down