[llvm] r326237 - [ValueTracking] Teach cannotBeOrderedLessThanZeroImpl to look through ExtractElement.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 27 11:53:45 PST 2018


Author: ctopper
Date: Tue Feb 27 11:53:45 2018
New Revision: 326237

URL: http://llvm.org/viewvc/llvm-project?rev=326237&view=rev
Log:
[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

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=326237&r1=326236&r2=326237&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Tue Feb 27 11:53:45 2018
@@ -2783,6 +2783,12 @@ static bool cannotBeOrderedLessThanZeroI
     // 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<CallInst>(I);
     Intrinsic::ID IID = getIntrinsicForCallSite(CI, TLI);

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=326237&r1=326236&r2=326237&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/floating-point-arithmetic.ll Tue Feb 27 11:53:45 2018
@@ -435,3 +435,17 @@ define float @fabs_sqrt_nnan_fabs(float
   %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> <float 1.000000e+00, float 1.000000e+00>, <2 x float> <float 2.000000e+00, float 2.000000e+00>
+; 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> <float 1.0, float 1.0>, <2 x float> <float 2.0, float 2.0>
+  %extract = extractelement <2 x float> %select, i32 0
+  %fabs = call float @llvm.fabs.f32(float %extract)
+  ret float %fabs
+}




More information about the llvm-commits mailing list