mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-06 23:32:27 +00:00
Fix indvars randomness by removing iteration over a map.
I rewrote the algorithm a while back so it doesn't require map lookup, but neglected to change the data structure. This was caught by llvm-gcc self host, not because there's anything special about llvm-gcc, but because it is the only test for nondeterminism we currently have. Unit tests don't work well for everything; we should always try to have a nondeterminism stress test running. Fixes PR11133: llvm-gcc self host .o mismatch after enable-iv-rewrite=false git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142036 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4ed1fb0095
commit
513b1f47c1
@ -721,10 +721,11 @@ namespace {
|
|||||||
// extend operations. This information is recorded by CollectExtend and
|
// extend operations. This information is recorded by CollectExtend and
|
||||||
// provides the input to WidenIV.
|
// provides the input to WidenIV.
|
||||||
struct WideIVInfo {
|
struct WideIVInfo {
|
||||||
|
PHINode *NarrowIV;
|
||||||
Type *WidestNativeType; // Widest integer type created [sz]ext
|
Type *WidestNativeType; // Widest integer type created [sz]ext
|
||||||
bool IsSigned; // Was an sext user seen before a zext?
|
bool IsSigned; // Was an sext user seen before a zext?
|
||||||
|
|
||||||
WideIVInfo() : WidestNativeType(0), IsSigned(false) {}
|
WideIVInfo() : NarrowIV(0), WidestNativeType(0), IsSigned(false) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class WideIVVisitor : public IVVisitor {
|
class WideIVVisitor : public IVVisitor {
|
||||||
@ -734,8 +735,9 @@ namespace {
|
|||||||
public:
|
public:
|
||||||
WideIVInfo WI;
|
WideIVInfo WI;
|
||||||
|
|
||||||
WideIVVisitor(ScalarEvolution *SCEV, const TargetData *TData) :
|
WideIVVisitor(PHINode *NarrowIV, ScalarEvolution *SCEV,
|
||||||
SE(SCEV), TD(TData) {}
|
const TargetData *TData) :
|
||||||
|
SE(SCEV), TD(TData) { WI.NarrowIV = NarrowIV; }
|
||||||
|
|
||||||
// Implement the interface used by simplifyUsersOfIV.
|
// Implement the interface used by simplifyUsersOfIV.
|
||||||
virtual void visitCast(CastInst *Cast);
|
virtual void visitCast(CastInst *Cast);
|
||||||
@ -812,10 +814,10 @@ class WidenIV {
|
|||||||
SmallVector<NarrowIVDefUse, 8> NarrowIVUsers;
|
SmallVector<NarrowIVDefUse, 8> NarrowIVUsers;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WidenIV(PHINode *PN, const WideIVInfo &WI, LoopInfo *LInfo,
|
WidenIV(const WideIVInfo &WI, LoopInfo *LInfo,
|
||||||
ScalarEvolution *SEv, DominatorTree *DTree,
|
ScalarEvolution *SEv, DominatorTree *DTree,
|
||||||
SmallVectorImpl<WeakVH> &DI) :
|
SmallVectorImpl<WeakVH> &DI) :
|
||||||
OrigPhi(PN),
|
OrigPhi(WI.NarrowIV),
|
||||||
WideType(WI.WidestNativeType),
|
WideType(WI.WidestNativeType),
|
||||||
IsSigned(WI.IsSigned),
|
IsSigned(WI.IsSigned),
|
||||||
LI(LInfo),
|
LI(LInfo),
|
||||||
@ -1181,7 +1183,7 @@ PHINode *WidenIV::CreateWideIV(SCEVExpander &Rewriter) {
|
|||||||
void IndVarSimplify::SimplifyAndExtend(Loop *L,
|
void IndVarSimplify::SimplifyAndExtend(Loop *L,
|
||||||
SCEVExpander &Rewriter,
|
SCEVExpander &Rewriter,
|
||||||
LPPassManager &LPM) {
|
LPPassManager &LPM) {
|
||||||
std::map<PHINode *, WideIVInfo> WideIVMap;
|
SmallVector<WideIVInfo, 8> WideIVs;
|
||||||
|
|
||||||
SmallVector<PHINode*, 8> LoopPhis;
|
SmallVector<PHINode*, 8> LoopPhis;
|
||||||
for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I) {
|
for (BasicBlock::iterator I = L->getHeader()->begin(); isa<PHINode>(I); ++I) {
|
||||||
@ -1202,24 +1204,22 @@ void IndVarSimplify::SimplifyAndExtend(Loop *L,
|
|||||||
PHINode *CurrIV = LoopPhis.pop_back_val();
|
PHINode *CurrIV = LoopPhis.pop_back_val();
|
||||||
|
|
||||||
// Information about sign/zero extensions of CurrIV.
|
// Information about sign/zero extensions of CurrIV.
|
||||||
WideIVVisitor WIV(SE, TD);
|
WideIVVisitor WIV(CurrIV, SE, TD);
|
||||||
|
|
||||||
Changed |= simplifyUsersOfIV(CurrIV, SE, &LPM, DeadInsts, &WIV);
|
Changed |= simplifyUsersOfIV(CurrIV, SE, &LPM, DeadInsts, &WIV);
|
||||||
|
|
||||||
if (WIV.WI.WidestNativeType) {
|
if (WIV.WI.WidestNativeType) {
|
||||||
WideIVMap[CurrIV] = WIV.WI;
|
WideIVs.push_back(WIV.WI);
|
||||||
}
|
}
|
||||||
} while(!LoopPhis.empty());
|
} while(!LoopPhis.empty());
|
||||||
|
|
||||||
for (std::map<PHINode *, WideIVInfo>::const_iterator I = WideIVMap.begin(),
|
for (; !WideIVs.empty(); WideIVs.pop_back()) {
|
||||||
E = WideIVMap.end(); I != E; ++I) {
|
WidenIV Widener(WideIVs.back(), LI, SE, DT, DeadInsts);
|
||||||
WidenIV Widener(I->first, I->second, LI, SE, DT, DeadInsts);
|
|
||||||
if (PHINode *WidePhi = Widener.CreateWideIV(Rewriter)) {
|
if (PHINode *WidePhi = Widener.CreateWideIV(Rewriter)) {
|
||||||
Changed = true;
|
Changed = true;
|
||||||
LoopPhis.push_back(WidePhi);
|
LoopPhis.push_back(WidePhi);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WideIVMap.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user