From 0480c1bb9f45052fbf5bcab50fd1fd0ac257f65c Mon Sep 17 00:00:00 2001 From: Mandeep Singh Grang Date: Tue, 18 Oct 2016 00:11:19 +0000 Subject: [PATCH] Fix differences in codegen between Linux and Windows toolchains Summary: There are differences in codegen between Linux and Windows due to: 1. Using std::sort which uses quicksort which is a non-stable sort. 2. Iterating over Set data structure where the iteration order is non deterministic. Reviewers: arsenm, grosbach, junbuml, zinob, MatzeB Subscribers: MatzeB, wdng Differential Revision: https://reviews.llvm.org/D25695 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284441 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/RegionInfo.h | 3 ++- lib/CodeGen/LocalStackSlotAllocation.cpp | 8 +++++--- lib/CodeGen/MachineScheduler.cpp | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/llvm/Analysis/RegionInfo.h b/include/llvm/Analysis/RegionInfo.h index 6d901f4a732..85f0a80d6ca 100644 --- a/include/llvm/Analysis/RegionInfo.h +++ b/include/llvm/Analysis/RegionInfo.h @@ -39,6 +39,7 @@ #include "llvm/ADT/DepthFirstIterator.h" #include "llvm/ADT/PointerIntPair.h" +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/iterator_range.h" #include "llvm/IR/CFG.h" #include "llvm/IR/Dominators.h" @@ -678,7 +679,7 @@ class RegionInfoBase { friend class MachineRegionInfo; typedef DenseMap BBtoBBMap; typedef DenseMap BBtoRegionMap; - typedef SmallPtrSet RegionSet; + typedef SmallSetVector RegionSet; RegionInfoBase(); virtual ~RegionInfoBase(); diff --git a/lib/CodeGen/LocalStackSlotAllocation.cpp b/lib/CodeGen/LocalStackSlotAllocation.cpp index 6cb59a68086..b86406e2fcd 100644 --- a/lib/CodeGen/LocalStackSlotAllocation.cpp +++ b/lib/CodeGen/LocalStackSlotAllocation.cpp @@ -55,7 +55,8 @@ namespace { FrameRef(MachineBasicBlock::iterator I, int64_t Offset, int Idx) : MI(I), LocalOffset(Offset), FrameIdx(Idx) {} bool operator<(const FrameRef &RHS) const { - return LocalOffset < RHS.LocalOffset; + return std::tie(LocalOffset, FrameIdx) < + std::tie(RHS.LocalOffset, RHS.FrameIdx); } MachineBasicBlock::iterator getMachineInstr() const { return MI; } int64_t getLocalOffset() const { return LocalOffset; } @@ -318,8 +319,9 @@ bool LocalStackSlotPass::insertFrameReferenceRegisters(MachineFunction &Fn) { } } - // Sort the frame references by local offset - array_pod_sort(FrameReferenceInsns.begin(), FrameReferenceInsns.end()); + // Sort the frame references by local offset. + // Use frame index as a tie-breaker in case MI's have the same offset. + std::sort(FrameReferenceInsns.begin(), FrameReferenceInsns.end()); MachineBasicBlock *Entry = &Fn.front(); diff --git a/lib/CodeGen/MachineScheduler.cpp b/lib/CodeGen/MachineScheduler.cpp index f431ee9ba00..a43277cb8dc 100644 --- a/lib/CodeGen/MachineScheduler.cpp +++ b/lib/CodeGen/MachineScheduler.cpp @@ -1359,7 +1359,8 @@ class BaseMemOpClusterMutation : public ScheduleDAGMutation { : SU(su), BaseReg(reg), Offset(ofs) {} bool operator<(const MemOpInfo&RHS) const { - return std::tie(BaseReg, Offset) < std::tie(RHS.BaseReg, RHS.Offset); + return std::tie(BaseReg, Offset, SU->NodeNum) < + std::tie(RHS.BaseReg, RHS.Offset, RHS.SU->NodeNum); } }; -- 2.50.1