[llvm] r326138 - [ValueTracking] Teach cannotBeOrderedLessThanZeroImpl to handle vector constants.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 14:33:17 PST 2018
Author: ctopper
Date: Mon Feb 26 14:33:17 2018
New Revision: 326138
URL: http://llvm.org/viewvc/llvm-project?rev=326138&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=326138&r1=326137&r2=326138&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Mon Feb 26 14:33:17 2018
@@ -2728,6 +2728,24 @@ static bool cannotBeOrderedLessThanZeroI
(!SignBitOnly && CFP->getValueAPF().isZero());
}
+ // Handle vector of constants.
+ if (auto *CV = dyn_cast<Constant>(V)) {
+ if (CV->getType()->isVectorTy()) {
+ unsigned NumElts = CV->getType()->getVectorNumElements();
+ for (unsigned i = 0; i != NumElts; ++i) {
+ auto *CFP = dyn_cast_or_null<ConstantFP>(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.
Modified: llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll?rev=326138&r1=326137&r2=326138&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll Mon Feb 26 14:33:17 2018
@@ -132,8 +132,7 @@ define <2 x float> @fabs_select_positive
; CHECK-LABEL: @fabs_select_positive_constants_vector(
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float 1.000000e+00, float 1.000000e+00>, <2 x float> <float 2.000000e+00, float 2.000000e+00>
-; 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> <float 1.0, float 1.0>, <2 x float> <float 2.0, float 2.0>
@@ -235,8 +234,7 @@ define <2 x float> @fabs_select_nan_nan_
; CHECK-LABEL: @fabs_select_nan_nan_vector(
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <2 x float> <float 0x7FF8000100000000, float 0x7FF8000100000000>
-; 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> <float 0x7FF8000000000000, float 0x7FF8000000000000>, <2 x float> <float 0x7FF8000100000000, float 0x7FF8000100000000>
More information about the llvm-commits
mailing list