From: Craig Topper Date: Tue, 27 Feb 2018 19:53:45 +0000 (+0000) Subject: [ValueTracking] Teach cannotBeOrderedLessThanZeroImpl to look through ExtractElement. X-Git-Tag: llvmorg-7.0.0-rc1~11852 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=301991080e24ac402793ca6684daa2fc70647f8a;p=platform%2Fupstream%2Fllvm.git [ValueTracking] Teach cannotBeOrderedLessThanZeroImpl to look through ExtractElement. This is similar to what's done in computeKnownBits and computeSignBits. Don't do anything fancy just collect information valid for any element. Differential Revision: https://reviews.llvm.org/D43789 llvm-svn: 326237 --- diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index a1ec9df..31cb63d 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2783,6 +2783,12 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V, // Widening/narrowing never change sign. return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly, Depth + 1); + case Instruction::ExtractElement: + // Look through extract element. At the moment we keep this simple and skip + // tracking the specific element. But at least we might find information + // valid for all elements of the vector. + return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly, + Depth + 1); case Instruction::Call: const auto *CI = cast(I); Intrinsic::ID IID = getIntrinsicForCallSite(CI, TLI); diff --git a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll index d564992..7e19c9b 100644 --- a/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll +++ b/llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll @@ -435,3 +435,17 @@ define float @fabs_sqrt_nnan_fabs(float %a) { %fabs = call float @llvm.fabs.f32(float %sqrt) ret float %fabs } + +define float @fabs_select_positive_constants_vector_extract(i32 %c) { +; CHECK-LABEL: @fabs_select_positive_constants_vector_extract( +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 +; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], <2 x float> , <2 x float> +; CHECK-NEXT: [[EXTRACT:%.*]] = extractelement <2 x float> [[SELECT]], i32 0 +; CHECK-NEXT: ret float [[EXTRACT]] +; + %cmp = icmp eq i32 %c, 0 + %select = select i1 %cmp, <2 x float> , <2 x float> + %extract = extractelement <2 x float> %select, i32 0 + %fabs = call float @llvm.fabs.f32(float %extract) + ret float %fabs +}