[llvm-commits] [llvm] r149226 - /llvm/trunk/lib/VMCore/Constants.cpp

Duncan Sands baldrick at free.fr
Thu Feb 9 06:06:47 PST 2012


Hi Chris,

> First step of flipping on ConstantDataSequential: enable ConstantDataVector
> to be formed whenever ConstantVector::get is used.

> --- llvm/trunk/lib/VMCore/Constants.cpp (original)
> +++ llvm/trunk/lib/VMCore/Constants.cpp Mon Jan 30 00:21:21 2012
> @@ -836,11 +836,89 @@
>       return ConstantAggregateZero::get(T);
>     if (isUndef)
>       return UndefValue::get(T);
> +
> +  // Check to see if all of the elements are ConstantFP or ConstantInt and if
> +  // the element type is compatible with ConstantDataVector.  If so, use it.
> +  if (ConstantDataSequential::isElementTypeCompatible(C->getType())&&
> +      (isa<ConstantFP>(C) || isa<ConstantInt>(C))) {
> +    // We speculatively build the elements here even if it turns out that there
> +    // is a constantexpr or something else weird in the array, since it is so
> +    // uncommon for that to happen.
> +    if (ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
> +      if (CI->getType()->isIntegerTy(8)) {
> +        SmallVector<uint8_t, 16>  Elts;
> +        for (unsigned i = 0, e = V.size(); i != e; ++i)
> +          if (ConstantInt *CI = dyn_cast<ConstantInt>(V[i]))
> +            Elts.push_back(CI->getZExtValue());
> +          else
> +            break;

here you know the first element of V is a ConstantInt, since that element is C
and you checked C above.  So this could be written like this instead

         SmallVector<uint8_t, 16>  Elts;
         Elts.push_back(CI->getZExtValue());
         for (unsigned i = 1, e = V.size(); i < e; ++i)
           if (ConstantInt *CI = dyn_cast<ConstantInt>(V[i]))
             Elts.push_back(CI->getZExtValue());
           else
             break;

saving one dyn_cast.  Maybe not worth it.

...
> +    }
>
> +    if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {

This could be
     } else if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
saving a pointless dyn_cast if you got here from the ConstantInt case.

Ciao, Duncan.



More information about the llvm-commits mailing list