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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to