[llvm] r284441 - Fix differences in codegen between Linux and Windows toolchains
Mandeep Singh Grang via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 17 17:11:19 PDT 2016
Author: mgrang
Date: Mon Oct 17 19:11:19 2016
New Revision: 284441
URL: http://llvm.org/viewvc/llvm-project?rev=284441&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/Analysis/RegionInfo.h
llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp
llvm/trunk/lib/CodeGen/MachineScheduler.cpp
Modified: llvm/trunk/include/llvm/Analysis/RegionInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/RegionInfo.h?rev=284441&r1=284440&r2=284441&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/RegionInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/RegionInfo.h Mon Oct 17 19:11:19 2016
@@ -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<BlockT *, BlockT *> BBtoBBMap;
typedef DenseMap<BlockT *, RegionT *> BBtoRegionMap;
- typedef SmallPtrSet<RegionT *, 4> RegionSet;
+ typedef SmallSetVector<RegionT *, 4> RegionSet;
RegionInfoBase();
virtual ~RegionInfoBase();
Modified: llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp?rev=284441&r1=284440&r2=284441&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp (original)
+++ llvm/trunk/lib/CodeGen/LocalStackSlotAllocation.cpp Mon Oct 17 19:11:19 2016
@@ -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::insertFrameRefe
}
}
- // 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();
Modified: llvm/trunk/lib/CodeGen/MachineScheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineScheduler.cpp?rev=284441&r1=284440&r2=284441&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineScheduler.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineScheduler.cpp Mon Oct 17 19:11:19 2016
@@ -1359,7 +1359,8 @@ class BaseMemOpClusterMutation : public
: 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);
}
};
More information about the llvm-commits
mailing list