[llvm-commits] [llvm] r172576 - in /llvm/trunk: lib/Transforms/InstCombine/InstCombineVectorOps.cpp test/Transforms/InstCombine/vec_extract_elt.ll

Duncan Sands baldrick at free.fr
Thu Jan 17 04:11:39 PST 2013


Hi Nadav,

On 16/01/13 00:43, Nadav Rotem wrote:
> Author: nadav
> Date: Tue Jan 15 17:43:14 2013
> New Revision: 172576
>
> URL: http://llvm.org/viewvc/llvm-project?rev=172576&view=rev
> Log:
> Teach InstCombine to optimize extract of a value from a vector add operation with a constant zero.

could this go in instsimplify instead?  It could also be generalized a lot,
for example for mul by 1.  I can imagine the following: try to simplify

   extract element EltNo from (binop x, y)

by applying the following algorithm:

(1) See if EltNo element of x is already available (aka FindScalarElement).
Call it xElt.
(2) See if EltNo element of y is already available.  Call it yElt.
(3) If so, ask instsimplify if binop xElt, yElt simplifies.  If so, return
it.

I think this gets the transform you added as a special case.

Similarly for all kinds of other operations (unary ops, select).

Ciao, Duncan.

>
>
> Modified:
>      llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
>      llvm/trunk/test/Transforms/InstCombine/vec_extract_elt.ll
>
> Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=172576&r1=172575&r2=172576&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Tue Jan 15 17:43:14 2013
> @@ -13,7 +13,9 @@
>   //===----------------------------------------------------------------------===//
>
>   #include "InstCombine.h"
> +#include "llvm/Support/PatternMatch.h"
>   using namespace llvm;
> +using namespace PatternMatch;
>
>   /// CheapToScalarize - Return true if the value is cheaper to scalarize than it
>   /// is to leave as a vector operation.  isConstant indicates whether we're
> @@ -92,6 +94,13 @@
>       return FindScalarElement(SVI->getOperand(1), InEl - LHSWidth);
>     }
>
> +  // Extract a value from a vector add operation with a constant zero.
> +  Value *Val = 0; Constant *Con = 0;
> +  if (match(V, m_Add(m_Value(Val), m_Constant(Con)))) {
> +    if (Con->getAggregateElement(EltNo)->isNullValue())
> +      return FindScalarElement(Val, EltNo);
> +  }
> +
>     // Otherwise, we don't know.
>     return 0;
>   }
>
> Modified: llvm/trunk/test/Transforms/InstCombine/vec_extract_elt.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/vec_extract_elt.ll?rev=172576&r1=172575&r2=172576&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/vec_extract_elt.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/vec_extract_elt.ll Tue Jan 15 17:43:14 2013
> @@ -7,3 +7,13 @@
>           ret i32 %tmp19
>   }
>
> +define i64 @test2(i64 %in) {
> +  %vec = insertelement <8 x i64> undef, i64 %in, i32 0
> +  %splat = shufflevector <8 x i64> %vec, <8 x i64> undef, <8 x i32> zeroinitializer
> +  %add = add <8 x i64> %splat, <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7>
> +  %scl1 = extractelement <8 x i64> %add, i32 0
> +  %scl2 = extractelement <8 x i64> %add, i32 0
> +  %r = add i64 %scl1, %scl2
> +  ret i64 %r
> +}
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>




More information about the llvm-commits mailing list