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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jan 19 10:36:17 PST 2026


Author: neildhar
Date: 2026-01-19T19:36:13+01:00
New Revision: b4e1c547c038fa605ced0fb6761ed871c1a45094

URL: https://github.com/llvm/llvm-project/commit/b4e1c547c038fa605ced0fb6761ed871c1a45094
DIFF: https://github.com/llvm/llvm-project/commit/b4e1c547c038fa605ced0fb6761ed871c1a45094.diff

LOG: [NFC][mlir] Clarify bail condition in ExtractValueOp::fold (#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.

Added: 
    

Modified: 
    mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 6281f0d6e0b09..e6addfc4359a9 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