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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sun Jan 18 23:17:32 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))) {
----------------
neildhar wrote:

> extract value position change does not benefit from the walking the insert value op chain

Could you say more about this? I am imagining a case like:

```
%0 = llvm.extractvalue %foo[0]
%1 = llvm.insertvalue %bar, %0[0]
%2 = llvm.extractvalue %1[1]
```

Which could get folded to:

```
llvm.extractvalue %foo[0, 1]
```

If the source of `%foo` is itself an `InsertValueOp` or a constant, it could be folded even further by applying the other cases (and so on).

In the current version of the PR, the three cases are kept independent and we let multiple invocations of the folder deal with fully folding such chains. I find that slightly simpler to think about, but I defer to you.

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


More information about the Mlir-commits mailing list