[PATCH] D61695: [InstCombine] When turning sext into zext due to known bits, return the new ZExt instead of calling replaceinstuseswith

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 13:32:48 PDT 2019


craig.topper created this revision.
craig.topper added a reviewer: spatel.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

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.


https://reviews.llvm.org/D61695

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1372,10 +1372,8 @@
   // 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)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61695.198715.patch
Type: text/x-patch
Size: 788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190508/c5574321/attachment.bin>


More information about the llvm-commits mailing list