[llvm] 69ce2ae - [ConstantRange][LVI] Use overflow flags from `sub` to constrain the range
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 7 05:19:33 PST 2019
Author: Roman Lebedev
Date: 2019-11-07T16:18:03+03:00
New Revision: 69ce2ae990e7fffb4d0ed7a851ec072ad4e32c33
URL: https://github.com/llvm/llvm-project/commit/69ce2ae990e7fffb4d0ed7a851ec072ad4e32c33
DIFF: https://github.com/llvm/llvm-project/commit/69ce2ae990e7fffb4d0ed7a851ec072ad4e32c33.diff
LOG: [ConstantRange][LVI] Use overflow flags from `sub` to constrain the range
Summary:
This notably improves non-negativity deduction:
```
| statistic | old | new | delta | % change |
| correlated-value-propagation.NumAShrs | 209 | 227 | 18 | 8.6124% |
| correlated-value-propagation.NumAddNSW | 4972 | 4988 | 16 | 0.3218% |
| correlated-value-propagation.NumAddNUW | 7141 | 7148 | 7 | 0.0980% |
| correlated-value-propagation.NumAddNW | 12113 | 12136 | 23 | 0.1899% |
| correlated-value-propagation.NumAnd | 442 | 445 | 3 | 0.6787% |
| correlated-value-propagation.NumNSW | 7160 | 7176 | 16 | 0.2235% |
| correlated-value-propagation.NumNUW | 13306 | 13316 | 10 | 0.0752% |
| correlated-value-propagation.NumNW | 20466 | 20492 | 26 | 0.1270% |
| correlated-value-propagation.NumSDivs | 207 | 212 | 5 | 2.4155% |
| correlated-value-propagation.NumSExt | 6279 | 6679 | 400 | 6.3704% |
| correlated-value-propagation.NumSRems | 28 | 29 | 1 | 3.5714% |
| correlated-value-propagation.NumShlNUW | 2793 | 2796 | 3 | 0.1074% |
| correlated-value-propagation.NumShlNW | 3964 | 3967 | 3 | 0.0757% |
| correlated-value-propagation.NumUDivs | 353 | 358 | 5 | 1.4164% |
| instcount.NumAShrInst | 13763 | 13741 | -22 | -0.1598% |
| instcount.NumAddInst | 277349 | 277348 | -1 | -0.0004% |
| instcount.NumLShrInst | 27437 | 27463 | 26 | 0.0948% |
| instcount.NumOrInst | 102677 | 102678 | 1 | 0.0010% |
| instcount.NumSDivInst | 8732 | 8727 | -5 | -0.0573% |
| instcount.NumSExtInst | 80872 | 80468 | -404 | -0.4996% |
| instcount.NumSRemInst | 1679 | 1678 | -1 | -0.0596% |
| instcount.NumTruncInst | 62154 | 62153 | -1 | -0.0016% |
| instcount.NumUDivInst | 2526 | 2527 | 1 | 0.0396% |
| instcount.NumURemInst | 1589 | 1590 | 1 | 0.0629% |
| instcount.NumZExtInst | 69405 | 69809 | 404 | 0.5821% |
| instcount.TotalInsts | 7439575 | 7439574 | -1 | 0.0000% |
```
Reviewers: nikic, reames, spatel
Reviewed By: nikic
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69942
Added:
Modified:
llvm/lib/IR/ConstantRange.cpp
llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
Removed:
################################################################################
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index 4914c50c203c..18d8e9d42c6b 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -824,6 +824,8 @@ ConstantRange ConstantRange::overflowingBinaryOp(Instruction::BinaryOps BinOp,
switch (BinOp) {
case Instruction::Add:
return addWithNoWrap(Other, NoWrapKind);
+ case Instruction::Sub:
+ return subWithNoWrap(Other, NoWrapKind);
default:
// Don't know about this Overflowing Binary Operation.
// Conservatively fallback to plain binop handling.
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll b/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
index 6ec996ff9416..8f783f828475 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/icmp.ll
@@ -490,11 +490,9 @@ define i1 @test16(i32 %a, i32 %b) {
; CHECK-NEXT: [[SUB:%.*]] = sub nuw nsw i32 [[A]], [[B]]
; CHECK-NEXT: br label [[CONT:%.*]]
; CHECK: cont:
-; CHECK-NEXT: [[RES:%.*]] = icmp sge i32 [[SUB]], 0
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
-; CHECK-NEXT: [[IV:%.*]] = phi i1 [ true, [[BEGIN:%.*]] ], [ [[RES]], [[CONT]] ]
-; CHECK-NEXT: ret i1 [[IV]]
+; CHECK-NEXT: ret i1 true
;
begin:
%cmp0 = icmp sge i32 %a, 0
@@ -598,11 +596,9 @@ define i1 @test19(i32 %a, i32 %b) {
; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 [[A]], [[B]]
; CHECK-NEXT: br label [[CONT:%.*]]
; CHECK: cont:
-; CHECK-NEXT: [[RES:%.*]] = icmp sle i32 [[SUB]], 0
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
-; CHECK-NEXT: [[IV:%.*]] = phi i1 [ true, [[BEGIN:%.*]] ], [ [[RES]], [[CONT]] ]
-; CHECK-NEXT: ret i1 [[IV]]
+; CHECK-NEXT: ret i1 true
;
begin:
%cmp0 = icmp sle i32 %a, 0
More information about the llvm-commits
mailing list