[llvm-commits] [dragonegg] r132121 - /dragonegg/trunk/src/Convert.cpp
Duncan Sands
baldrick at free.fr
Thu May 26 05:37:43 PDT 2011
Author: baldrick
Date: Thu May 26 07:37:43 2011
New Revision: 132121
URL: http://llvm.org/viewvc/llvm-project?rev=132121&view=rev
Log:
Add support for ABS_EXPR on a vector of floats.
Modified:
dragonegg/trunk/src/Convert.cpp
Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=132121&r1=132120&r2=132121&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Thu May 26 07:37:43 2011
@@ -6483,6 +6483,24 @@
Value *Cmp = Builder.CreateICmp(pred, Op,
Constant::getNullValue(Op->getType()), "abscond");
return Builder.CreateSelect(Cmp, Op, OpN, Op->getName()+"abs");
+ } else if (TREE_CODE(TREE_TYPE(op)) == VECTOR_TYPE) {
+ // Clear the sign bits.
+ Value *Op = EmitRegister(op);
+ const VectorType *VecTy = cast<VectorType>(Op->getType());
+
+ // Mask = ~(1 << (Bits-1)).
+ unsigned Bits = VecTy->getElementType()->getPrimitiveSizeInBits();
+ const Type *IntTy = IntegerType::get(Context, Bits);
+ const Type *IntVecTy = VectorType::get(IntTy, VecTy->getNumElements());
+ APInt API = APInt::getAllOnesValue(Bits);
+ API.clearBit(Bits-1);
+ Constant *Mask = ConstantInt::get(IntVecTy, API);
+
+ // Zap the sign bits.
+ Op = Builder.CreateBitCast(Op, IntVecTy);
+ Op = Builder.CreateAnd(Op, Mask);
+ Op = Builder.CreateBitCast(Op, VecTy);
+ return Op;
}
// Turn FP abs into fabs/fabsf.
More information about the llvm-commits
mailing list