[clang] [CIR] Upstream extract op for VectorType (PR #138413)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Tue May 6 12:20:11 PDT 2025
AmrDeveloper wrote:
> Overall looks good. While here, can you please implement a folder for this operation? It should kick-in if both idx and input vector are constants.
@bcardosolopes I implement it like this snippet
```
OpFoldResult cir::VecExtractOp::fold(FoldAdaptor adaptor) {
const auto vectorAttr =
llvm::dyn_cast_if_present<cir::ConstVectorAttr>(adaptor.getVec());
if (!vectorAttr)
return {};
const auto indexAttr =
llvm::dyn_cast_if_present<cir::IntAttr>(adaptor.getIndex());
if (!indexAttr)
return {};
const mlir::ArrayAttr elements = vectorAttr.getElts();
const int64_t index = indexAttr.getSInt();
return elements[index];
}
```
But I am thinking, is there a case that codegen will perform extractOp directly from ConstVec, not on load or get_global? I see a similar implementation in MLIR Vector Dialect 🤔 I will try to come up with a test case for testing
https://github.com/llvm/llvm-project/pull/138413
More information about the cfe-commits
mailing list