]> granicus.if.org Git - llvm/commitdiff
[InstCombine] Teach SimplifyDemandedInstructionBits that even if we reach an instruct...
authorCraig Topper <craig.topper@gmail.com>
Wed, 12 Apr 2017 18:17:46 +0000 (18:17 +0000)
committerCraig Topper <craig.topper@gmail.com>
Wed, 12 Apr 2017 18:17:46 +0000 (18:17 +0000)
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 case that r300075 didn't catch.

Differential Revision: https://reviews.llvm.org/D31552

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300084 91177308-0d34-0410-b5e6-96231b3b80d8

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

index dd789fad569c0e6438409e8b360538b3e4296e2f..279f44c2eaeba5a9f922863b6c2cd2fafe6e6916 100644 (file)
@@ -834,6 +834,12 @@ Value *InstCombiner::SimplifyMultipleUseDemandedBits(Instruction *I,
 
   // 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;
 }
 
index 0b4882fa823ead886c8f8c5b1d78d17932cbf6ef..1af248b804c0beeac0ad1c952af41383f4a8c0c3 100644 (file)
@@ -171,7 +171,7 @@ define i32 @test13(i32 %a, i32 %b) {
 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]]