[llvm] [ValueTracking] Add experimental_get_vector_length to isKnownNonZero. (PR #79950)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 29 22:59:39 PST 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/79950
If the input is non-zero, this intrinsic should also return a non-zero value.
>From 312e988e12863f66e199bc557366c39fac5f655c Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Mon, 29 Jan 2024 22:49:43 -0800
Subject: [PATCH] [ValueTracking] Add experimental_get_vector_length to
isKnownNonZero.
If the input is non-zero, this intrinsic should also return a
non-zero value.
---
llvm/lib/Analysis/ValueTracking.cpp | 2 ++
.../Analysis/ValueTracking/known-non-zero.ll | 24 +++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index f1f73f565c51f..362d02a39ef26 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2739,6 +2739,8 @@ static bool isKnownNonZeroFromOperator(const Operator *I,
break;
case Intrinsic::vscale:
return true;
+ case Intrinsic::experimental_get_vector_length:
+ return isKnownNonZero(I->getOperand(0), Depth, Q);
default:
break;
}
diff --git a/llvm/test/Analysis/ValueTracking/known-non-zero.ll b/llvm/test/Analysis/ValueTracking/known-non-zero.ll
index 2ce9df886d863..d804fe9664903 100644
--- a/llvm/test/Analysis/ValueTracking/known-non-zero.ll
+++ b/llvm/test/Analysis/ValueTracking/known-non-zero.ll
@@ -1269,3 +1269,27 @@ while.end.i:
%bool = icmp eq i32 %orval, 0
ret i1 %bool
}
+
+define i1 @check_get_vector_length(i32 %x, i32 %y) {
+; CHECK-LABEL: @check_get_vector_length(
+; CHECK-NEXT: [[NE:%.*]] = icmp ne i32 [[X:%.*]], 0
+; CHECK-NEXT: br i1 [[NE]], label [[TRUE:%.*]], label [[FALSE:%.*]]
+; CHECK: true:
+; CHECK-NEXT: [[Z:%.*]] = call i32 @llvm.experimental.get.vector.length.i32(i32 [[X]], i32 1, i1 true)
+; CHECK-NEXT: [[CMP0:%.*]] = icmp ugt i32 [[Z]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[CMP0]]
+; CHECK: false:
+; CHECK-NEXT: ret i1 [[NE]]
+;
+ %ne = icmp ne i32 %x, 0
+ br i1 %ne, label %true, label %false
+true:
+ %z = call i32 @llvm.experimental.get.vector.length.i32(i32 %x, i32 1, i1 true)
+ %cmp0 = icmp ugt i32 %z, %y
+ %cmp1 = icmp eq i32 %y, 0
+ %r = or i1 %cmp0, %cmp1
+ ret i1 %r
+false:
+ ret i1 %ne
+}
+declare i32 @llvm.experimental.get.vector.length.i32(i32, i32, i1)
More information about the llvm-commits
mailing list