Loading llvm/lib/Analysis/ValueTracking.cpp +16 −3 Original line number Diff line number Diff line Loading @@ -567,11 +567,24 @@ static bool cmpExcludesZero(CmpInst::Predicate Pred, const Value *RHS) { // All other predicates - rely on generic ConstantRange handling. const APInt *C; if (!match(RHS, m_APInt(C))) auto Zero = APInt::getZero(RHS->getType()->getScalarSizeInBits()); if (match(RHS, m_APInt(C))) { ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(Pred, *C); return !TrueValues.contains(Zero); } auto *VC = dyn_cast<ConstantDataVector>(RHS); if (VC == nullptr) return false; ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(Pred, *C); return !TrueValues.contains(APInt::getZero(C->getBitWidth())); for (unsigned ElemIdx = 0, NElem = VC->getNumElements(); ElemIdx < NElem; ++ElemIdx) { ConstantRange TrueValues = ConstantRange::makeExactICmpRegion( Pred, VC->getElementAsAPInt(ElemIdx)); if (TrueValues.contains(Zero)) return false; } return true; } static bool isKnownNonZeroFromAssume(const Value *V, const SimplifyQuery &Q) { Loading llvm/test/Analysis/ValueTracking/known-non-zero.ll +1 −5 Original line number Diff line number Diff line Loading @@ -1163,11 +1163,7 @@ define i1 @sdiv_known_non_zero_fail(i8 %x, i8 %y) { define <2 x i1> @cmp_excludes_zero_with_nonsplat_vec(<2 x i8> %a, <2 x i8> %b) { ; CHECK-LABEL: @cmp_excludes_zero_with_nonsplat_vec( ; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i8> [[A:%.*]], <i8 1, i8 4> ; CHECK-NEXT: [[S:%.*]] = select <2 x i1> [[C]], <2 x i8> [[A]], <2 x i8> <i8 4, i8 5> ; CHECK-NEXT: [[AND:%.*]] = or <2 x i8> [[S]], [[B:%.*]] ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[AND]], zeroinitializer ; CHECK-NEXT: ret <2 x i1> [[R]] ; CHECK-NEXT: ret <2 x i1> zeroinitializer ; %c = icmp sge <2 x i8> %a, <i8 1, i8 4> %s = select <2 x i1> %c, <2 x i8> %a, <2 x i8> <i8 4, i8 5> Loading Loading
llvm/lib/Analysis/ValueTracking.cpp +16 −3 Original line number Diff line number Diff line Loading @@ -567,11 +567,24 @@ static bool cmpExcludesZero(CmpInst::Predicate Pred, const Value *RHS) { // All other predicates - rely on generic ConstantRange handling. const APInt *C; if (!match(RHS, m_APInt(C))) auto Zero = APInt::getZero(RHS->getType()->getScalarSizeInBits()); if (match(RHS, m_APInt(C))) { ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(Pred, *C); return !TrueValues.contains(Zero); } auto *VC = dyn_cast<ConstantDataVector>(RHS); if (VC == nullptr) return false; ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(Pred, *C); return !TrueValues.contains(APInt::getZero(C->getBitWidth())); for (unsigned ElemIdx = 0, NElem = VC->getNumElements(); ElemIdx < NElem; ++ElemIdx) { ConstantRange TrueValues = ConstantRange::makeExactICmpRegion( Pred, VC->getElementAsAPInt(ElemIdx)); if (TrueValues.contains(Zero)) return false; } return true; } static bool isKnownNonZeroFromAssume(const Value *V, const SimplifyQuery &Q) { Loading
llvm/test/Analysis/ValueTracking/known-non-zero.ll +1 −5 Original line number Diff line number Diff line Loading @@ -1163,11 +1163,7 @@ define i1 @sdiv_known_non_zero_fail(i8 %x, i8 %y) { define <2 x i1> @cmp_excludes_zero_with_nonsplat_vec(<2 x i8> %a, <2 x i8> %b) { ; CHECK-LABEL: @cmp_excludes_zero_with_nonsplat_vec( ; CHECK-NEXT: [[C:%.*]] = icmp sge <2 x i8> [[A:%.*]], <i8 1, i8 4> ; CHECK-NEXT: [[S:%.*]] = select <2 x i1> [[C]], <2 x i8> [[A]], <2 x i8> <i8 4, i8 5> ; CHECK-NEXT: [[AND:%.*]] = or <2 x i8> [[S]], [[B:%.*]] ; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i8> [[AND]], zeroinitializer ; CHECK-NEXT: ret <2 x i1> [[R]] ; CHECK-NEXT: ret <2 x i1> zeroinitializer ; %c = icmp sge <2 x i8> %a, <i8 1, i8 4> %s = select <2 x i1> %c, <2 x i8> %a, <2 x i8> <i8 4, i8 5> Loading