[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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@375455 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index 6be715c..2ef8526 100644
--- a/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -76,6 +76,9 @@
STATISTIC(NumMulNW, "Number of no-wrap deductions for mul");
STATISTIC(NumMulNSW, "Number of no-signed-wrap deductions for mul");
STATISTIC(NumMulNUW, "Number of no-unsigned-wrap deductions for mul");
+STATISTIC(NumShlNW, "Number of no-wrap deductions for shl");
+STATISTIC(NumShlNSW, "Number of no-signed-wrap deductions for shl");
+STATISTIC(NumShlNUW, "Number of no-unsigned-wrap deductions for shl");
STATISTIC(NumOverflows, "Number of overflow checks removed");
STATISTIC(NumSaturating,
"Number of saturating arithmetics converted to normal arithmetics");
@@ -450,6 +453,11 @@
OpcNSW = &NumMulNSW;
OpcNUW = &NumMulNUW;
break;
+ case Instruction::Shl:
+ OpcNW = &NumShlNW;
+ OpcNSW = &NumShlNSW;
+ OpcNUW = &NumShlNUW;
+ break;
default:
llvm_unreachable("Will not be called with other binops");
}
@@ -861,6 +869,7 @@
case Instruction::Add:
case Instruction::Sub:
case Instruction::Mul:
+ case Instruction::Shl:
BBChanged |= processBinOp(cast<BinaryOperator>(II), LVI);
break;
case Instruction::And:
diff --git a/test/Transforms/CorrelatedValuePropagation/icmp.ll b/test/Transforms/CorrelatedValuePropagation/icmp.ll
index 3b0f33a..7f28dad 100644
--- a/test/Transforms/CorrelatedValuePropagation/icmp.ll
+++ b/test/Transforms/CorrelatedValuePropagation/icmp.ll
@@ -173,7 +173,7 @@
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[Y:%.*]], 5
; CHECK-NEXT: br i1 [[CMP2]], label [[CONT2:%.*]], label [[OUT]]
; CHECK: cont2:
-; CHECK-NEXT: [[SHIFTED:%.*]] = shl i32 [[X]], [[Y]]
+; CHECK-NEXT: [[SHIFTED:%.*]] = shl nuw nsw i32 [[X]], [[Y]]
; CHECK-NEXT: br label [[CONT3:%.*]]
; CHECK: cont3:
; CHECK-NEXT: br label [[OUT]]
@@ -212,7 +212,7 @@
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[Y:%.*]], 15
; CHECK-NEXT: br i1 [[CMP2]], label [[CONT2:%.*]], label [[OUT]]
; CHECK: cont2:
-; CHECK-NEXT: [[SHIFTED:%.*]] = shl i32 [[X]], [[Y]]
+; CHECK-NEXT: [[SHIFTED:%.*]] = shl nuw nsw i32 [[X]], [[Y]]
; CHECK-NEXT: br label [[CONT3:%.*]]
; CHECK: cont3:
; CHECK-NEXT: [[CMP3:%.*]] = icmp ult i32 [[SHIFTED]], 65536
diff --git a/test/Transforms/CorrelatedValuePropagation/shl.ll b/test/Transforms/CorrelatedValuePropagation/shl.ll
index 81d26c9..0514ec9 100644
--- a/test/Transforms/CorrelatedValuePropagation/shl.ll
+++ b/test/Transforms/CorrelatedValuePropagation/shl.ll
@@ -85,7 +85,7 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[B:%.*]], 7
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
; CHECK: bb:
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 [[A:%.*]], [[B]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 [[A:%.*]], [[B]]
; CHECK-NEXT: ret i8 [[SHL]]
; CHECK: exit:
; CHECK-NEXT: ret i8 0
@@ -104,7 +104,7 @@
define i8 @test5(i8 %b) {
; CHECK-LABEL: @test5(
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 0, [[B:%.*]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 0, [[B:%.*]]
; CHECK-NEXT: ret i8 [[SHL]]
;
%shl = shl i8 0, %b
@@ -113,7 +113,7 @@
define i8 @test6(i8 %b) {
; CHECK-LABEL: @test6(
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 1, [[B:%.*]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw i8 1, [[B:%.*]]
; CHECK-NEXT: ret i8 [[SHL]]
;
%shl = shl i8 1, %b
@@ -126,7 +126,7 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[B:%.*]], 7
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
; CHECK: bb:
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 1, [[B]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 1, [[B]]
; CHECK-NEXT: ret i8 [[SHL]]
; CHECK: exit:
; CHECK-NEXT: ret i8 0
@@ -145,7 +145,7 @@
define i8 @test8(i8 %b) {
; CHECK-LABEL: @test8(
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 -1, [[B:%.*]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nsw i8 -1, [[B:%.*]]
; CHECK-NEXT: ret i8 [[SHL]]
;
%shl = shl i8 -1, %b
@@ -158,7 +158,7 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[B:%.*]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
; CHECK: bb:
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 -1, [[B]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 -1, [[B]]
; CHECK-NEXT: ret i8 -1
; CHECK: exit:
; CHECK-NEXT: ret i8 0
@@ -190,7 +190,7 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[B:%.*]], 2
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
; CHECK: bb:
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 42, [[B]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 42, [[B]]
; CHECK-NEXT: ret i8 [[SHL]]
; CHECK: exit:
; CHECK-NEXT: ret i8 0
@@ -213,7 +213,7 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[B:%.*]], 3
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
; CHECK: bb:
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 42, [[B]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw i8 42, [[B]]
; CHECK-NEXT: ret i8 [[SHL]]
; CHECK: exit:
; CHECK-NEXT: ret i8 0
@@ -268,7 +268,7 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i8 [[B:%.*]], 2
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
; CHECK: bb:
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 -42, [[B]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nsw i8 -42, [[B]]
; CHECK-NEXT: ret i8 [[SHL]]
; CHECK: exit:
; CHECK-NEXT: ret i8 0
@@ -314,7 +314,7 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[B:%.*]], 2
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
; CHECK: bb:
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 42, [[B]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i8 42, [[B]]
; CHECK-NEXT: ret i8 [[SHL]]
; CHECK: exit:
; CHECK-NEXT: ret i8 0
@@ -337,7 +337,7 @@
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[B:%.*]], 3
; CHECK-NEXT: br i1 [[CMP]], label [[BB:%.*]], label [[EXIT:%.*]]
; CHECK: bb:
-; CHECK-NEXT: [[SHL:%.*]] = shl i8 42, [[B]]
+; CHECK-NEXT: [[SHL:%.*]] = shl nuw i8 42, [[B]]
; CHECK-NEXT: ret i8 [[SHL]]
; CHECK: exit:
; CHECK-NEXT: ret i8 0