[llvm-commits] [llvm] r94990 - in /llvm/trunk/lib/CodeGen/SelectionDAG: DAGCombiner.cpp SelectionDAG.cpp

Duncan Sands baldrick at free.fr
Mon Feb 1 11:20:51 PST 2010


Hi Mon Ping,

> Fixed a couple of optimization with EXTRACT_VECTOR_ELT that assumes the result
> type is the same as the element type of the vector.  EXTRACT_VECTOR_ELT can
> be used to extended the width of an integer type.  This fixes a bug for
> Generic/vector-casts.ll on a ppc750.

according to the comments in SelectionDAGNodes.h, the operand is only allowed
to be wider (or the same as) the element type.  If the docs are wrong, please
correct them.  Are they wrong?  Is it a good idea to allow the operand to be
smaller than the element type, and if so what kind of implicit extension is
being done - anyextend?

> -   if (InOp.getValueType() != EltVT)
> -     return DAG.getNode(ISD::TRUNCATE, InVec.getDebugLoc(), EltVT, InOp);
> +   EVT NVT = N->getValueType(0);
> +   if (InOp.getValueType() != NVT) {
> +     assert(InOp.getValueType().isInteger() && NVT.isInteger());
> +     if (NVT.getSizeInBits() > InOp.getValueType().getSizeInBits())
> +       return DAG.getNode(ISD::SIGN_EXTEND, InVec.getDebugLoc(), NVT, InOp);
> +     else
> +       return DAG.getNode(ISD::TRUNCATE, InVec.getDebugLoc(), NVT, InOp);
> +   }

There is a special method for this: DAG.getSExtOrTrunc.

> @@ -2765,7 +2765,7 @@
>      // operations are lowered to scalars.
>      if (N1.getOpcode() == ISD::INSERT_VECTOR_ELT) {
>        // If the indices are the same, return the inserted element.
> -      if (N1.getOperand(2) == N2)
> +      if (N1.getOperand(2) == N2 && VT == N1.getOperand(1).getValueType())
>          return N1.getOperand(1);
>        // If the indices are known different, extract the element from
>        // the original vector.

Why not just extend/truncate here too?

Ciao,

Duncan.



More information about the llvm-commits mailing list