[llvm] 4af4828 - [ValueTracking] Handle non-zero ashr/lshr recurrences
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 31 16:50:19 PDT 2021
Author: Philip Reames
Date: 2021-03-31T16:48:32-07:00
New Revision: 4af4828a6ef5778609c6738f674a35bc28eaf829
URL: https://github.com/llvm/llvm-project/commit/4af4828a6ef5778609c6738f674a35bc28eaf829
DIFF: https://github.com/llvm/llvm-project/commit/4af4828a6ef5778609c6738f674a35bc28eaf829.diff
LOG: [ValueTracking] Handle non-zero ashr/lshr recurrences
If we know we don't shift out bits (e.g. exact), all we need to know is that input is non-zero.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/monotonic-phi.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index e5c3f3f96e3e0..cffbe927adb39 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2237,6 +2237,9 @@ static bool isNonZeroRecurrence(const PHINode *PN) {
case Instruction::Shl:
return !StartC->isNullValue() &&
(BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap());
+ case Instruction::AShr:
+ case Instruction::LShr:
+ return !StartC->isNullValue() && BO->isExact();
default:
return false;
}
diff --git a/llvm/test/Analysis/ValueTracking/monotonic-phi.ll b/llvm/test/Analysis/ValueTracking/monotonic-phi.ll
index 3c2aea528cbdd..af8ad2931e10f 100644
--- a/llvm/test/Analysis/ValueTracking/monotonic-phi.ll
+++ b/llvm/test/Analysis/ValueTracking/monotonic-phi.ll
@@ -486,8 +486,7 @@ define i1 @test_lshr_exact(i8 %p, i8* %pq, i8 %n) {
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[A]], [[N:%.*]]
; CHECK-NEXT: br i1 [[CMP1]], label [[EXIT:%.*]], label [[LOOP]]
; CHECK: exit:
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A]], 0
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 false
;
entry:
br label %loop
@@ -561,8 +560,7 @@ define i1 @test_ashr_exact(i8 %p, i8* %pq, i8 %n) {
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[A]], [[N:%.*]]
; CHECK-NEXT: br i1 [[CMP1]], label [[EXIT:%.*]], label [[LOOP]]
; CHECK: exit:
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A]], 0
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 false
;
entry:
br label %loop
More information about the llvm-commits
mailing list