Skip to content

Commit

Permalink
Fix #8455 (in combination with #8457) (#8456)
Browse files Browse the repository at this point in the history
* Partial fix for #8455

In slice_vector(), only check for type equality after vectors have been normalized to fixed (i.e., it's ok for some original input to be vscale)

* Update CodeGen_LLVM.h
  • Loading branch information
steven-johnson authored Nov 6, 2024
1 parent f981571 commit a1723e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4947,11 +4947,18 @@ Value *CodeGen_LLVM::concat_vectors(const vector<Value *> &v) {

Value *CodeGen_LLVM::shuffle_vectors(Value *a, Value *b,
const std::vector<int> &indices) {
internal_assert(a->getType() == b->getType());
if (isa<llvm::ScalableVectorType>(a->getType())) {
a = scalable_to_fixed_vector_type(a);
}
if (isa<llvm::ScalableVectorType>(b->getType())) {
b = scalable_to_fixed_vector_type(b);
}
if (!a->getType()->isVectorTy()) {
a = create_broadcast(a, 1);
b = create_broadcast(b, 1);
}
// Check for type identity *after* normalizing to fixed vectors
internal_assert(a->getType() == b->getType());
vector<Constant *> llvm_indices(indices.size());
for (size_t i = 0; i < llvm_indices.size(); i++) {
if (indices[i] >= 0) {
Expand All @@ -4963,12 +4970,6 @@ Value *CodeGen_LLVM::shuffle_vectors(Value *a, Value *b,
llvm_indices[i] = PoisonValue::get(i32_t);
}
}
if (isa<llvm::ScalableVectorType>(a->getType())) {
a = scalable_to_fixed_vector_type(a);
}
if (isa<llvm::ScalableVectorType>(b->getType())) {
b = scalable_to_fixed_vector_type(b);
}
return builder->CreateShuffleVector(a, b, ConstantVector::get(llvm_indices));
}

Expand Down
4 changes: 3 additions & 1 deletion src/CodeGen_LLVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ class CodeGen_LLVM : public IRVisitor {
/** Concatenate a bunch of llvm vectors. Must be of the same type. */
virtual llvm::Value *concat_vectors(const std::vector<llvm::Value *> &);

/** Create an LLVM shuffle vectors instruction. */
/** Create an LLVM shuffle vectors instruction. Takes a combination of
* fixed or scalable vectors as input, so long as the effective lengths match,
* but always returns a fixed vector. */
virtual llvm::Value *shuffle_vectors(llvm::Value *a, llvm::Value *b,
const std::vector<int> &indices);
/** Shorthand for shuffling a single vector. */
Expand Down

0 comments on commit a1723e7

Please sign in to comment.