Skip to content

Commit 6872a64

Browse files
committed
[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().
1 parent 0e76818 commit 6872a64

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,11 +2918,10 @@ bool isKnownNonZero(const Value *V, const APInt &DemandedElts, unsigned Depth,
29182918
if (MDNode *Ranges = Q.IIQ.getMetadata(I, LLVMContext::MD_range)) {
29192919
// If the possible ranges don't contain zero, then the value is
29202920
// definitely non-zero.
2921-
if (auto *Ty = dyn_cast<IntegerType>(V->getType())) {
2922-
const APInt ZeroValue(Ty->getBitWidth(), 0);
2923-
if (rangeMetadataExcludesValue(Ranges, ZeroValue))
2924-
return true;
2925-
}
2921+
assert(V->getType()->isIntOrIntVectorTy() && "Range on non-integer?");
2922+
const APInt ZeroValue(Ty->getScalarSizeInBits(), 0);
2923+
if (rangeMetadataExcludesValue(Ranges, ZeroValue))
2924+
return true;
29262925
}
29272926
}
29282927

llvm/test/Analysis/ValueTracking/known-non-zero.ll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,10 +1295,7 @@ false:
12951295

12961296
define <2 x i1> @range_metadata_vec(ptr %p, <2 x i32> %x) {
12971297
; CHECK-LABEL: @range_metadata_vec(
1298-
; CHECK-NEXT: [[Z:%.*]] = load <2 x i32>, ptr [[P:%.*]], align 8, !range [[RNG0:![0-9]+]]
1299-
; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[Z]], [[X:%.*]]
1300-
; CHECK-NEXT: [[CMP0:%.*]] = icmp ne <2 x i32> [[OR]], zeroinitializer
1301-
; CHECK-NEXT: ret <2 x i1> [[CMP0]]
1298+
; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
13021299
;
13031300
%v = load <2 x i32>, ptr %p, !range !{i32 1, i32 100}
13041301
%or = or <2 x i32> %v, %x

0 commit comments

Comments
 (0)