================ @@ -1580,9 +1580,46 @@ OpFoldResult cir::VecExtractOp::fold(FoldAdaptor adaptor) { } //===----------------------------------------------------------------------===// -// VecShuffle +// VecShuffleOp //===----------------------------------------------------------------------===// +OpFoldResult cir::VecShuffleOp::fold(FoldAdaptor adaptor) { + auto vec1Attr = + mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec1()); + auto vec2Attr = + mlir::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec2()); + if (!vec1Attr || !vec2Attr) + return {}; + + mlir::Type vec1ElemTy = + mlir::cast<cir::VectorType>(vec1Attr.getType()).getElementType(); + + mlir::ArrayAttr vec1Elts = vec1Attr.getElts(); + mlir::ArrayAttr vec2Elts = vec2Attr.getElts(); + mlir::ArrayAttr indicesElts = adaptor.getIndices(); + + SmallVector<mlir::Attribute, 16> elements; + elements.reserve(indicesElts.size()); + + uint64_t vec1Size = vec1Elts.size(); + for (const auto &idxAttr : indicesElts.getAsRange<cir::IntAttr>()) { + if (idxAttr.getSInt() == -1) { + elements.push_back(cir::UndefAttr::get(vec1ElemTy)); + continue; + } + + uint64_t idxValue = idxAttr.getUInt(); + if (idxValue < vec1Size) { + elements.push_back(vec1Elts[idxValue]); + } else { + elements.push_back(vec2Elts[idxValue - vec1Size]); ---------------- bcardosolopes wrote:
`elements.push_back(idxValue < vec1Size ? vec1Elts[idxValue] : vec2Elts[idxValue - vec1Size])` https://github.com/llvm/llvm-project/pull/143260 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits