[llvm-commits] [llvm] r163817 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp

Duncan Sands baldrick at free.fr
Fri Sep 14 00:31:06 PDT 2012


Hi Dan,

> Extract code for reducing a type to a single value type into a helper function.

I know you were just moving it, but

> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Thu Sep 13 13:19:06 2012
> @@ -29,6 +29,26 @@
>     return Ty;
>   }
>
> +/// reduceToSingleValueType - Given an aggregate type which ultimately holds a
> +/// single scalar element, like {{{type}}} or [1 x type], return type.
> +static Type *reduceToSingleValueType(Type *T) {
> +  while (!T->isSingleValueType()) {

You could also handle vectors of one element.

> +    if (StructType *STy = dyn_cast<StructType>(T)) {
> +      if (STy->getNumElements() == 1)
> +        T = STy->getElementType(0);
> +      else
> +        break;

If you have a struct with more than one element, say { i32, i32 }, then
{ i32, i32 } will be returned, which is kind of unexpected given the
description of the function.  How about returning null.

> +    } else if (ArrayType *ATy = dyn_cast<ArrayType>(T)) {
> +      if (ATy->getNumElements() == 1)
> +        T = ATy->getElementType();
> +      else
> +        break;

Likewise.

> +    } else
> +      break;

Likewise.

> +  }
> +
> +  return T;
> +}
>
>   Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
>     unsigned DstAlign = getKnownAlignment(MI->getArgOperand(0), TD);
> @@ -80,20 +100,7 @@
>       if (TD && SrcETy->isSized() && TD->getTypeStoreSize(SrcETy) == Size) {
>         // The SrcETy might be something like {{{double}}} or [1 x double].  Rip
>         // down through these levels if so.
> -      while (!SrcETy->isSingleValueType()) {
> -        if (StructType *STy = dyn_cast<StructType>(SrcETy)) {
> -          if (STy->getNumElements() == 1)
> -            SrcETy = STy->getElementType(0);
> -          else
> -            break;
> -        } else if (ArrayType *ATy = dyn_cast<ArrayType>(SrcETy)) {
> -          if (ATy->getNumElements() == 1)
> -            SrcETy = ATy->getElementType();
> -          else
> -            break;
> -        } else
> -          break;
> -      }
> +      SrcETy = reduceToSingleValueType(SrcETy);
>
>         if (SrcETy->isSingleValueType()) {

Here you would check for non-null.

Ciao, Duncan.

>           NewSrcPtrTy = PointerType::get(SrcETy, SrcAddrSp);
> @@ -102,7 +109,6 @@
>       }
>     }
>
> -
>     // If the memcpy/memmove provides better alignment info than we can
>     // infer, use it.
>     SrcAlign = std::max(SrcAlign, CopyAlign);
>
>
> _______________________________________________
> 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