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
// 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;
}
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]]