Skip to content

Commit e5f1064

Browse files
committed
SILCombiner: fix a non-determinism in a peephole optimization for load instructions.
1 parent cc2ed20 commit e5f1064

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,18 @@ SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
477477
// Given a load with multiple struct_extracts/tuple_extracts and no other
478478
// uses, canonicalize the load into several (struct_element_addr (load))
479479
// pairs.
480-
using ProjInstPairTy = std::pair<Projection, SingleValueInstruction *>;
480+
481+
struct ProjInstPair {
482+
Projection P;
483+
SingleValueInstruction *I;
484+
485+
// When sorting, just look at the projection and ignore the instruction.
486+
bool operator<(const ProjInstPair &RHS) const { return P < RHS.P; }
487+
};
481488

482489
// Go through the loads uses and add any users that are projections to the
483490
// projection list.
484-
llvm::SmallVector<ProjInstPairTy, 8> Projections;
491+
llvm::SmallVector<ProjInstPair, 8> Projections;
485492
for (auto *UI : getNonDebugUses(LI)) {
486493
auto *User = UI->getUser();
487494

@@ -503,8 +510,8 @@ SILInstruction *SILCombiner::visitLoadInst(LoadInst *LI) {
503510
Projection *LastProj = nullptr;
504511
LoadInst *LastNewLoad = nullptr;
505512
for (auto &Pair : Projections) {
506-
auto &Proj = Pair.first;
507-
auto *Inst = Pair.second;
513+
auto &Proj = Pair.P;
514+
auto *Inst = Pair.I;
508515

509516
// If this projection is the same as the last projection we processed, just
510517
// replace all uses of the projection with the load we created previously.

0 commit comments

Comments
 (0)