Skip to content

Commit

Permalink
Generate simpler LLVM IR for shuffles that recursively become broadca…
Browse files Browse the repository at this point in the history
…sts (#7902)

* Generate simpler LLVM IR for shuffles that recursively become broadcasts

* Don't re-codegen arg
  • Loading branch information
abadams authored Oct 14, 2023
1 parent 51ad730 commit 7e35494
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4062,6 +4062,25 @@ void CodeGen_LLVM::visit(const Shuffle *op) {
vecs.push_back(codegen(e));
}

// Handle simple broadcasts, which can be generated by the recursive calls below.
if (op->vectors.size() == 1) {
bool all_indices_the_same = true;
internal_assert(!op->indices.empty());
for (int i : op->indices) {
all_indices_the_same &= (i == op->indices[0]);
}
if (all_indices_the_same) {
value = vecs[0];
if (value->getType()->isVectorTy()) {
value = builder->CreateExtractElement(value, ConstantInt::get(i32_t, op->indices[0]));
} else {
internal_assert(op->indices[0] == 0);
}
value = create_broadcast(value, op->indices.size());
return;
}
}

if (op->is_interleave()) {
value = interleave_vectors(vecs);
} else if (op->is_concat()) {
Expand Down

0 comments on commit 7e35494

Please sign in to comment.