[Mlir-commits] [mlir] [mlir][spirv] Use MapVector for BlockMergeInfoMap (PR #169636)

Igor Wodiany llvmlistbot at llvm.org
Wed Nov 26 03:04:43 PST 2025


https://github.com/IgWod-IMG created https://github.com/llvm/llvm-project/pull/169636

This should ensure that the structurizer `while` loop is deterministic across runs. Use of `MapVector` addresses the source of the nondeterminism which is use of a `Block*` as a map key.

fixes #128547

>From c1f9288ed51923a20bb8d7e94ae967eaafe28cdf Mon Sep 17 00:00:00 2001
From: Igor Wodiany <igor.wodiany at imgtec.com>
Date: Tue, 25 Nov 2025 17:15:04 +0000
Subject: [PATCH] [mlir][spirv] Use MapVector for BlockMergeInfoMap

This should ensure that the structurizer while loop is deterministic
across runs. Use of MapVector addresses the source of the nondeterminism
which is use of a Block* as a map key.

fixes #128547
---
 mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp | 3 ---
 mlir/lib/Target/SPIRV/Deserialization/Deserializer.h   | 4 +++-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 252be796488c5..d08e7ecf326ca 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -2923,9 +2923,6 @@ LogicalResult spirv::Deserializer::structurizeControlFlow() {
     return failure();
   }
 
-  // TODO: This loop is non-deterministic. Iteration order may vary between runs
-  // for the same shader as the key to the map is a pointer. See:
-  // https://github.com/llvm/llvm-project/issues/128547
   while (!blockMergeInfo.empty()) {
     Block *headerBlock = blockMergeInfo.begin()->first;
     BlockMergeInfo mergeInfo = blockMergeInfo.begin()->second;
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
index 243e6fd70ae43..6d09d556c4d02 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.h
@@ -58,7 +58,9 @@ struct DebugLine {
 };
 
 /// Map from a selection/loop's header block to its merge (and continue) target.
-using BlockMergeInfoMap = DenseMap<Block *, BlockMergeInfo>;
+/// Use `MapVector<>` to ensure a deterministic iteration order with a pointer
+/// key.
+using BlockMergeInfoMap = llvm::MapVector<Block *, BlockMergeInfo>;
 
 /// A "deferred struct type" is a struct type with one or more member types not
 /// known when the Deserializer first encounters the struct. This happens, for



More information about the Mlir-commits mailing list