Skip to content

Commit 7cd7f4a

Browse files
committedOct 21, 2019
[CVP] No-wrap deduction for shl
Summary: This is the last `OverflowingBinaryOperator` for which we don't deduce flags. D69217 taught `ConstantRange::makeGuaranteedNoWrapRegion()` about it. The effect is better than of the `mul` patch (D69203): | statistic | old | new | delta | % change | | correlated-value-propagation.NumAddNUW | 7145 | 7144 | -1 | -0.0140% | | correlated-value-propagation.NumAddNW | 12126 | 12125 | -1 | -0.0082% | | correlated-value-propagation.NumAnd | 443 | 446 | 3 | 0.6772% | | correlated-value-propagation.NumNSW | 5986 | 7158 | 1172 | 19.5790% | | correlated-value-propagation.NumNUW | 10512 | 13304 | 2792 | 26.5601% | | correlated-value-propagation.NumNW | 16498 | 20462 | 3964 | 24.0272% | | correlated-value-propagation.NumShlNSW | 0 | 1172 | 1172 | | | correlated-value-propagation.NumShlNUW | 0 | 2793 | 2793 | | | correlated-value-propagation.NumShlNW | 0 | 3965 | 3965 | | | instcount.NumAShrInst | 13824 | 13790 | -34 | -0.2459% | | instcount.NumAddInst | 277584 | 277586 | 2 | 0.0007% | | instcount.NumAndInst | 66061 | 66056 | -5 | -0.0076% | | instcount.NumBrInst | 709153 | 709147 | -6 | -0.0008% | | instcount.NumICmpInst | 483709 | 483708 | -1 | -0.0002% | | instcount.NumSExtInst | 79497 | 79496 | -1 | -0.0013% | | instcount.NumShlInst | 40691 | 40654 | -37 | -0.0909% | | instcount.NumSubInst | 61997 | 61996 | -1 | -0.0016% | | instcount.NumZExtInst | 68208 | 68211 | 3 | 0.0044% | | instcount.TotalBlocks | 843916 | 843910 | -6 | -0.0007% | | instcount.TotalInsts | 7387528 | 7387448 | -80 | -0.0011% | Reviewers: nikic, reames, sanjoy, timshen Reviewed By: nikic Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D69277 llvm-svn: 375455
1 parent ed870cc commit 7cd7f4a

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed
 

‎llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ STATISTIC(NumSubNUW, "Number of no-unsigned-wrap deductions for sub");
7676
STATISTIC(NumMulNW, "Number of no-wrap deductions for mul");
7777
STATISTIC(NumMulNSW, "Number of no-signed-wrap deductions for mul");
7878
STATISTIC(NumMulNUW, "Number of no-unsigned-wrap deductions for mul");
79+
STATISTIC(NumShlNW, "Number of no-wrap deductions for shl");
80+
STATISTIC(NumShlNSW, "Number of no-signed-wrap deductions for shl");
81+
STATISTIC(NumShlNUW, "Number of no-unsigned-wrap deductions for shl");
7982
STATISTIC(NumOverflows, "Number of overflow checks removed");
8083
STATISTIC(NumSaturating,
8184
"Number of saturating arithmetics converted to normal arithmetics");
@@ -450,6 +453,11 @@ static void setDeducedOverflowingFlags(Value *V, Instruction::BinaryOps Opcode,
450453
OpcNSW = &NumMulNSW;
451454
OpcNUW = &NumMulNUW;
452455
break;
456+
case Instruction::Shl:
457+
OpcNW = &NumShlNW;
458+
OpcNSW = &NumShlNSW;
459+
OpcNUW = &NumShlNUW;
460+
break;
453461
default:
454462
llvm_unreachable("Will not be called with other binops");
455463
}
@@ -861,6 +869,7 @@ static bool runImpl(Function &F, LazyValueInfo *LVI, DominatorTree *DT,
861869
case Instruction::Add:
862870
case Instruction::Sub:
863871
case Instruction::Mul:
872+
case Instruction::Shl:
864873
BBChanged |= processBinOp(cast<BinaryOperator>(II), LVI);
865874
break;
866875
case Instruction::And:

‎llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ define i1 @test5(i32 %x, i32 %y) #0 {
173173
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[Y:%.*]], 5
174174
; CHECK-NEXT: br i1 [[CMP2]], label [[CONT2:%.*]], label [[OUT]]
175175
; CHECK: cont2:
176-
; CHECK-NEXT: [[SHIFTED:%.*]] = shl i32 [[X]], [[Y]]
176+
; CHECK-NEXT: [[SHIFTED:%.*]] = shl nuw nsw i32 [[X]], [[Y]]
177177
; CHECK-NEXT: br label [[CONT3:%.*]]
178178
; CHECK: cont3:
179179
; CHECK-NEXT: br label [[OUT]]
@@ -212,7 +212,7 @@ define i1 @test6(i32 %x, i32 %y) #0 {
212212
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[Y:%.*]], 15
213213
; CHECK-NEXT: br i1 [[CMP2]], label [[CONT2:%.*]], label [[OUT]]
214214
; CHECK: cont2:
215-
; CHECK-NEXT: [[SHIFTED:%.*]] = shl i32 [[X]], [[Y]]
215+
; CHECK-NEXT: [[SHIFTED:%.*]] = shl nuw nsw i32 [[X]], [[Y]]
216216
; CHECK-NEXT: br label [[CONT3:%.*]]
217217
; CHECK: cont3:
218218
; CHECK-NEXT: [[CMP3:%.*]] = icmp ult i32 [[SHIFTED]], 65536

