Implement casts.ll:test26: a cast from float -> double -> integer, doesn't
authorChris Lattner <sabre@nondot.org>
Thu, 19 Jan 2006 07:40:22 +0000 (07:40 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 19 Jan 2006 07:40:22 +0000 (07:40 +0000)
need the float->double part.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25452 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 2fcf91948465134e1f1e1ce5899422ceb39084ef..f440e475e0b2195793efe8b7f8ebe2abcae595a9 100644 (file)
@@ -3799,8 +3799,8 @@ static CastType getCastType(const Type *Src, const Type *Dest) {
 // isEliminableCastOfCast - Return true if it is valid to eliminate the CI
 // instruction.
 //
-static inline bool isEliminableCastOfCast(const Type *SrcTy, const Type *MidTy,
-                                          const Type *DstTy, TargetData *TD) {
+static bool isEliminableCastOfCast(const Type *SrcTy, const Type *MidTy,
+                                   const Type *DstTy, TargetData *TD) {
 
   // It is legal to eliminate the instruction if casting A->B->A if the sizes
   // are identical and the bits don't get reinterpreted (for example
@@ -3856,6 +3856,15 @@ static inline bool isEliminableCastOfCast(const Type *SrcTy, const Type *MidTy,
       return ResultCast == FirstCast;
     }
   }
+  
+  // If this is a cast from 'float -> double -> integer', cast from
+  // 'float -> integer' directly, as the value isn't changed by the 
+  // float->double conversion.
+  if (SrcTy->isFloatingPoint() && MidTy->isFloatingPoint() &&
+      DstTy->isIntegral() && 
+      SrcTy->getPrimitiveSize() < MidTy->getPrimitiveSize())
+    return true;
+  
   return false;
 }