Skip to content

Commit 4af4828

Browse files
committed
[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.
1 parent 0f70a17 commit 4af4828

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,9 @@ static bool isNonZeroRecurrence(const PHINode *PN) {
22372237
case Instruction::Shl:
22382238
return !StartC->isNullValue() &&
22392239
(BO->hasNoUnsignedWrap() || BO->hasNoSignedWrap());
2240+
case Instruction::AShr:
2241+
case Instruction::LShr:
2242+
return !StartC->isNullValue() && BO->isExact();
22402243
default:
22412244
return false;
22422245
}

llvm/test/Analysis/ValueTracking/monotonic-phi.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,7 @@ define i1 @test_lshr_exact(i8 %p, i8* %pq, i8 %n) {
486486
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[A]], [[N:%.*]]
487487
; CHECK-NEXT: br i1 [[CMP1]], label [[EXIT:%.*]], label [[LOOP]]
488488
; CHECK: exit:
489-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A]], 0
490-
; CHECK-NEXT: ret i1 [[CMP]]
489+
; CHECK-NEXT: ret i1 false
491490
;
492491
entry:
493492
br label %loop
@@ -561,8 +560,7 @@ define i1 @test_ashr_exact(i8 %p, i8* %pq, i8 %n) {
561560
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8 [[A]], [[N:%.*]]
562561
; CHECK-NEXT: br i1 [[CMP1]], label [[EXIT:%.*]], label [[LOOP]]
563562
; CHECK: exit:
564-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[A]], 0
565-
; CHECK-NEXT: ret i1 [[CMP]]
563+
; CHECK-NEXT: ret i1 false
566564
;
567565
entry:
568566
br label %loop

0 commit comments

Comments
 (0)