‎llvm/test/Transforms/CorrelatedValuePropagation/shl.ll

+11-11
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ define i8 @test4(i8 %a, i8 %b) {
8585
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[B:%.*]], 7
8686
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
8787
; CHECK: bb:
88-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 [[A:%.*]], [[B]]
88+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 [[A:%.*]], [[B]]
8989
; CHECK-NEXT: ret i8 [[SHL]]
9090
; CHECK: exit:
9191
; CHECK-NEXT: ret i8 0
@@ -104,7 +104,7 @@ exit:
104104

105105
define i8 @test5(i8 %b) {
106106
; CHECK-LABEL: @test5(
107-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 0, [[B:%.*]]
107+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 0, [[B:%.*]]
108108
; CHECK-NEXT: ret i8 [[SHL]]
109109
;
110110
%shl = shl i8 0, %b
@@ -113,7 +113,7 @@ define i8 @test5(i8 %b) {
113113

114114
define i8 @test6(i8 %b) {
115115
; CHECK-LABEL: @test6(
116-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 1, [[B:%.*]]
116+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i8 1, [[B:%.*]]
117117
; CHECK-NEXT: ret i8 [[SHL]]
118118
;
119119
%shl = shl i8 1, %b
@@ -126,7 +126,7 @@ define i8 @test7(i8 %b) {
126126
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[B:%.*]], 7
127127
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
128128
; CHECK: bb:
129-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 1, [[B]]
129+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 1, [[B]]
130130
; CHECK-NEXT: ret i8 [[SHL]]
131131
; CHECK: exit:
132132
; CHECK-NEXT: ret i8 0
@@ -145,7 +145,7 @@ exit:
145145

146146
define i8 @test8(i8 %b) {
147147
; CHECK-LABEL: @test8(
148-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 -1, [[B:%.*]]
148+
; CHECK-NEXT: [[SHL:%.*]] = shl nsw i8 -1, [[B:%.*]]
149149
; CHECK-NEXT: ret i8 [[SHL]]
150150
;
151151
%shl = shl i8 -1, %b
@@ -158,7 +158,7 @@ define i8 @test9(i8 %b) {
158158
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[B:%.*]], 0
159159
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
160160
; CHECK: bb:
161-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 -1, [[B]]
161+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 -1, [[B]]
162162
; CHECK-NEXT: ret i8 -1
163163
; CHECK: exit:
164164
; CHECK-NEXT: ret i8 0
@@ -190,7 +190,7 @@ define i8 @test11(i8 %b) {
190190
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[B:%.*]], 2
191191
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
192192
; CHECK: bb:
193-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 42, [[B]]
193+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 42, [[B]]
194194
; CHECK-NEXT: ret i8 [[SHL]]
195195
; CHECK: exit:
196196
; CHECK-NEXT: ret i8 0
@@ -213,7 +213,7 @@ define i8 @test12(i8 %b) {
213213
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[B:%.*]], 3
214214
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
215215
; CHECK: bb:
216-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 42, [[B]]
216+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i8 42, [[B]]
217217
; CHECK-NEXT: ret i8 [[SHL]]
218218
; CHECK: exit:
219219
; CHECK-NEXT: ret i8 0
@@ -268,7 +268,7 @@ define i8 @test15(i8 %b) {
268268
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[B:%.*]], 2
269269
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
270270
; CHECK: bb:
271-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 -42, [[B]]
271+
; CHECK-NEXT: [[SHL:%.*]] = shl nsw i8 -42, [[B]]
272272
; CHECK-NEXT: ret i8 [[SHL]]
273273
; CHECK: exit:
274274
; CHECK-NEXT: ret i8 0
@@ -314,7 +314,7 @@ define i8 @test17(i8 %b) {
314314
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[B:%.*]], 2
315315
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
316316
; CHECK: bb:
317-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 42, [[B]]
317+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 42, [[B]]
318318
; CHECK-NEXT: ret i8 [[SHL]]
319319
; CHECK: exit:
320320
; CHECK-NEXT: ret i8 0
@@ -337,7 +337,7 @@ define i8 @test18(i8 %b) {
337337
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[B:%.*]], 3
338338
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
339339
; CHECK: bb:
340-
; CHECK-NEXT: [[SHL:%.*]] = shl i8 42, [[B]]
340+
; CHECK-NEXT: [[SHL:%.*]] = shl nuw i8 42, [[B]]
341341
; CHECK-NEXT: ret i8 [[SHL]]
342342
; CHECK: exit:
343343
; CHECK-NEXT: ret i8 0

0 commit comments

Comments
 (0)
Please sign in to comment.