[llvm-commits] [llvm] r138206 - in /llvm/trunk: lib/Analysis/ConstantFolding.cpp test/Transforms/InstCombine/bitcast.ll

Duncan Sands baldrick at free.fr
Sun Aug 21 04:13:38 PDT 2011


Hi Nadav,

> Add constant folding support for bitcasts of splat vectors to integers.
>
>
> Modified:
>      llvm/trunk/lib/Analysis/ConstantFolding.cpp
>      llvm/trunk/test/Transforms/InstCombine/bitcast.ll
>
> Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=138206&r1=138205&r2=138206&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
> +++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Sat Aug 20 09:02:29 2011
> @@ -46,7 +46,16 @@
>   static Constant *FoldBitCast(Constant *C, Type *DestTy,
>                                const TargetData&TD) {
>
> -  // This only handles casts to vectors currently.
> +  ConstantVector *CV = dyn_cast<ConstantVector>(C);
> +  IntegerType *IntVTy = dyn_cast<IntegerType>(DestTy);
> +  // When casting vectors to scalar integers, catch the
> +  // obvious splat cases.
> +  if (IntVTy&&  CV) {

these tests seem fairly pointless.  It shouldn't matter that the source is a
vector and the target is an integer.  For the null value case you can just do:

if (C->isNullValue())
   return Constant::getNullValue(DestTy);

Unfortunately you can't currently do

if (C->isAllOnesValue())
   return Constant::getAllOnesValue(DestTy);

That's because isAllOnes value doesn't exist (but I think it should) and
getAllOnes value only handles a limited range of types (but I think it
should be extended to handle everything, like getNullValue).  Any chance
of implementing this - making AllOnes work uniformly like NullValue?

Ciao, Duncan.


> +    if (CV->isNullValue()) return ConstantInt::getNullValue(IntVTy);
> +    if (CV->isAllOnesValue()) return ConstantInt::getAllOnesValue(IntVTy);
> +  }
> +
> +  // The code below only handles casts to vectors currently.
>     VectorType *DestVTy = dyn_cast<VectorType>(DestTy);
>     if (DestVTy == 0)
>       return ConstantExpr::getBitCast(C, DestTy);
> @@ -59,7 +68,6 @@
>     }
>
>     // If this is a bitcast from constant vector ->  vector, fold it.
> -  ConstantVector *CV = dyn_cast<ConstantVector>(C);
>     if (CV == 0)
>       return ConstantExpr::getBitCast(C, DestTy);
>
>
> Modified: llvm/trunk/test/Transforms/InstCombine/bitcast.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/bitcast.ll?rev=138206&r1=138205&r2=138206&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstCombine/bitcast.ll (original)
> +++ llvm/trunk/test/Transforms/InstCombine/bitcast.ll Sat Aug 20 09:02:29 2011
> @@ -1,5 +1,8 @@
>   ; RUN: opt<  %s -instcombine -S | FileCheck %s
>
> +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
> +target triple = "x86_64-apple-darwin10.0.0"
> +
>   ; Bitcasts between vectors and scalars are valid.
>   ; PR4487
>   define i32 @test1(i64 %a) {
> @@ -103,3 +106,10 @@
>   ; CHECK-NEXT: insertelement<2 x float>  <float 4.200000e+01, float undef>, float %A, i32 1
>   ; CHECK: ret
>   }
> +
> +define i64 @ISPC0(i64 %in) {
> +  %out = and i64 %in, xor (i64 bitcast (<4 x i16>  <i16 -1, i16 -1, i16 -1, i16 -1>  to i64), i64 -1)
> +  ret i64 %out
> +; CHECK: @ISPC0
> +; CHECK: ret i64 0
> +}
>
>
> _______________________________________________
> 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