Skip to content

Commit 7d2d908

Browse files
Order a preprocessing storage's element types deterministically
The storage type's element list was built by inserting into a DenseSet<Type> and then copying the set out. Type is a pointer wrapper, so the set hands its elements back in the order of their addresses, and that order is not stable from one run to the next. The order is not cosmetic: the element list is part of the __preprocessing function's signature and fixes which memref each store and load site indexes, so permuting it produces a different module for the same input. A storage with one element type could not show this; a storage holding several -- plaintexts next to prepared linear transformations -- can. Collect the types in first-occurrence order instead, which is what the nearby uniqueElementTypes() helper already documents as the intended contract.
1 parent ffd79eb commit 7d2d908

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

lib/Transforms/SplitPreprocessing/SplitPreprocessing.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,13 @@ struct SplitPreprocessingPass
378378
}
379379

380380
// Create a preprocessing.storage type with the set plaintext types
381-
DenseSet<Type> encodeTypesDeduped;
381+
// Preserve first-occurrence order as it determines storage field indices.
382+
SmallVector<Type> encodeTypes;
382383
for (Operation* input : analysis.encodeOps) {
383-
encodeTypesDeduped.insert(
384-
getElementTypeOrSelf(input->getResult(0).getType()));
384+
Type encodeTy = getElementTypeOrSelf(input->getResult(0).getType());
385+
if (!llvm::is_contained(encodeTypes, encodeTy))
386+
encodeTypes.push_back(encodeTy);
385387
}
386-
SmallVector<Type> encodeTypes(encodeTypesDeduped.begin(),
387-
encodeTypesDeduped.end());
388388
auto storageTy =
389389
preprocessing::PreprocessingStorageType::get(context, encodeTypes);
390390

0 commit comments

Comments
 (0)