Skip to content

Commit 0288086

Browse files
Copilotalexreinking
andcommitted
Add VectorReduce generation to fuzz_simplify
Co-authored-by: alexreinking <169273+alexreinking@users.noreply.github.com>
1 parent effe0a0 commit 0288086

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/correctness/fuzz_simplify.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,32 @@ Expr random_shuffle_expr(RandomEngine &rng, Type t, int depth, bool overflow_und
151151
return random_choice(rng, shuffles)();
152152
}
153153

154+
Expr random_vector_reduce_expr(RandomEngine &rng, Type t, int depth, bool overflow_undef) {
155+
int input_lanes = (t.is_scalar() ? random_vector_width(rng) : t.lanes());
156+
Type input_type = t.with_lanes(input_lanes);
157+
Expr vec = random_expr(rng, input_type, depth, overflow_undef);
158+
int output_lanes = get_random_divisor(rng, input_type);
159+
160+
if (input_type.is_bool()) {
161+
VectorReduce::Operator reduce_ops[] = {
162+
VectorReduce::And,
163+
VectorReduce::Or,
164+
};
165+
return VectorReduce::make(random_choice(rng, reduce_ops), vec, output_lanes);
166+
}
167+
168+
VectorReduce::Operator reduce_ops[] = {
169+
VectorReduce::Add,
170+
VectorReduce::SaturatingAdd,
171+
VectorReduce::Mul,
172+
VectorReduce::Min,
173+
VectorReduce::Max,
174+
VectorReduce::And,
175+
VectorReduce::Or,
176+
};
177+
return VectorReduce::make(random_choice(rng, reduce_ops), vec, output_lanes);
178+
}
179+
154180
Expr random_condition(RandomEngine &rng, Type t, int depth, bool maybe_scalar) {
155181
static make_bin_op_fn make_bin_op[] = {
156182
EQ::make,
@@ -243,6 +269,9 @@ Expr random_expr(RandomEngine &rng, Type t, int depth, bool overflow_undef) {
243269
[&]() {
244270
return random_shuffle_expr(rng, t, depth, overflow_undef);
245271
},
272+
[&]() {
273+
return random_vector_reduce_expr(rng, t, depth, overflow_undef);
274+
},
246275
[&]() {
247276
if (t.is_bool()) {
248277
auto e1 = random_expr(rng, t, depth);

0 commit comments

Comments
 (0)