================
@@ -1395,6 +1395,26 @@ LogicalResult cir::VecCreateOp::verify() {
   return success();
 }
 
+//===----------------------------------------------------------------------===//
+// VecExtractOp
+//===----------------------------------------------------------------------===//
+
+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];
----------------
bcardosolopes wrote:

If the index is out of bounds we don't want to try accessing the elements. We 
have couple options here: (a) make the verifier look at input constants and 
verify out of bounds and/or (b) return `{}` in case it's not bound. If you add 
a verifier, than the check could be a helper function used by both it and 
`::fold`.

https://github.com/llvm/llvm-project/pull/139304
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to