diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 1c0dbba4d11108..3a9e80c0e5b986 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2681,6 +2681,16 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth, computeKnownBits(I->getOperand(0), DemandedElts, Known, Depth, Q); if (Known.One[0]) return true; + + if (!Known.isUnknown()) { + KnownBits KnownCnt = + computeKnownBits(I->getOperand(1), DemandedElts, Depth, Q); + + if (KnownCnt.getMaxValue().ult(Known.getBitWidth()) && + !Known.One.shl(KnownCnt.getMaxValue()).isZero()) + return true; + } + break; } case Instruction::LShr: diff --git a/llvm/test/Analysis/ValueTracking/known-non-zero.ll b/llvm/test/Analysis/ValueTracking/known-non-zero.ll index 7c4e7eae8eb98a..68ec1ef107aa90 100644 --- a/llvm/test/Analysis/ValueTracking/known-non-zero.ll +++ b/llvm/test/Analysis/ValueTracking/known-non-zero.ll @@ -170,11 +170,7 @@ define <2 x i1> @check_add_sat_vec(<2 x i8> %x, <2 x i8> %y, <2 x i8> %w) { define <2 x i1> @shl_nz_bounded_cnt_vec(<2 x i32> %x, <2 x i32> %y) { ; CHECK-LABEL: @shl_nz_bounded_cnt_vec( -; CHECK-NEXT: [[CNT:%.*]] = and <2 x i32> [[X:%.*]], -; CHECK-NEXT: [[VAL:%.*]] = or <2 x i32> [[Y:%.*]], -; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> [[VAL]], [[CNT]] -; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i32> [[SHL]], zeroinitializer -; CHECK-NEXT: ret <2 x i1> [[R]] +; CHECK-NEXT: ret <2 x i1> zeroinitializer ; %cnt = and <2 x i32> %x, %val = or <2 x i32> %y, @@ -187,10 +183,7 @@ define i1 @shl_nz_bounded_cnt(i32 %cnt, i32 %y) { ; CHECK-LABEL: @shl_nz_bounded_cnt( ; CHECK-NEXT: [[CNT_ULT4:%.*]] = icmp ult i32 [[CNT:%.*]], 4 ; CHECK-NEXT: call void @llvm.assume(i1 [[CNT_ULT4]]) -; CHECK-NEXT: [[VAL:%.*]] = or i32 [[Y:%.*]], 131072 -; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[VAL]], [[CNT]] -; CHECK-NEXT: [[R:%.*]] = icmp eq i32 [[SHL]], 0 -; CHECK-NEXT: ret i1 [[R]] +; CHECK-NEXT: ret i1 false ; %cnt_ult4 = icmp ult i32 %cnt, 4 call void @llvm.assume(i1 %cnt_ult4)