[Mlir-commits] [mlir] [mlir] Always update ExtractValue to use last container in insert chain (PR #176588)

Tobias Gysi llvmlistbot at llvm.org
Sun Jan 18 12:59:21 PST 2026


================
@@ -1928,11 +1928,20 @@ OpFoldResult LLVM::ExtractValueOp::fold(FoldAdaptor adaptor) {
     return getResult();
   }
 
-  Operation *container = getContainer().getDefiningOp();
-  OpFoldResult result = {};
+  Attribute containerAttr;
+  if (matchPattern(getContainer(), m_Constant(&containerAttr))) {
+    for (int64_t pos : getPosition()) {
+      containerAttr = extractElementAt(containerAttr, pos);
+      if (!containerAttr)
+        return nullptr;
+    }
+    return containerAttr;
+  }
+
+  Value container = getContainer();
   ArrayRef<int64_t> extractPos = getPosition();
-  bool switchedToInsertedValue = false;
-  while (auto insertValueOp = dyn_cast_if_present<InsertValueOp>(container)) {
+  while (auto insertValueOp =
+             dyn_cast_if_present<InsertValueOp>(container.getDefiningOp())) {
----------------
gysit wrote:

```suggestion
  while (auto insertValueOp = container.getDefiningOp<InsertValueOp>()) {
```
nit: I think this should work?

https://github.com/llvm/llvm-project/pull/176588


More information about the Mlir-commits mailing list