forked from OSchip/llvm-project
[InstCombine] Use replaceOperand() in demanded elements simplification
To make sure that dead operands get DCEd. This fixes the largest source of leftover dead operands we see in tests. NFC apart from worklist changes.
This commit is contained in:
parent
4e4ea2cde4
commit
53d209076a
|
@ -1164,10 +1164,8 @@ Instruction *InstCombiner::simplifyMaskedStore(IntrinsicInst &II) {
|
|||
APInt DemandedElts = possiblyDemandedEltsInMask(ConstMask);
|
||||
APInt UndefElts(DemandedElts.getBitWidth(), 0);
|
||||
if (Value *V = SimplifyDemandedVectorElts(II.getOperand(0),
|
||||
DemandedElts, UndefElts)) {
|
||||
II.setOperand(0, V);
|
||||
return ⅈ
|
||||
}
|
||||
DemandedElts, UndefElts))
|
||||
return replaceOperand(II, 0, V);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1202,15 +1200,11 @@ Instruction *InstCombiner::simplifyMaskedScatter(IntrinsicInst &II) {
|
|||
APInt DemandedElts = possiblyDemandedEltsInMask(ConstMask);
|
||||
APInt UndefElts(DemandedElts.getBitWidth(), 0);
|
||||
if (Value *V = SimplifyDemandedVectorElts(II.getOperand(0),
|
||||
DemandedElts, UndefElts)) {
|
||||
II.setOperand(0, V);
|
||||
return ⅈ
|
||||
}
|
||||
DemandedElts, UndefElts))
|
||||
return replaceOperand(II, 0, V);
|
||||
if (Value *V = SimplifyDemandedVectorElts(II.getOperand(1),
|
||||
DemandedElts, UndefElts)) {
|
||||
II.setOperand(1, V);
|
||||
return ⅈ
|
||||
}
|
||||
DemandedElts, UndefElts))
|
||||
return replaceOperand(II, 1, V);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -2667,10 +2661,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
// we can simplify the input based on that, do so now.
|
||||
Value *Arg = II->getArgOperand(0);
|
||||
unsigned VWidth = Arg->getType()->getVectorNumElements();
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Arg, VWidth, 1)) {
|
||||
II->setArgOperand(0, V);
|
||||
return II;
|
||||
}
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Arg, VWidth, 1))
|
||||
return replaceOperand(*II, 0, V);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2720,11 +2712,11 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
Value *Arg1 = II->getArgOperand(1);
|
||||
unsigned VWidth = Arg0->getType()->getVectorNumElements();
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Arg0, VWidth, 1)) {
|
||||
II->setArgOperand(0, V);
|
||||
replaceOperand(*II, 0, V);
|
||||
MadeChange = true;
|
||||
}
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Arg1, VWidth, 1)) {
|
||||
II->setArgOperand(1, V);
|
||||
replaceOperand(*II, 1, V);
|
||||
MadeChange = true;
|
||||
}
|
||||
if (MadeChange)
|
||||
|
@ -2938,10 +2930,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
"Unexpected packed shift size");
|
||||
unsigned VWidth = Arg1->getType()->getVectorNumElements();
|
||||
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Arg1, VWidth, VWidth / 2)) {
|
||||
II->setArgOperand(1, V);
|
||||
return II;
|
||||
}
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Arg1, VWidth, VWidth / 2))
|
||||
return replaceOperand(*II, 1, V);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3012,7 +3002,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
APInt(2, (Imm & 0x01) ? 2 : 1));
|
||||
if (Value *V = SimplifyDemandedVectorElts(Arg0, DemandedElts1,
|
||||
UndefElts1)) {
|
||||
II->setArgOperand(0, V);
|
||||
replaceOperand(*II, 0, V);
|
||||
MadeChange = true;
|
||||
}
|
||||
|
||||
|
@ -3021,7 +3011,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
APInt(2, (Imm & 0x10) ? 2 : 1));
|
||||
if (Value *V = SimplifyDemandedVectorElts(Arg1, DemandedElts2,
|
||||
UndefElts2)) {
|
||||
II->setArgOperand(1, V);
|
||||
replaceOperand(*II, 1, V);
|
||||
MadeChange = true;
|
||||
}
|
||||
|
||||
|
@ -3068,11 +3058,11 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
// operands and the lowest 16-bits of the second.
|
||||
bool MadeChange = false;
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth0, 1)) {
|
||||
II->setArgOperand(0, V);
|
||||
replaceOperand(*II, 0, V);
|
||||
MadeChange = true;
|
||||
}
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Op1, VWidth1, 2)) {
|
||||
II->setArgOperand(1, V);
|
||||
replaceOperand(*II, 1, V);
|
||||
MadeChange = true;
|
||||
}
|
||||
if (MadeChange)
|
||||
|
@ -3098,10 +3088,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
|
||||
// EXTRQI only uses the lowest 64-bits of the first 128-bit vector
|
||||
// operand.
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth, 1)) {
|
||||
II->setArgOperand(0, V);
|
||||
return II;
|
||||
}
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth, 1))
|
||||
return replaceOperand(*II, 0, V);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3131,10 +3119,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
|
||||
// INSERTQ only uses the lowest 64-bits of the first 128-bit vector
|
||||
// operand.
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth, 1)) {
|
||||
II->setArgOperand(0, V);
|
||||
return II;
|
||||
}
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth, 1))
|
||||
return replaceOperand(*II, 0, V);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3166,11 +3152,11 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
// operands.
|
||||
bool MadeChange = false;
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Op0, VWidth0, 1)) {
|
||||
II->setArgOperand(0, V);
|
||||
replaceOperand(*II, 0, V);
|
||||
MadeChange = true;
|
||||
}
|
||||
if (Value *V = SimplifyDemandedVectorEltsLow(Op1, VWidth1, 1)) {
|
||||
II->setArgOperand(1, V);
|
||||
replaceOperand(*II, 1, V);
|
||||
MadeChange = true;
|
||||
}
|
||||
if (MadeChange)
|
||||
|
|
|
@ -1303,10 +1303,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
|
|||
auto *II = dyn_cast<IntrinsicInst>(Inst);
|
||||
Value *Op = II ? II->getArgOperand(OpNum) : Inst->getOperand(OpNum);
|
||||
if (Value *V = SimplifyDemandedVectorElts(Op, Demanded, Undef, Depth + 1)) {
|
||||
if (II)
|
||||
II->setArgOperand(OpNum, V);
|
||||
else
|
||||
Inst->setOperand(OpNum, V);
|
||||
replaceOperand(*Inst, OpNum, V);
|
||||
MadeChange = true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -345,10 +345,8 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
|
|||
APInt DemandedElts(NumElts, 0);
|
||||
DemandedElts.setBit(IndexC->getZExtValue());
|
||||
if (Value *V =
|
||||
SimplifyDemandedVectorElts(SrcVec, DemandedElts, UndefElts)) {
|
||||
EI.setOperand(0, V);
|
||||
return &EI;
|
||||
}
|
||||
SimplifyDemandedVectorElts(SrcVec, DemandedElts, UndefElts))
|
||||
return replaceOperand(EI, 0, V);
|
||||
} else {
|
||||
// If the input vector has multiple uses, simplify it based on a union
|
||||
// of all elements used.
|
||||
|
|
Loading…
Reference in New Issue