[Mlir-commits] [mlir] [NFC][mlir] Clarify bail condition in ExtractValueOp::fold (PR #176583)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Jan 17 09:53:20 PST 2026


https://github.com/neildhar created https://github.com/llvm/llvm-project/pull/176583

This bail condition was added before we added the traversal of nested structs, which handles the case where insert position is a prefix of extract position. So we only need to check for the extract position being a prefix of the insert position here. Make the check clearer and update the comment so it is less confusing.

>From 4f2e5ccbe5e6fdbce069e6e9302888001d773b9c Mon Sep 17 00:00:00 2001
From: Neil Dhar <neildhar at meta.com>
Date: Sat, 17 Jan 2026 09:46:25 -0800
Subject: [PATCH] [NFC][mlir] Clarify bail condition in ExtractValueOp::fold

---
 mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index f9162b35966c1..957f5348c9572 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -1962,11 +1962,10 @@ OpFoldResult LLVM::ExtractValueOp::fold(FoldAdaptor adaptor) {
     }
 
     // Case 3: Try to continue the traversal with the container value.
-    unsigned min = std::min(extractPosSize, insertPosSize);
 
-    // If one is fully prefix of the other, stop propagating back as it will
-    // miss dependencies. For instance, %3 should not fold to %f0 in the
-    // following example:
+    // If extract position is a prefix of insert position, stop propagating back
+    // as it will miss dependencies. For instance, %3 should not fold to %f0 in
+    // the following example:
     // ```
     //   %1 = llvm.insertvalue %f0, %0[0, 0] :
     //     !llvm.array<4 x !llvm.array<4 x f32>>
@@ -1974,7 +1973,8 @@ OpFoldResult LLVM::ExtractValueOp::fold(FoldAdaptor adaptor) {
     //     !llvm.array<4 x !llvm.array<4 x f32>>
     //   %3 = llvm.extractvalue %2[0, 0] : !llvm.array<4 x !llvm.array<4 x f32>>
     // ```
-    if (extractPos.take_front(min) == insertPos.take_front(min))
+    if (insertPosSize > extractPosSize &&
+        extractPos == insertPos.take_front(extractPosSize))
       return result;
     // If neither a prefix, nor the exact position, we can extract out of the
     // value being inserted into. Moreover, we can try again if that operand



More information about the Mlir-commits mailing list