[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 15:01:57 PDT 2017


craig.topper updated this revision to Diff 93713.
craig.topper added a comment.

Add the test case update. The first 3 of them are the same as https://reviews.llvm.org/D31120


https://reviews.llvm.org/D31552

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


Index: test/Transforms/InstCombine/and2.ll
===================================================================
--- test/Transforms/InstCombine/and2.ll
+++ test/Transforms/InstCombine/and2.ll
@@ -126,8 +126,7 @@
 define i32 @test11(i32 %a, i32 %b) {
 ; CHECK-LABEL: @test11(
 ; CHECK-NEXT:    [[X:%.*]] = shl i32 [[A:%.*]], 8
-; CHECK-NEXT:    [[Y:%.*]] = add i32 [[X]], [[B:%.*]]
-; CHECK-NEXT:    [[Z:%.*]] = and i32 [[Y]], 128
+; CHECK-NEXT:    [[Z:%.*]] = and i32 [[B:%.*]], 128
 ; CHECK-NEXT:    [[W:%.*]] = mul i32 [[Z]], [[X]]
 ; CHECK-NEXT:    ret i32 [[W]]
 ;
@@ -142,8 +141,7 @@
 define i32 @test12(i32 %a, i32 %b) {
 ; CHECK-LABEL: @test12(
 ; CHECK-NEXT:    [[X:%.*]] = shl i32 [[A:%.*]], 8
-; CHECK-NEXT:    [[Y:%.*]] = add i32 [[X]], [[B:%.*]]
-; CHECK-NEXT:    [[Z:%.*]] = and i32 [[Y]], 128
+; CHECK-NEXT:    [[Z:%.*]] = and i32 [[B:%.*]], 128
 ; CHECK-NEXT:    [[W:%.*]] = mul i32 [[Z]], [[X]]
 ; CHECK-NEXT:    ret i32 [[W]]
 ;
@@ -158,8 +156,7 @@
 define i32 @test13(i32 %a, i32 %b) {
 ; CHECK-LABEL: @test13(
 ; CHECK-NEXT:    [[X:%.*]] = shl i32 [[A:%.*]], 8
-; CHECK-NEXT:    [[Y:%.*]] = sub i32 [[B:%.*]], [[X]]
-; CHECK-NEXT:    [[Z:%.*]] = and i32 [[Y]], 128
+; CHECK-NEXT:    [[Z:%.*]] = and i32 [[B:%.*]], 128
 ; CHECK-NEXT:    [[W:%.*]] = mul i32 [[Z]], [[X]]
 ; CHECK-NEXT:    ret i32 [[W]]
 ;
@@ -174,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: 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.93713.patch
Type: text/x-patch
Size: 2358 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170331/57100734/attachment-0001.bin>


More information about the llvm-commits mailing list