[llvm-commits] [llvm] r65835 - in /llvm/branches/Apple/Dib: include/llvm/Bitcode/LLVMBitCodes.h lib/Bitcode/Reader/BitcodeReader.cpp lib/Bitcode/Writer/BitcodeWriter.cpp lib/VMCore/Constants.cpp test/Transforms/InstCombine/shufflevec-constant.ll

Bill Wendling isanbard at gmail.com
Mon Mar 2 01:46:35 PST 2009


Author: void
Date: Mon Mar  2 03:46:35 2009
New Revision: 65835

URL: http://llvm.org/viewvc/llvm-project?rev=65835&view=rev
Log:
Merge r64401 into Dib:

Add suppport for ConstantExprs of shufflevectors whose result type is not equal
to the type of the vectors being shuffled.

Added:
    llvm/branches/Apple/Dib/test/Transforms/InstCombine/shufflevec-constant.ll
      - copied unchanged from r64401, llvm/trunk/test/Transforms/InstCombine/shufflevec-constant.ll
Modified:
    llvm/branches/Apple/Dib/include/llvm/Bitcode/LLVMBitCodes.h
    llvm/branches/Apple/Dib/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/branches/Apple/Dib/lib/Bitcode/Writer/BitcodeWriter.cpp
    llvm/branches/Apple/Dib/lib/VMCore/Constants.cpp

Modified: llvm/branches/Apple/Dib/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/Bitcode/LLVMBitCodes.h?rev=65835&r1=65834&r2=65835&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/branches/Apple/Dib/include/llvm/Bitcode/LLVMBitCodes.h Mon Mar  2 03:46:35 2009
@@ -125,7 +125,8 @@
     CST_CODE_CE_INSERTELT  = 15,  // CE_INSERTELT:  [opval, opval, opval]
     CST_CODE_CE_SHUFFLEVEC = 16,  // CE_SHUFFLEVEC: [opval, opval, opval]
     CST_CODE_CE_CMP        = 17,  // CE_CMP:        [opty, opval, opval, pred]
-    CST_CODE_INLINEASM     = 18   // INLINEASM:     [sideeffect,asmstr,conststr]
+    CST_CODE_INLINEASM     = 18,  // INLINEASM:     [sideeffect,asmstr,conststr]
+    CST_CODE_CE_SHUFVEC_EX = 19   // SHUFVEC_EX:    [opty, opval, opval, opval]
   };
   
   /// CastOpcodes - These are values used in the bitcode files to encode which

Modified: llvm/branches/Apple/Dib/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Bitcode/Reader/BitcodeReader.cpp?rev=65835&r1=65834&r2=65835&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Bitcode/Reader/BitcodeReader.cpp Mon Mar  2 03:46:35 2009
@@ -933,7 +933,7 @@
     case bitc::CST_CODE_CE_SHUFFLEVEC: { // CE_SHUFFLEVEC: [opval, opval, opval]
       const VectorType *OpTy = dyn_cast<VectorType>(CurTy);
       if (Record.size() < 3 || OpTy == 0)
-        return Error("Invalid CE_INSERTELT record");
+        return Error("Invalid CE_SHUFFLEVEC record");
       Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy);
       Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy);
       const Type *ShufTy=VectorType::get(Type::Int32Ty, OpTy->getNumElements());
@@ -941,6 +941,18 @@
       V = ConstantExpr::getShuffleVector(Op0, Op1, Op2);
       break;
     }
+    case bitc::CST_CODE_CE_SHUFVEC_EX: { // [opty, opval, opval, opval]
+      const VectorType *RTy = dyn_cast<VectorType>(CurTy);
+      const VectorType *OpTy = dyn_cast<VectorType>(getTypeByID(Record[0]));
+      if (Record.size() < 4 || RTy == 0 || OpTy == 0)
+        return Error("Invalid CE_SHUFVEC_EX record");
+      Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy);
+      Constant *Op1 = ValueList.getConstantFwdRef(Record[2], OpTy);
+      const Type *ShufTy=VectorType::get(Type::Int32Ty, RTy->getNumElements());
+      Constant *Op2 = ValueList.getConstantFwdRef(Record[3], ShufTy);
+      V = ConstantExpr::getShuffleVector(Op0, Op1, Op2);
+      break;
+    }
     case bitc::CST_CODE_CE_CMP: {     // CE_CMP: [opty, opval, opval, pred]
       if (Record.size() < 4) return Error("Invalid CE_CMP record");
       const Type *OpTy = getTypeByID(Record[0]);

Modified: llvm/branches/Apple/Dib/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=65835&r1=65834&r2=65835&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Bitcode/Writer/BitcodeWriter.cpp Mon Mar  2 03:46:35 2009
@@ -643,7 +643,16 @@
         Record.push_back(VE.getValueID(C->getOperand(2)));
         break;
       case Instruction::ShuffleVector:
-        Code = bitc::CST_CODE_CE_SHUFFLEVEC;
+        // If the return type and argument types are the same, this is a
+        // standard shufflevector instruction.  If the types are different,
+        // then the shuffle is widening or truncating the input vectors, and
+        // the argument type must also be encoded.
+        if (C->getType() == C->getOperand(0)->getType()) {
+          Code = bitc::CST_CODE_CE_SHUFFLEVEC;
+        } else {
+          Code = bitc::CST_CODE_CE_SHUFVEC_EX;
+          Record.push_back(VE.getTypeID(C->getOperand(0)->getType()));
+        }
         Record.push_back(VE.getValueID(C->getOperand(0)));
         Record.push_back(VE.getValueID(C->getOperand(1)));
         Record.push_back(VE.getValueID(C->getOperand(2)));

Modified: llvm/branches/Apple/Dib/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/VMCore/Constants.cpp?rev=65835&r1=65834&r2=65835&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/VMCore/Constants.cpp (original)
+++ llvm/branches/Apple/Dib/lib/VMCore/Constants.cpp Mon Mar  2 03:46:35 2009
@@ -554,7 +554,10 @@
     return User::operator new(s, 3);
   }
   ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3)
-  : ConstantExpr(C1->getType(), Instruction::ShuffleVector, 
+  : ConstantExpr(VectorType::get(
+                   cast<VectorType>(C1->getType())->getElementType(),
+                   cast<VectorType>(C3->getType())->getNumElements()),
+                 Instruction::ShuffleVector, 
                  &Op<0>(), 3) {
     Op<0>() = C1;
     Op<1>() = C2;
@@ -2349,7 +2352,11 @@
                                          Constant *Mask) {
   assert(ShuffleVectorInst::isValidOperands(V1, V2, Mask) &&
          "Invalid shuffle vector constant expr operands!");
-  return getShuffleVectorTy(V1->getType(), V1, V2, Mask);
+
+  unsigned NElts = cast<VectorType>(Mask->getType())->getNumElements();
+  const Type *EltTy = cast<VectorType>(V1->getType())->getElementType();
+  const Type *ShufTy = VectorType::get(EltTy, NElts);
+  return getShuffleVectorTy(ShufTy, V1, V2, Mask);
 }
 
 Constant *ConstantExpr::getInsertValueTy(const Type *ReqTy, Constant *Agg,





More information about the llvm-commits mailing list