[llvm] bd1a4c8 - [ValueTracking] Teach isKnownNonZero that a vscale is never 0.
David Green via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 23 07:25:29 PDT 2022
Author: David Green
Date: 2022-06-23T15:25:24+01:00
New Revision: bd1a4c8565ac7a48a5dc1e18b8ea07b29b93d213
URL: https://github.com/llvm/llvm-project/commit/bd1a4c8565ac7a48a5dc1e18b8ea07b29b93d213
DIFF: https://github.com/llvm/llvm-project/commit/bd1a4c8565ac7a48a5dc1e18b8ea07b29b93d213.diff
LOG: [ValueTracking] Teach isKnownNonZero that a vscale is never 0.
A llvm.vscale will always be at least 1, never zero. Teaching that to
isKnownNonZero can help fold away some statically known compares.
Differential Revision: https://reviews.llvm.org/D128217
Added:
llvm/test/Transforms/InstCombine/vscale_zero.ll
Modified:
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 17bebe1905357..801167fe281af 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2698,6 +2698,9 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
if (isKnownNonZero(Op, Depth, Q) &&
isGuaranteedNotToBePoison(Op, Q.AC, Q.CxtI, Q.DT, Depth))
return true;
+ } else if (const auto *II = dyn_cast<IntrinsicInst>(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
index 0000000000000..bab0a8bc7980a
--- /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()
More information about the llvm-commits
mailing list