[llvm-commits] [llvm-gcc-4.2] r56533 - /llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Evan Cheng evan.cheng at apple.com
Tue Sep 23 17:49:34 PDT 2008


Author: evancheng
Date: Tue Sep 23 19:49:33 2008
New Revision: 56533

URL: http://llvm.org/viewvc/llvm-project?rev=56533&view=rev
Log:
Implement floating-point not.

Modified:
    llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp

Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=56533&r1=56532&r2=56533&view=diff

==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Tue Sep 23 19:49:33 2008
@@ -3204,6 +3204,25 @@
   return Call;
 }
 
+/// getSuitableBitCastIntType - Given Ty is a floating point type or a vector
+/// type with floating point elements, return an integer type to bitcast to.
+/// e.g. 4 x float -> 4 x i32
+static const Type *getSuitableBitCastIntType(const Type *Ty) {
+  if (Ty == Type::FloatTy)
+    return Type::Int32Ty;
+  else if (Ty == Type::DoubleTy)
+    return Type::Int64Ty;
+  else if (const VectorType *VTy = dyn_cast<VectorType>(Ty)) {
+    unsigned NumElements = VTy->getNumElements();
+    const Type *EltTy = VTy->getElementType();
+    if (EltTy == Type::FloatTy)
+      return VectorType::get(Type::Int32Ty, NumElements);
+    else if (EltTy == Type::DoubleTy)
+      return VectorType::get(Type::Int64Ty, NumElements);
+  }
+  return NULL;
+}
+
 Value *TreeToLLVM::EmitBIT_NOT_EXPR(tree exp) {
   Value *Op = Emit(TREE_OPERAND(exp, 0), 0);
   if (isa<PointerType>(Op->getType())) {
@@ -3211,6 +3230,16 @@
             "Expected integer type here");
     Op = CastToType(Instruction::PtrToInt, Op, TREE_TYPE(exp));
   }
+
+  const Type *Ty = Op->getType();
+  if (Ty->isFloatingPoint() ||
+      (isa<VectorType>(Ty) && 
+       cast<VectorType>(Ty)->getElementType()->isFloatingPoint())) {
+    Ty = getSuitableBitCastIntType(Ty);
+    if (!Ty)
+      abort();
+    Op = BitCastToType(Op, Ty);
+  }
   return Builder.CreateNot(Op, (Op->getName()+"not").c_str());
 }
 
@@ -3297,20 +3326,8 @@
       (Ty->isFloatingPoint() ||
        (isa<VectorType>(Ty) && 
         cast<VectorType>(Ty)->getElementType()->isFloatingPoint()))) {
-    if (Ty == Type::FloatTy)
-      Ty = Type::Int32Ty;
-    else if (Ty == Type::DoubleTy)
-      Ty = Type::Int64Ty;
-    else if (const VectorType *VTy = dyn_cast<VectorType>(Ty)) {
-      unsigned NumElements = VTy->getNumElements();
-      const Type *EltTy = VTy->getElementType();
-      if (EltTy == Type::FloatTy)
-        Ty = VectorType::get(Type::Int32Ty, NumElements);
-      else if (EltTy == Type::DoubleTy)
-        Ty = VectorType::get(Type::Int64Ty, NumElements);
-      else
-        abort();
-    } else
+    Ty = getSuitableBitCastIntType(Ty);
+    if (!Ty)
       abort();
     LHS = BitCastToType(LHS, Ty);
     RHS = BitCastToType(RHS, Ty);





More information about the llvm-commits mailing list