[llvm] r360284 - [InstCombine] When turning sext into zext due to known bits, return the new ZExt instead of calling replaceinstuseswith

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 13:59:22 PDT 2019


Author: ctopper
Date: Wed May  8 13:59:21 2019
New Revision: 360284

URL: http://llvm.org/viewvc/llvm-project?rev=360284&view=rev
Log:
[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

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp?rev=360284&r1=360283&r2=360284&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCasts.cpp Wed May  8 13:59:21 2019
@@ -1372,10 +1372,8 @@ Instruction *InstCombiner::visitSExt(SEx
   // 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)) {




More information about the llvm-commits mailing list