From: Nikita Popov Date: Sun, 29 Mar 2020 18:07:46 +0000 (+0200) Subject: [InstCombine] Use replaceOperand() in demanded elements simplification X-Git-Tag: llvmorg-12-init~10797 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=53d209076aa877e4e40edaaf3614f33285e1851b;p=platform%2Fupstream%2Fllvm.git [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. --- diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index d9e2c52..c417678 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 77a8410..a2437b3 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(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 bc6696a..b866f44 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.