[llvm] 6872a64 - [ValueTracking] Handle vector range metadata in isKnownNonZero()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 07:50:24 PDT 2024
Author: Nikita Popov
Date: 2024-03-19T15:50:13+01:00
New Revision: 6872a646523c1e85a98dfa20b2f4dd7774e10ba4
URL: https://github.com/llvm/llvm-project/commit/6872a646523c1e85a98dfa20b2f4dd7774e10ba4
DIFF: https://github.com/llvm/llvm-project/commit/6872a646523c1e85a98dfa20b2f4dd7774e10ba4.diff
LOG: [ValueTracking] Handle vector range metadata in isKnownNonZero()
Nowadays !range can be placed on instructions with vector of int
return value. Support this case in isKnownNonZero().
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Analysis/ValueTracking/known-non-zero.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 2e0a930cf0a32e..bf6afad3636b4a 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2918,11 +2918,10 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
if (MDNode *Ranges = Q.IIQ.getMetadata(I, LLVMContext::MD_range)) {
// If the possible ranges don't contain zero, then the value is
// definitely non-zero.
- if (auto *Ty = dyn_cast<IntegerType>(V->getType())) {
- const APInt ZeroValue(Ty->getBitWidth(), 0);
- if (rangeMetadataExcludesValue(Ranges, ZeroValue))
- return true;
- }
+ assert(V->getType()->isIntOrIntVectorTy() && "Range on non-integer?");
+ const APInt ZeroValue(Ty->getScalarSizeInBits(), 0);
+ if (rangeMetadataExcludesValue(Ranges, ZeroValue))
+ return true;
}
}
diff --git a/llvm/test/Analysis/ValueTracking/known-non-zero.ll b/llvm/test/Analysis/ValueTracking/known-non-zero.ll
index f514968715c23c..30d340dc725a3e 100644
--- a/llvm/test/Analysis/ValueTracking/known-non-zero.ll
+++ b/llvm/test/Analysis/ValueTracking/known-non-zero.ll
@@ -1295,10 +1295,7 @@ false:
define <2 x i1> @range_metadata_vec(ptr %p, <2 x i32> %x) {
; CHECK-LABEL: @range_metadata_vec(
-; CHECK-NEXT: [[Z:%.*]] = load <2 x i32>, ptr [[P:%.*]], align 8, !range [[RNG0:![0-9]+]]
-; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[Z]], [[X:%.*]]
-; CHECK-NEXT: [[CMP0:%.*]] = icmp ne <2 x i32> [[OR]], zeroinitializer
-; CHECK-NEXT: ret <2 x i1> [[CMP0]]
+; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%v = load <2 x i32>, ptr %p, !range !{i32 1, i32 100}
%or = or <2 x i32> %v, %x
More information about the llvm-commits
mailing list