[llvm] r298478 - [InstCombine] Teach SimplifyDemandedUseBits to shrink Constants on the left side of subtracts
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 21 21:03:53 PDT 2017
Author: ctopper
Date: Tue Mar 21 23:03:53 2017
New Revision: 298478
URL: http://llvm.org/viewvc/llvm-project?rev=298478&view=rev
Log:
[InstCombine] Teach SimplifyDemandedUseBits to shrink Constants on the left side of subtracts
Summary: Subtracts can have constants on the left side, but we don't shrink them based on demanded bits. This patch fixes that to match the right hand side.
Reviewers: davide, majnemer, spatel, sanjoy, hfinkel
Reviewed By: spatel
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D31119
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
llvm/trunk/test/Transforms/InstCombine/sub.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp?rev=298478&r1=298477&r2=298478&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp Tue Mar 21 23:03:53 2017
@@ -533,7 +533,8 @@ Value *InstCombiner::SimplifyDemandedUse
// Right fill the mask of bits for this ADD/SUB to demand the most
// significant bit and all those below it.
APInt DemandedFromOps(APInt::getLowBitsSet(BitWidth, BitWidth-NLZ));
- if (SimplifyDemandedBits(I->getOperandUse(0), DemandedFromOps,
+ if (ShrinkDemandedConstant(I, 0, DemandedFromOps) ||
+ SimplifyDemandedBits(I->getOperandUse(0), DemandedFromOps,
LHSKnownZero, LHSKnownOne, Depth + 1) ||
ShrinkDemandedConstant(I, 1, DemandedFromOps) ||
SimplifyDemandedBits(I->getOperandUse(1), DemandedFromOps,
Modified: llvm/trunk/test/Transforms/InstCombine/sub.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/sub.ll?rev=298478&r1=298477&r2=298478&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/sub.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/sub.ll Tue Mar 21 23:03:53 2017
@@ -701,3 +701,46 @@ define i8 @bool_sext_sub_nuw(i8 %x, i1 %
ret i8 %sub
}
+define i32 @test49(i32 %X) {
+; CHECK-LABEL: @test49(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 1, [[X:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = and i32 [[SUB]], 64
+; CHECK-NEXT: ret i32 [[RES]]
+;
+ %sub = sub i32 129, %X
+ %res = and i32 %sub, 64
+ ret i32 %res
+}
+
+define i32 @test50(i32 %X) {
+; CHECK-LABEL: @test50(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 1, [[X:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = and i32 [[SUB]], 127
+; CHECK-NEXT: ret i32 [[RES]]
+;
+ %sub = sub i32 129, %X
+ %res = and i32 %sub, 127
+ ret i32 %res
+}
+
+define i32 @test51(i32 %X) {
+; CHECK-LABEL: @test51(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 126, [[X:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = and i32 [[SUB]], 64
+; CHECK-NEXT: ret i32 [[RES]]
+;
+ %sub = sub i32 254, %X
+ %res = and i32 %sub, 64
+ ret i32 %res
+}
+
+define i32 @test52(i32 %X) {
+; CHECK-LABEL: @test52(
+; CHECK-NEXT: [[SUB:%.*]] = sub i32 126, [[X:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = and i32 [[SUB]], 127
+; CHECK-NEXT: ret i32 [[RES]]
+;
+ %sub = sub i32 254, %X
+ %res = and i32 %sub, 127
+ ret i32 %res
+}
More information about the llvm-commits
mailing list