[PATCH] D31552: [InstCombine] Teach SimplifyDemandedInstructionBits that even if we reach an instruction that has multiple uses, if we know all the bits for the demanded bits for this context we can go ahead and create a constant.

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 31 14:59:42 PDT 2017


craig.topper created this revision.

Currently if we reach an instruction with multiples uses we know we can't do any optimizations to that instruction itself since we only have the demanded bits for one of the users. But if we know all of the bits are zero/one for that one user we can still go ahead and create a constant to give to that user.

This might then reduce the instruction to having a single use and allow additional optimizations on the other path.

This picks up an additional transformation that the patch for https://reviews.llvm.org/D31120 didn't catch.


https://reviews.llvm.org/D31552

Files:
  lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp


Index: lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -227,6 +227,12 @@
 
     // Compute the KnownZero/KnownOne bits to simplify things downstream.
     computeKnownBits(I, KnownZero, KnownOne, Depth, CxtI);
+
+    // If the client is only demanding bits that we know, return the known
+    // constant.
+    if ((DemandedMask & (KnownZero|KnownOne)) == DemandedMask)
+      return Constant::getIntegerValue(VTy, KnownOne);
+
     return nullptr;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31552.93711.patch
Type: text/x-patch
Size: 664 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170331/f46111a5/attachment.bin>


More information about the llvm-commits mailing list