[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.

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 12 11:30:37 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL300084: [InstCombine] Teach SimplifyDemandedInstructionBits that even if we reach an… (authored by ctopper).

Changed prior to commit:
  https://reviews.llvm.org/D31552?vs=93713&id=95007#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31552

Files:
  llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
  llvm/trunk/test/Transforms/InstCombine/and2.ll


Index: llvm/trunk/test/Transforms/InstCombine/and2.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/and2.ll
+++ llvm/trunk/test/Transforms/InstCombine/and2.ll
@@ -171,7 +171,7 @@
 define i32 @test14(i32 %a, i32 %b) {
 ; CHECK-LABEL: @test14(
 ; CHECK-NEXT:    [[X:%.*]] = shl i32 [[A:%.*]], 8
-; CHECK-NEXT:    [[Y:%.*]] = sub i32 [[X]], [[B:%.*]]
+; CHECK-NEXT:    [[Y:%.*]] = sub i32 0, [[B:%.*]]
 ; CHECK-NEXT:    [[Z:%.*]] = and i32 [[Y]], 128
 ; CHECK-NEXT:    [[W:%.*]] = mul i32 [[Z]], [[X]]
 ; CHECK-NEXT:    ret i32 [[W]]
Index: llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
===================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -834,6 +834,12 @@
 
   // Compute the KnownZero/KnownOne bits to simplify things downstream.
   computeKnownBits(I, KnownZero, KnownOne, Depth, CxtI);
+
+  // If this user is only demanding bits that we know, return the known
+  // constant.
+  if ((DemandedMask & (KnownZero|KnownOne)) == DemandedMask)
+    return Constant::getIntegerValue(ITy, KnownOne);
+
   return nullptr;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31552.95007.patch
Type: text/x-patch
Size: 1276 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170412/4ac02fe4/attachment.bin>


More information about the llvm-commits mailing list