From 69c8972fd1dd4beb75421dd32110d2f0e1cb3a5f Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 26 Feb 2018 22:33:17 +0000 Subject: [PATCH] [ValueTracking] Teach cannotBeOrderedLessThanZeroImpl to handle vector constants. Summary: This allows vector fabs to be removed in more cases. Reviewers: spatel, arsenm, RKSimon Reviewed By: spatel Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D43739 llvm-svn: 326138 --- llvm/lib/Analysis/ValueTracking.cpp | 18 ++++++++++++++++++ .../InstSimplify/floating-point-arithmetic.ll | 6 ++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index e425599..a1ec9df 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2728,6 +2728,24 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V, (!SignBitOnly && CFP->getValueAPF().isZero()); } + // Handle vector of constants. + if (auto *CV = dyn_cast(V)) { + if (CV->getType()->isVectorTy()) { + unsigned NumElts = CV->getType()->getVectorNumElements(); + for (unsigned i = 0; i != NumElts; ++i) { + auto *CFP = dyn_cast_or_null(CV->getAggregateElement(i)); + if (!CFP) + return false; + if (CFP->getValueAPF().isNegative() && + (SignBitOnly || !CFP->getValueAPF().isZero())) + return false; + } + + // All non-negative ConstantFPs. + return true; + } + } + if (Depth == MaxDepth) return false; // Limit search depth. diff --git a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll index 5ec820f..ba177ea 100644 --- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll +++ b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll @@ -132,8 +132,7 @@ define <2 x float> @fabs_select_positive_constants_vector(i32 %c) { ; CHECK-LABEL: @fabs_select_positive_constants_vector( ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> , <2 x float> -; CHECK-NEXT: [[FABS:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[SELECT]]) -; CHECK-NEXT: ret <2 x float> [[FABS]] +; CHECK-NEXT: ret <2 x float> [[SELECT]] ; %cmp = icmp eq i32 %c, 0 %select = select i1 %cmp, <2 x float> , <2 x float> @@ -235,8 +234,7 @@ define <2 x float> @fabs_select_nan_nan_vector(i32 %c) { ; CHECK-LABEL: @fabs_select_nan_nan_vector( ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> , <2 x float> -; CHECK-NEXT: [[FABS:%.*]] = call <2 x float> @llvm.fabs.v2f32(<2 x float> [[SELECT]]) -; CHECK-NEXT: ret <2 x float> [[FABS]] +; CHECK-NEXT: ret <2 x float> [[SELECT]] ; %cmp = icmp eq i32 %c, 0 %select = select i1 %cmp, <2 x float> , <2 x float> -- 2.7.4