From: Nikita Popov Date: Sun, 29 Mar 2020 15:38:23 +0000 (+0200) Subject: [InstCombine] Fix worklist management in varargs transform X-Git-Tag: llvmorg-12-init~10813 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=28f67bd5c56ba9c466b1fef600923483a967aa97;p=platform%2Fupstream%2Fllvm.git [InstCombine] Fix worklist management in varargs transform Add a replaceUse() helper to mirror replaceOperand() for the rare cases where we're working directly on uses. NFC apart from worklist order changes. --- diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index b28da94..d9e2c52 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -4573,7 +4573,7 @@ Instruction *InstCombiner::visitCallBase(CallBase &Call) { I != E; ++I, ++ix) { CastInst *CI = dyn_cast(*I); if (CI && isSafeToEliminateVarargsCast(Call, DL, CI, ix)) { - *I = CI->getOperand(0); + replaceUse(*I, CI->getOperand(0)); // Update the byval type to match the argument type. if (Call.isByValArgument(ix)) { diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index d6053c2..f21c7d14 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -686,6 +686,12 @@ public: return &I; } + /// Replace use and add the previously used value to the worklist. + void replaceUse(Use &U, Value *NewValue) { + Worklist.addValue(U); + U = NewValue; + } + /// Creates a result tuple for an overflow intrinsic \p II with a given /// \p Result and a constant \p Overflow value. Instruction *CreateOverflowTuple(IntrinsicInst *II, Value *Result, diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp index e697b99..77a8410 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp @@ -87,9 +87,7 @@ bool InstCombiner::SimplifyDemandedBits(Instruction *I, unsigned OpNo, Value *NewVal = SimplifyDemandedUseBits(U.get(), DemandedMask, Known, Depth, I); if (!NewVal) return false; - // Add the old operand back to the worklist. - Worklist.addValue(U.get()); - U = NewVal; + replaceUse(U, NewVal); return true; }