[llvm] r176131 - Constant fold vector bitcasts of halves similarly to how floats and doubles are folded. Test case included.

Michael Ilseman milseman at apple.com
Tue Feb 26 14:51:07 PST 2013


Author: milseman
Date: Tue Feb 26 16:51:07 2013
New Revision: 176131

URL: http://llvm.org/viewvc/llvm-project?rev=176131&view=rev
Log:
Constant fold vector bitcasts of halves similarly to how floats and doubles are folded. Test case included.

Modified:
    llvm/trunk/lib/Analysis/ConstantFolding.cpp
    llvm/trunk/test/Transforms/InstCombine/bitcast-vector-fold.ll

Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=176131&r1=176130&r2=176131&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Tue Feb 26 16:51:07 2013
@@ -54,13 +54,12 @@ static Constant *FoldBitCast(Constant *C
 
   // Handle a vector->integer cast.
   if (IntegerType *IT = dyn_cast<IntegerType>(DestTy)) {
-    ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(C);
-    if (CDV == 0)
+    VectorType *VTy = dyn_cast<VectorType>(C->getType());
+    if (VTy == 0)
       return ConstantExpr::getBitCast(C, DestTy);
 
-    unsigned NumSrcElts = CDV->getType()->getNumElements();
-
-    Type *SrcEltTy = CDV->getType()->getElementType();
+    unsigned NumSrcElts = VTy->getNumElements();
+    Type *SrcEltTy = VTy->getElementType();
 
     // If the vector is a vector of floating point, convert it to vector of int
     // to simplify things.
@@ -70,9 +69,12 @@ static Constant *FoldBitCast(Constant *C
         VectorType::get(IntegerType::get(C->getContext(), FPWidth), NumSrcElts);
       // Ask IR to do the conversion now that #elts line up.
       C = ConstantExpr::getBitCast(C, SrcIVTy);
-      CDV = cast<ConstantDataVector>(C);
     }
 
+    ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(C);
+    if (CDV == 0)
+      return ConstantExpr::getBitCast(C, DestTy);
+
     // Now that we know that the input value is a vector of integers, just shift
     // and insert them into our result.
     unsigned BitShift = TD.getTypeAllocSizeInBits(SrcEltTy);

Modified: llvm/trunk/test/Transforms/InstCombine/bitcast-vector-fold.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/bitcast-vector-fold.ll?rev=176131&r1=176130&r2=176131&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/bitcast-vector-fold.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/bitcast-vector-fold.ll Tue Feb 26 16:51:07 2013
@@ -31,3 +31,8 @@ define <4 x i32> @test6() {
 	%tmp3 = bitcast <2 x double> <double 0.5, double 1.0> to <4 x i32>
 	ret <4 x i32> %tmp3
 }
+
+define i32 @test7() {
+       %tmp3 = bitcast <2 x half> <half 0xH1100, half 0xH0011> to i32
+       ret i32 %tmp3
+}
\ No newline at end of file





More information about the llvm-commits mailing list