Use the isTruncFree and isZExtFree API to figure out of these operations are free...
authorNadav Rotem <nrotem@apple.com>
Sun, 11 Nov 2012 05:34:45 +0000 (05:34 +0000)
committerNadav Rotem <nrotem@apple.com>
Sun, 11 Nov 2012 05:34:45 +0000 (05:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167685 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/TargetTransformImpl.cpp

index c07332de32968827593b63e31b1c04578e9320b0..b36e6f858f7251b0cde7803ce8cdaedd08f946a1 100644 (file)
@@ -214,8 +214,16 @@ unsigned VectorTargetTransformImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
   // Handle scalar conversions.
   if (!Src->isVectorTy() && !Dst->isVectorTy()) {
 
-    // Scalar bitcasts and truncs are usually free.
-    if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
+    // Scalar bitcasts are usually free.
+    if (Opcode == Instruction::BitCast)
+      return 0;
+
+    if (Opcode == Instruction::Trunc &&
+        TLI->isTruncateFree(SrcLT.second, DstLT.second))
+      return 0;
+
+    if (Opcode == Instruction::ZExt &&
+        TLI->isZExtFree(SrcLT.second, DstLT.second))
       return 0;
 
     // Just check the op cost. If the operation is legal then assume it costs 1.