Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit f3bbc06

Browse files
committed
Merging r330792:
------------------------------------------------------------------------ r330792 | gberry | 2018-04-24 19:17:56 -0700 (Tue, 24 Apr 2018) | 14 lines [DivRemPairs] Fix non-determinism in use list order. Summary: Use a MapVector instead of a DenseMap for RemMap since it is iteratated over and the order of iteration can effect the order that new instructions are created. This can in turn effect the use list order of div/rem input values if multiple new instructions are created that share any input values. Reviewers: spatel Subscribers: mcrosier, llvm-commits Differential Revision: https://reviews.llvm.org/D45858 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@332080 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a6a3cde commit f3bbc06

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/Transforms/Scalar/DivRemPairs.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
#include "llvm/Transforms/Scalar/DivRemPairs.h"
16+
#include "llvm/ADT/DenseMap.h"
17+
#include "llvm/ADT/MapVector.h"
1618
#include "llvm/ADT/Statistic.h"
1719
#include "llvm/Analysis/GlobalsModRef.h"
1820
#include "llvm/Analysis/TargetTransformInfo.h"
@@ -48,7 +50,10 @@ static bool optimizeDivRem(Function &F, const TargetTransformInfo &TTI,
4850

4951
// Insert all divide and remainder instructions into maps keyed by their
5052
// operands and opcode (signed or unsigned).
51-
DenseMap<DivRemMapKey, Instruction *> DivMap, RemMap;
53+
DenseMap<DivRemMapKey, Instruction *> DivMap;
54+
// Use a MapVector for RemMap so that instructions are moved/inserted in a
55+
// deterministic order.
56+
MapVector<DivRemMapKey, Instruction *> RemMap;
5257
for (auto &BB : F) {
5358
for (auto &I : BB) {
5459
if (I.getOpcode() == Instruction::SDiv)
@@ -67,14 +72,14 @@ static bool optimizeDivRem(Function &F, const TargetTransformInfo &TTI,
6772
// rare than division.
6873
for (auto &RemPair : RemMap) {
6974
// Find the matching division instruction from the division map.
70-
Instruction *DivInst = DivMap[RemPair.getFirst()];
75+
Instruction *DivInst = DivMap[RemPair.first];
7176
if (!DivInst)
7277
continue;
7378

7479
// We have a matching pair of div/rem instructions. If one dominates the
7580
// other, hoist and/or replace one.
7681
NumPairs++;
77-
Instruction *RemInst = RemPair.getSecond();
82+
Instruction *RemInst = RemPair.second;
7883
bool IsSigned = DivInst->getOpcode() == Instruction::SDiv;
7984
bool HasDivRemOp = TTI.hasDivRemOp(DivInst->getType(), IsSigned);
8085

0 commit comments

Comments
 (0)