[llvm-commits] [dragonegg] r132182 - in /dragonegg/trunk: include/dragonegg/Internals.h src/Convert.cpp

Duncan Sands baldrick at free.fr
Fri May 27 01:12:03 PDT 2011


Author: baldrick
Date: Fri May 27 03:12:03 2011
New Revision: 132182

URL: http://llvm.org/viewvc/llvm-project?rev=132182&view=rev
Log:
Add support for VEC_LSHIFT_EXPR and VEC_RSHIFT_EXPR, fixing PR10015.

Modified:
    dragonegg/trunk/include/dragonegg/Internals.h
    dragonegg/trunk/src/Convert.cpp

Modified: dragonegg/trunk/include/dragonegg/Internals.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/dragonegg/Internals.h?rev=132182&r1=132181&r2=132182&view=diff
==============================================================================
--- dragonegg/trunk/include/dragonegg/Internals.h (original)
+++ dragonegg/trunk/include/dragonegg/Internals.h Fri May 27 03:12:03 2011
@@ -698,6 +698,7 @@
   Value *EmitReg_RotateOp(tree_node *type, tree_node *op0, tree_node *op1,
                           unsigned Opc1, unsigned Opc2);
   Value *EmitReg_ShiftOp(tree_node *op0, tree_node *op1, unsigned Opc);
+  Value *EmitReg_VecShiftOp(tree_node *op0, tree_node *op1, unsigned Opc);
   Value *EmitReg_TruthOp(tree_node *type, tree_node *op0, tree_node *op1,
                          unsigned Opc);
   Value *EmitReg_BIT_AND_EXPR(tree_node *op0, tree_node *op1);

Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=132182&r1=132181&r2=132182&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Fri May 27 03:12:03 2011
@@ -6791,6 +6791,30 @@
   return Builder.CreateBinOp((Instruction::BinaryOps)Opc, LHS, RHS);
 }
 
+Value *TreeToLLVM::EmitReg_VecShiftOp(tree op0, tree op1, unsigned Opc) {
+  Value *LHS = EmitRegister(op0); // A vector.
+  Value *Amt = EmitRegister(op1); // An integer.
+
+  // Ensure the shift amount has the same type as the vector element type.
+  const VectorType *VecTy = cast<VectorType>(LHS->getType());
+  const Type *EltTy = VecTy->getElementType();
+  if (Amt->getType() != EltTy)
+    Amt = Builder.CreateIntCast(Amt, EltTy, /*isSigned*/false,
+                                Amt->getName()+".cast");
+
+  // Form a vector with all elements equal to the shift amount by creating a
+  // vector with the amount as the first element then shuffling it all over.
+  Constant *Zero = Constant::getNullValue(Type::getInt32Ty(Context));
+  Value *RHS = Builder.CreateInsertElement(UndefValue::get(VecTy), Amt, Zero);
+  const Type *MaskTy = VectorType::get(Type::getInt32Ty(Context),
+                                       VecTy->getNumElements());
+  Constant *Mask = ConstantInt::get(MaskTy, 0);
+  RHS = Builder.CreateShuffleVector(RHS, UndefValue::get(VecTy), Mask);
+
+  // Form the shift.
+  return Builder.CreateBinOp((Instruction::BinaryOps)Opc, LHS, RHS);
+}
+
 Value *TreeToLLVM::EmitReg_TruthOp(tree type, tree op0, tree op1, unsigned Opc){
   Value *LHS = EmitRegister(op0);
   Value *RHS = EmitRegister(op1);
@@ -8312,8 +8336,14 @@
     RHS = EmitReg_VEC_INTERLEAVE_HIGH_EXPR(rhs1, rhs2); break;
   case VEC_INTERLEAVE_LOW_EXPR:
     RHS = EmitReg_VEC_INTERLEAVE_LOW_EXPR(rhs1, rhs2); break;
+  case VEC_LSHIFT_EXPR:
+    RHS = EmitReg_VecShiftOp(rhs1, rhs2, Instruction::Shl); break;
   case VEC_PACK_TRUNC_EXPR:
     RHS = EmitReg_VEC_PACK_TRUNC_EXPR(type, rhs1, rhs2); break;
+  case VEC_RSHIFT_EXPR:
+    RHS = EmitReg_VecShiftOp(rhs1, rhs2, TYPE_UNSIGNED(TREE_TYPE(type)) ?
+                             Instruction::LShr : Instruction::AShr);
+    break;
   case VEC_UNPACK_HI_EXPR:
     RHS = EmitReg_VEC_UNPACK_HI_EXPR(type, rhs1); break;
   case VEC_UNPACK_LO_EXPR:





More information about the llvm-commits mailing list