diff options
author | Nikita Popov <npopov@redhat.com> | 2024-07-05 16:56:46 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2024-07-05 17:02:03 +0200 |
commit | 130f0f526dc28ebbe23e5956857e85f7c9b754f5 (patch) | |
tree | dfd7b08c299086ed85f9ea4068fd04831eef07b0 | |
parent | f92bfca9fc217cad9026598ef6755e711c0be070 (diff) | |
download | llvm-130f0f526dc28ebbe23e5956857e85f7c9b754f5.zip llvm-130f0f526dc28ebbe23e5956857e85f7c9b754f5.tar.gz llvm-130f0f526dc28ebbe23e5956857e85f7c9b754f5.tar.bz2 |
[LVI][CVP] Add support for vector comparisons
-rw-r--r-- | llvm/lib/Analysis/LazyValueInfo.cpp | 6 | ||||
-rw-r--r-- | llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll | 32 |
2 files changed, 27 insertions, 11 deletions
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 27a2537..877898f 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -1784,12 +1784,8 @@ static Constant *getPredicateResult(CmpInst::Predicate Pred, Constant *C, Type *ResTy = CmpInst::makeCmpResultType(C->getType()); if (Val.isConstantRange()) { - ConstantInt *CI = dyn_cast<ConstantInt>(C); - if (!CI) - return nullptr; - const ConstantRange &CR = Val.getConstantRange(); - ConstantRange RHS(CI->getValue()); + ConstantRange RHS = C->toConstantRange(); if (CR.icmp(Pred, RHS)) return ConstantInt::getTrue(ResTy); if (CR.icmp(CmpInst::getInversePredicate(Pred), RHS)) diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll b/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll index 88e995a..6f13263 100644 --- a/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll +++ b/llvm/test/Transforms/CorrelatedValuePropagation/vectors.ll @@ -1,32 +1,52 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 ; RUN: opt -S -passes=correlated-propagation < %s | FileCheck %s -; TODO: Add support for this. define <2 x i1> @cmp1(<2 x i8> %a) { ; CHECK-LABEL: define <2 x i1> @cmp1( ; CHECK-SAME: <2 x i8> [[A:%.*]]) { ; CHECK-NEXT: [[ADD:%.*]] = add nuw <2 x i8> [[A]], <i8 1, i8 1> -; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[ADD]], zeroinitializer -; CHECK-NEXT: ret <2 x i1> [[CMP]] +; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> ; %add = add nuw <2 x i8> %a, splat (i8 1) %cmp = icmp ne <2 x i8> %add, zeroinitializer ret <2 x i1> %cmp } -; TODO: Add support for this. define <2 x i1> @cmp2(<2 x i8> %a) { ; CHECK-LABEL: define <2 x i1> @cmp2( ; CHECK-SAME: <2 x i8> [[A:%.*]]) { ; CHECK-NEXT: [[ADD:%.*]] = add nuw <2 x i8> [[A]], <i8 5, i8 5> -; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> [[ADD]], <i8 2, i8 2> -; CHECK-NEXT: ret <2 x i1> [[CMP]] +; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> ; %add = add nuw <2 x i8> %a, splat (i8 5) %cmp = icmp ugt <2 x i8> %add, splat (i8 2) ret <2 x i1> %cmp } +define <2 x i1> @cmp_nonsplat(<2 x i8> %a) { +; CHECK-LABEL: define <2 x i1> @cmp_nonsplat( +; CHECK-SAME: <2 x i8> [[A:%.*]]) { +; CHECK-NEXT: [[ADD:%.*]] = add nuw <2 x i8> [[A]], <i8 4, i8 5> +; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true> +; + %add = add nuw <2 x i8> %a, <i8 4, i8 5> + %cmp = icmp ugt <2 x i8> %add, <i8 2, i8 3> + ret <2 x i1> %cmp +} + +; Handling this would require keeping track of ranges on a per-element basis. +define <2 x i1> @cmp_nonsplat_fail(<2 x i8> %a) { +; CHECK-LABEL: define <2 x i1> @cmp_nonsplat_fail( +; CHECK-SAME: <2 x i8> [[A:%.*]]) { +; CHECK-NEXT: [[ADD:%.*]] = add nuw <2 x i8> [[A]], <i8 3, i8 4> +; CHECK-NEXT: [[CMP:%.*]] = icmp ugt <2 x i8> [[ADD]], <i8 2, i8 3> +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %add = add nuw <2 x i8> %a, <i8 3, i8 4> + %cmp = icmp ugt <2 x i8> %add, <i8 2, i8 3> + ret <2 x i1> %cmp +} + define <2 x i1> @cmp_signedness(<2 x i8> %a) { ; CHECK-LABEL: define <2 x i1> @cmp_signedness( ; CHECK-SAME: <2 x i8> [[A:%.*]]) { |