llvm.org GIT mirror llvm / f3bbc06
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 Tom Stellard 2 years ago
1 changed file(s) with 8 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "llvm/Transforms/Scalar/DivRemPairs.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/MapVector.h"
1517 #include "llvm/ADT/Statistic.h"
1618 #include "llvm/Analysis/GlobalsModRef.h"
1719 #include "llvm/Analysis/TargetTransformInfo.h"
4749
4850 // Insert all divide and remainder instructions into maps keyed by their
4951 // operands and opcode (signed or unsigned).
50 DenseMap DivMap, RemMap;
52 DenseMap DivMap;
53 // Use a MapVector for RemMap so that instructions are moved/inserted in a
54 // deterministic order.
55 MapVector RemMap;
5156 for (auto &BB : F) {
5257 for (auto &I : BB) {
5358 if (I.getOpcode() == Instruction::SDiv)
6671 // rare than division.
6772 for (auto &RemPair : RemMap) {
6873 // Find the matching division instruction from the division map.
69 Instruction *DivInst = DivMap[RemPair.getFirst()];
74 Instruction *DivInst = DivMap[RemPair.first];
7075 if (!DivInst)
7176 continue;
7277
7378 // We have a matching pair of div/rem instructions. If one dominates the
7479 // other, hoist and/or replace one.
7580 NumPairs++;
76 Instruction *RemInst = RemPair.getSecond();
81 Instruction *RemInst = RemPair.second;
7782 bool IsSigned = DivInst->getOpcode() == Instruction::SDiv;
7883 bool HasDivRemOp = TTI.hasDivRemOp(DivInst->getType(), IsSigned);
7984