Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions llvm/lib/Transforms/IPO/ConstantMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ static bool mergeConstants(Module &M) {
// Now that we have figured out which replacements must be made, do them all
// now. This avoid invalidating the pointers in CMap, which are unneeded
// now.
for (unsigned i = 0, e = SameContentReplacements.size(); i != e; ++i) {
GlobalVariable *Old = SameContentReplacements[i].first;
GlobalVariable *New = SameContentReplacements[i].second;
for (const auto &[Old, New] : SameContentReplacements) {
replace(M, Old, New);
++ChangesMade;
++NumIdenticalMerged;
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3036,12 +3036,12 @@ bool GVNPass::performScalarPRE(Instruction *CurInst) {
PHINode *Phi = PHINode::Create(CurInst->getType(), PredMap.size(),
CurInst->getName() + ".pre-phi");
Phi->insertBefore(CurrentBlock->begin());
for (unsigned I = 0, E = PredMap.size(); I != E; ++I) {
if (Value *V = PredMap[I].first) {
for (auto &[V, BB] : PredMap) {
if (V) {
// If we use an existing value in this phi, we have to patch the original
// value because the phi will be used to replace a later value.
patchReplacementInstruction(CurInst, V);
Phi->addIncoming(V, PredMap[I].second);
Phi->addIncoming(V, BB);
} else
Phi->addIncoming(PREInstr, PREPred);
}
Expand Down
8 changes: 3 additions & 5 deletions llvm/lib/Transforms/Scalar/Reassociate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,10 +1115,8 @@ Value *ReassociatePass::RemoveFactorFromExpression(Value *V, Value *Factor,
MadeChange |= LinearizeExprTree(BO, Tree, RedoInsts, Flags);
SmallVector<ValueEntry, 8> Factors;
Factors.reserve(Tree.size());
for (unsigned i = 0, e = Tree.size(); i != e; ++i) {
RepeatedValue E = Tree[i];
for (const RepeatedValue &E : Tree)
Factors.append(E.second, ValueEntry(getRank(E.first), E.first));
}

bool FoundFactor = false;
bool NeedsNegate = false;
Expand Down Expand Up @@ -1391,8 +1389,8 @@ Value *ReassociatePass::OptimizeXor(Instruction *I,
APInt ConstOpnd(Ty->getScalarSizeInBits(), 0);

// Step 1: Convert ValueEntry to XorOpnd
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
Value *V = Ops[i].Op;
for (const ValueEntry &Op : Ops) {
Value *V = Op.Op;
const APInt *C;
// TODO: Support non-splat vectors.
if (match(V, m_APInt(C))) {
Expand Down
24 changes: 11 additions & 13 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,8 @@ bool SimplifyCFGOpt::simplifyEqualityComparisonWithOnlyPredecessor(
SwitchInstProfUpdateWrapper SI = *cast<SwitchInst>(TI);
// Okay, TI has cases that are statically dead, prune them away.
SmallPtrSet<Constant *, 16> DeadCases;
for (unsigned i = 0, e = PredCases.size(); i != e; ++i)
DeadCases.insert(PredCases[i].Value);
for (const ValueEqualityComparisonCase &Case : PredCases)
DeadCases.insert(Case.Value);

LLVM_DEBUG(dbgs() << "Threading pred instr: " << *Pred->getTerminator()
<< "Through successor TI: " << *TI);
Expand Down Expand Up @@ -1307,14 +1307,14 @@ bool SimplifyCFGOpt::performValueComparisonIntoPredecessorFolding(

// Okay, now we know which constants were sent to BB from the
// predecessor. Figure out where they will all go now.
for (unsigned i = 0, e = BBCases.size(); i != e; ++i)
if (PTIHandled.count(BBCases[i].Value)) {
for (const ValueEqualityComparisonCase &Case : BBCases)
if (PTIHandled.count(Case.Value)) {
// If this is one we are capable of getting...
if (PredHasWeights || SuccHasWeights)
Weights.push_back(WeightsForHandled[BBCases[i].Value]);
PredCases.push_back(BBCases[i]);
++NewSuccessors[BBCases[i].Dest];
PTIHandled.erase(BBCases[i].Value); // This constant is taken care of
Weights.push_back(WeightsForHandled[Case.Value]);
PredCases.push_back(Case);
++NewSuccessors[Case.Dest];
PTIHandled.erase(Case.Value); // This constant is taken care of
}

// If there are any constants vectored to BB that TI doesn't handle,
Expand Down Expand Up @@ -5177,8 +5177,8 @@ bool SimplifyCFGOpt::simplifyBranchOnICmpChain(BranchInst *BI,
SwitchInst *New = Builder.CreateSwitch(CompVal, DefaultBB, Values.size());

// Add all of the 'cases' to the switch instruction.
for (unsigned i = 0, e = Values.size(); i != e; ++i)
New->addCase(Values[i], EdgeBB);
for (ConstantInt *Val : Values)
New->addCase(Val, EdgeBB);

// We added edges from PI to the EdgeBB. As such, if there were any
// PHI nodes in EdgeBB, they need entries to be added corresponding to
Expand Down Expand Up @@ -6453,9 +6453,7 @@ SwitchLookupTable::SwitchLookupTable(

// Build up the table contents.
SmallVector<Constant *, 64> TableContents(TableSize);
for (size_t I = 0, E = Values.size(); I != E; ++I) {
ConstantInt *CaseVal = Values[I].first;
Constant *CaseRes = Values[I].second;
for (const auto &[CaseVal, CaseRes] : Values) {
assert(CaseRes->getType() == ValueType);

uint64_t Idx = (CaseVal->getValue() - Offset->getValue()).getLimitedValue();
Expand Down