From: Craig Topper Date: Wed, 8 May 2019 20:59:21 +0000 (+0000) Subject: [InstCombine] When turning sext into zext due to known bits, return the new ZExt... X-Git-Tag: android-x86-9.0-r1~3667 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=780dedf4b06041036a442a35e317a8a2ff3f2284;p=android-x86%2Fexternal-llvm.git [InstCombine] When turning sext into zext due to known bits, return the new ZExt instead of calling replaceinstuseswith The worklist loop that we're returning back to should be able to do the repacement itself. This is how we normally do replacements. My main motivation was that I observed that we weren't preserving the name of the result when we do this transform. The replacement code in the worklist loop will call takeName as part of the replacement. Differential Revision: https://reviews.llvm.org/D61695 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360284 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp index 91fdda45ac7..1faaf0bf6af 100644 --- a/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1372,10 +1372,8 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) { // If we know that the value being extended is positive, we can use a zext // instead. KnownBits Known = computeKnownBits(Src, 0, &CI); - if (Known.isNonNegative()) { - Value *ZExt = Builder.CreateZExt(Src, DestTy); - return replaceInstUsesWith(CI, ZExt); - } + if (Known.isNonNegative()) + return CastInst::Create(Instruction::ZExt, Src, DestTy); // Try to extend the entire expression tree to the wide destination type. if (shouldChangeType(SrcTy, DestTy) && canEvaluateSExtd(Src, DestTy)) {