diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2698,6 +2698,9 @@ if (isKnownNonZero(Op, Depth, Q) && isGuaranteedNotToBePoison(Op, Q.AC, Q.CxtI, Q.DT, Depth)) return true; + } else if (const auto *II = dyn_cast(V)) { + if (II->getIntrinsicID() == Intrinsic::vscale) + return true; } KnownBits Known(BitWidth); diff --git a/llvm/test/Transforms/InstCombine/vscale_zero.ll b/llvm/test/Transforms/InstCombine/vscale_zero.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/vscale_zero.ll @@ -0,0 +1,26 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -passes=instcombine -S | FileCheck %s + +define i1 @iszero() { +; CHECK-LABEL: @iszero( +; CHECK-NEXT: entry: +; CHECK-NEXT: ret i1 false +; + entry: + %0 = call i32 @llvm.vscale.i32() + %1 = icmp eq i32 %0, 0 + ret i1 %1 +} + +define i1 @iszero_range() vscale_range(1,16) { +; CHECK-LABEL: @iszero_range( +; CHECK-NEXT: entry: +; CHECK-NEXT: ret i1 false +; + entry: + %0 = call i32 @llvm.vscale.i32() + %1 = icmp eq i32 %0, 0 + ret i1 %1 +} + +declare i32 @llvm.vscale.i32()