[NFC][CostModel] Refactor getCastInstrCost
authorSam Parker <sam.parker@arm.com>
Mon, 27 Apr 2020 11:41:30 +0000 (12:41 +0100)
committerSam Parker <sam.parker@arm.com>
Mon, 27 Apr 2020 11:42:34 +0000 (12:42 +0100)
Move ZExt/SExt load handling into the BasicTTI switch statement.

llvm/include/llvm/CodeGen/BasicTTIImpl.h

index 21e3d93..0aca5cf 100644 (file)
@@ -702,24 +702,25 @@ public:
     case Instruction::ZExt:
       if (TLI->isZExtFree(SrcLT.second, DstLT.second))
         return 0;
-      break;
-    case Instruction::AddrSpaceCast:
-      if (TLI->isFreeAddrSpaceCast(Src->getPointerAddressSpace(),
-                                   Dst->getPointerAddressSpace()))
-        return 0;
-      break;
-    }
-
-    // If this is a zext/sext of a load, return 0 if the corresponding
-    // extending load exists on target.
-    if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) &&
-        I && isa<LoadInst>(I->getOperand(0))) {
+      LLVM_FALLTHROUGH;
+    case Instruction::SExt: {
+      // If this is a zext/sext of a load, return 0 if the corresponding
+      // extending load exists on target.
+      if (I && isa<LoadInst>(I->getOperand(0))) {
         EVT ExtVT = EVT::getEVT(Dst);
         EVT LoadVT = EVT::getEVT(Src);
         unsigned LType =
           ((Opcode == Instruction::ZExt) ? ISD::ZEXTLOAD : ISD::SEXTLOAD);
         if (TLI->isLoadExtLegal(LType, ExtVT, LoadVT))
           return 0;
+      }
+      break;
+    }
+    case Instruction::AddrSpaceCast:
+      if (TLI->isFreeAddrSpaceCast(Src->getPointerAddressSpace(),
+                                   Dst->getPointerAddressSpace()))
+        return 0;
+      break;
     }
 
     // If the cast is marked as legal (or promote) then assume low cost.