Skip to content

Commit 49becb9

Browse files
mcourteauxGemini 3 Pro
andauthored
Three Hexagon bugs found by Gemini Pro. (#8989)
* Two bugs found by Gemini Pro. Co-authored-by: Gemini 3 Pro <gemini@aistudio.google.com> * Another bug found by Gemini Pro. Co-authored-by: Gemini 3 Pro <gemini@aistudio.google.com> * Fix infinite recursion on shuffles of vectors with exclusively don't-care indices. --------- Co-authored-by: Gemini 3 Pro <gemini@aistudio.google.com>
1 parent 54f2881 commit 49becb9

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

src/CodeGen_Hexagon.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,24 +1158,28 @@ Value *CodeGen_Hexagon::shuffle_vectors(Value *a, Value *b,
11581158
llvm::Type *result_ty = get_vector_type(element_ty, result_elements);
11591159

11601160
// Try to rewrite shuffles that only access the elements of b.
1161-
int min = indices[0];
1162-
for (size_t i = 1; i < indices.size(); i++) {
1163-
if (indices[i] != -1 && indices[i] < min) {
1164-
min = indices[i];
1161+
int min = INT_MAX;
1162+
int max = -1;
1163+
for (int idx : indices) {
1164+
if (idx != -1) {
1165+
min = std::min(min, idx);
1166+
max = std::max(max, idx);
11651167
}
11661168
}
1169+
if (min == INT_MAX) {
1170+
return llvm::PoisonValue::get(result_ty);
1171+
}
11671172
if (min >= a_elements) {
11681173
vector<int> shifted_indices(indices);
11691174
for (int &i : shifted_indices) {
11701175
if (i != -1) {
11711176
i -= a_elements;
11721177
}
11731178
}
1174-
return shuffle_vectors(b, shifted_indices);
1179+
return shuffle_vectors(b, b, shifted_indices);
11751180
}
11761181

11771182
// Try to rewrite shuffles that only access the elements of a.
1178-
int max = *std::max_element(indices.begin(), indices.end());
11791183
if (max < a_elements) {
11801184
BitCastInst *a_cast = dyn_cast<BitCastInst>(a);
11811185
CallInst *a_call = dyn_cast<CallInst>(a_cast ? a_cast->getOperand(0) : a);
@@ -1683,7 +1687,7 @@ Value *CodeGen_Hexagon::vlut(Value *lut, Value *idx, int min_index, int max_inde
16831687
// contains the result of each range, and a condition vector
16841688
// indicating whether the result should be used.
16851689
vector<std::pair<Value *, Value *>> ranges;
1686-
for (int min_index_i = 0; min_index_i < max_index; min_index_i += 256) {
1690+
for (int min_index_i = 0; min_index_i <= max_index; min_index_i += 256) {
16871691
// Make a vector of the indices shifted such that the min of
16881692
// this range is at 0. Use 16-bit indices for this.
16891693
Value *min_index_i_val = create_vector(i16x_t, min_index_i);
@@ -1697,9 +1701,11 @@ Value *CodeGen_Hexagon::vlut(Value *lut, Value *idx, int min_index, int max_inde
16971701
// truncate to 8 bits, as vlut requires.
16981702
indices = call_intrin(i8x_t, "halide.hexagon.pack.vh", {indices});
16991703

1700-
int range_extent_i = std::min(max_index - min_index_i, 255);
1701-
Value *range_i = vlut256(slice_vector(lut, min_index_i, range_extent_i),
1702-
indices, 0, range_extent_i);
1704+
int local_max_index = std::min(max_index - min_index_i, 255);
1705+
int slice_size = local_max_index + 1;
1706+
1707+
Value *range_i = vlut256(slice_vector(lut, min_index_i, slice_size),
1708+
indices, 0, local_max_index);
17031709
ranges.emplace_back(range_i, use_index);
17041710
}
17051711

0 commit comments

Comments
 (0)