[VectorCombine] add helper to replace uses and rename

The tests are regenerated to show a path that missed renaming,
but there should be no functional difference from this patch.
This commit is contained in:
Sanjay Patel
2020-06-22 09:26:46 -04:00
parent 8383ac6197
commit 98c2f4eea5
3 changed files with 33 additions and 31 deletions

View File

@@ -76,6 +76,11 @@ private:
bool scalarizeBinopOrCmp(Instruction &I);
};
static void replaceValue(Value &Old, Value &New) {
Old.replaceAllUsesWith(&New);
New.takeName(&Old);
}
/// Compare the relative costs of 2 extracts followed by scalar operation vs.
/// vector operation(s) followed by extract. Return true if the existing
/// instructions are cheaper than a vector alternative. Otherwise, return false
@@ -228,8 +233,7 @@ void VectorCombine::foldExtExtCmp(ExtractElementInst *Ext0,
Value *V0 = Ext0->getVectorOperand(), *V1 = Ext1->getVectorOperand();
Value *VecCmp = Builder.CreateCmp(Pred, V0, V1);
Value *NewExt = Builder.CreateExtractElement(VecCmp, Ext0->getIndexOperand());
I.replaceAllUsesWith(NewExt);
NewExt->takeName(&I);
replaceValue(I, *NewExt);
}
/// Try to reduce extract element costs by converting scalar binops to vector
@@ -254,8 +258,7 @@ void VectorCombine::foldExtExtBinop(ExtractElementInst *Ext0,
VecBOInst->copyIRFlags(&I);
Value *NewExt = Builder.CreateExtractElement(VecBO, Ext0->getIndexOperand());
I.replaceAllUsesWith(NewExt);
NewExt->takeName(&I);
replaceValue(I, *NewExt);
}
/// Match an instruction with extracted vector operands.
@@ -360,7 +363,7 @@ bool VectorCombine::foldBitcastShuf(Instruction &I) {
Value *CastV = Builder.CreateBitCast(V, DestTy);
Value *Shuf =
Builder.CreateShuffleVector(CastV, UndefValue::get(DestTy), NewMask);
I.replaceAllUsesWith(Shuf);
replaceValue(I, *Shuf);
return true;
}
@@ -477,8 +480,7 @@ bool VectorCombine::scalarizeBinopOrCmp(Instruction &I) {
Constant *NewVecC = IsCmp ? ConstantExpr::getCompare(Pred, VecC0, VecC1)
: ConstantExpr::get(Opcode, VecC0, VecC1);
Value *Insert = Builder.CreateInsertElement(NewVecC, Scalar, Index);
I.replaceAllUsesWith(Insert);
Insert->takeName(&I);
replaceValue(I, *Insert);
return true;
}