[llvm] 53d2090 - [InstCombine] Use replaceOperand() in demanded elements simplification
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 29 11:43:34 PDT 2020
Author: Nikita Popov
Date: 2020-03-29T20:43:19+02:00
New Revision: 53d209076aa877e4e40edaaf3614f33285e1851b
URL: https://github.com/llvm/llvm-project/commit/53d209076aa877e4e40edaaf3614f33285e1851b
DIFF: https://github.com/llvm/llvm-project/commit/53d209076aa877e4e40edaaf3614f33285e1851b.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index d9e2c52a9341..c41767894205 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -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)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 77a84100ea4c..a2437b3abe30 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -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;
}
};
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index bc6696a2a325..b866f44779eb 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -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.
More information about the llvm-commits
mailing list