[llvm] r346245 - [InstCombine] allow vector types for fcmp+fpext fold

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 6 09:20:20 PST 2018


Author: spatel
Date: Tue Nov  6 09:20:20 2018
New Revision: 346245

URL: http://llvm.org/viewvc/llvm-project?rev=346245&view=rev
Log:
[InstCombine] allow vector types for fcmp+fpext fold

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/trunk/test/Transforms/InstCombine/fcmp.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=346245&r1=346244&r2=346245&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Tue Nov  6 09:20:20 2018
@@ -5468,24 +5468,24 @@ Instruction *InstCombiner::visitFCmpInst
       return NewFCmp;
     }
 
-    // TODO: Use m_APFloat to handle vector splats.
-    ConstantFP *C;
-    if (match(Op1, m_ConstantFP(C))) {
+    const APFloat *C;
+    if (match(Op1, m_APFloat(C))) {
       // fcmp (fpext X), C -> fcmp X, (fptrunc C) if fptrunc is lossless
-      const fltSemantics &FPSem = X->getType()->getFltSemantics();
+      const fltSemantics &FPSem =
+          X->getType()->getScalarType()->getFltSemantics();
       bool Lossy;
-      APFloat F = C->getValueAPF();
-      F.convert(FPSem, APFloat::rmNearestTiesToEven, &Lossy);
+      APFloat TruncC = *C;
+      TruncC.convert(FPSem, APFloat::rmNearestTiesToEven, &Lossy);
 
       // Avoid lossy conversions and denormals.
       // Zero is a special case that's OK to convert.
-      APFloat Fabs = F;
+      APFloat Fabs = TruncC;
       Fabs.clearSign();
       if (!Lossy &&
           ((Fabs.compare(APFloat::getSmallestNormalized(FPSem)) !=
             APFloat::cmpLessThan) || Fabs.isZero())) {
-        Instruction *NewFCmp =
-            new FCmpInst(Pred, X, ConstantFP::get(C->getContext(), F));
+        Constant *NewC = ConstantFP::get(X->getType(), TruncC);
+        Instruction *NewFCmp = new FCmpInst(Pred, X, NewC);
         NewFCmp->copyFastMathFlags(&I);
         return NewFCmp;
       }

Modified: llvm/trunk/test/Transforms/InstCombine/fcmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fcmp.ll?rev=346245&r1=346244&r2=346245&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fcmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fcmp.ll Tue Nov  6 09:20:20 2018
@@ -28,8 +28,7 @@ define i1 @fpext_constant(float %a) {
 
 define <2 x i1> @fpext_constant_vec_splat(<2 x half> %a) {
 ; CHECK-LABEL: @fpext_constant_vec_splat(
-; CHECK-NEXT:    [[EXT:%.*]] = fpext <2 x half> [[A:%.*]] to <2 x double>
-; CHECK-NEXT:    [[CMP:%.*]] = fcmp nnan ole <2 x double> [[EXT]], <double 4.200000e+01, double 4.200000e+01>
+; CHECK-NEXT:    [[CMP:%.*]] = fcmp nnan ole <2 x half> [[A:%.*]], <half 0xH5140, half 0xH5140>
 ; CHECK-NEXT:    ret <2 x i1> [[CMP]]
 ;
   %ext = fpext <2 x half> %a to <2 x double>




More information about the llvm-commits mailing list