- Rename isLegalMemOpType to isSafeMemOpType. "Legal" is a very overloade term.
authorEvan Cheng <evan.cheng@apple.com>
Wed, 12 Dec 2012 01:32:07 +0000 (01:32 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 12 Dec 2012 01:32:07 +0000 (01:32 +0000)
Also added more comments to explain why it is generally ok to return true.
- Rename getOptimalMemOpType argument IsZeroVal to ZeroOrLdSrc. It's meant to
be true for loaded source (memcpy) or zero constants (memset). The poor name
choice is probably some kind of legacy issue.

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

include/llvm/Target/TargetLowering.h
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/Target/ARM/ARMISelLowering.cpp
lib/Target/ARM/ARMISelLowering.h
lib/Target/Mips/MipsISelLowering.cpp
lib/Target/Mips/MipsISelLowering.h
lib/Target/PowerPC/PPCISelLowering.cpp
lib/Target/PowerPC/PPCISelLowering.h
lib/Target/X86/X86ISelLowering.cpp
lib/Target/X86/X86ISelLowering.h

index f3010438518a6fbca5aee731d4f1fda2b97e0855..3adf517e4abc5ae35d4b3134578f87f3ae3a0629 100644 (file)
@@ -702,7 +702,7 @@ public:
   /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
   /// means there isn't a need to check it against alignment requirement,
   /// probably because the source does not need to be loaded. If
-  /// 'IsZeroVal' is true, that means it's safe to return a
+  /// 'ZeroOrLdSrc' is true, that means it's safe to return a
   /// non-scalar-integer type, e.g. empty string source, constant, or loaded
   /// from memory. 'MemcpyStrSrc' indicates whether the memcpy source is
   /// constant so it does not need to be loaded.
@@ -710,19 +710,20 @@ public:
   /// target-independent logic.
   virtual EVT getOptimalMemOpType(uint64_t /*Size*/,
                                   unsigned /*DstAlign*/, unsigned /*SrcAlign*/,
-                                  bool /*IsZeroVal*/,
+                                  bool /*ZeroOrLdSrc*/,
                                   bool /*MemcpyStrSrc*/,
                                   MachineFunction &/*MF*/) const {
     return MVT::Other;
   }
 
-  /// isLegalMemOpType - Returns true if it's legal to use load / store of the
+  /// isSafeMemOpType - Returns true if it's safe to use load / store of the
   /// specified type to expand memcpy / memset inline. This is mostly true
-  /// for legal types except for some special cases. For example, on X86
+  /// for all types except for some special cases. For example, on X86
   /// targets without SSE2 f64 load / store are done with fldl / fstpl which
-  /// also does type conversion.
-  virtual bool isLegalMemOpType(MVT VT) const {
-    return VT.isInteger();
+  /// also does type conversion. Note the specified type doesn't have to be
+  /// legal as the hook is used before type legalization.
+  virtual bool isSafeMemOpType(MVT VT) const {
+    return true;
   }
 
   /// usesUnderscoreSetJmp - Determine if we should use _setjmp or setjmp
index 36592e54f8f2be712776b2d2021a89b6ac868f8d..754e6f352d46b66916a0636a947416f1760e57d8 100644 (file)
@@ -3426,7 +3426,7 @@ static bool isMemSrcFromString(SDValue Src, StringRef &Str) {
 static bool FindOptimalMemOpLowering(std::vector<EVT> &MemOps,
                                      unsigned Limit, uint64_t Size,
                                      unsigned DstAlign, unsigned SrcAlign,
-                                     bool IsZeroVal,
+                                     bool ZeroOrLdSrc,
                                      bool MemcpyStrSrc,
                                      bool AllowOverlap,
                                      SelectionDAG &DAG,
@@ -3441,7 +3441,7 @@ static bool FindOptimalMemOpLowering(std::vector<EVT> &MemOps,
   // 'MemcpyStrSrc' indicates whether the memcpy source is constant so it does
   // not need to be loaded.
   EVT VT = TLI.getOptimalMemOpType(Size, DstAlign, SrcAlign,
-                                   IsZeroVal, MemcpyStrSrc,
+                                   ZeroOrLdSrc, MemcpyStrSrc,
                                    DAG.getMachineFunction());
 
   if (VT == MVT::Other) {
@@ -3481,11 +3481,11 @@ static bool FindOptimalMemOpLowering(std::vector<EVT> &MemOps,
       if (VT.isVector() || VT.isFloatingPoint()) {
         NewVT = (VT.getSizeInBits() > 64) ? MVT::i64 : MVT::i32;
         if (TLI.isOperationLegalOrCustom(ISD::STORE, NewVT) &&
-            TLI.isLegalMemOpType(NewVT.getSimpleVT()))
+            TLI.isSafeMemOpType(NewVT.getSimpleVT()))
           Found = true;
         else if (NewVT == MVT::i64 &&
                  TLI.isOperationLegalOrCustom(ISD::STORE, MVT::f64) &&
-                 TLI.isLegalMemOpType(MVT::f64)) {
+                 TLI.isSafeMemOpType(MVT::f64)) {
           // i64 is usually not legal on 32-bit targets, but f64 may be.
           NewVT = MVT::f64;
           Found = true;
@@ -3497,7 +3497,7 @@ static bool FindOptimalMemOpLowering(std::vector<EVT> &MemOps,
           NewVT = (MVT::SimpleValueType)(NewVT.getSimpleVT().SimpleTy - 1);
           if (NewVT == MVT::i8)
             break;
-        } while (!TLI.isLegalMemOpType(NewVT.getSimpleVT()));
+        } while (!TLI.isSafeMemOpType(NewVT.getSimpleVT()));
       }
       NewVTSize = NewVT.getSizeInBits() / 8;
 
index de7159e474a538324279241ddb7616cb33b0cb84..613df7a9b38b75e2f73c4d6371e037b1004c1c57 100644 (file)
@@ -9450,13 +9450,13 @@ static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign,
 
 EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size,
                                            unsigned DstAlign, unsigned SrcAlign,
-                                           bool IsZeroVal,
+                                           bool ZeroOrLdSrc,
                                            bool MemcpyStrSrc,
                                            MachineFunction &MF) const {
   const Function *F = MF.getFunction();
 
   // See if we can use NEON instructions for this...
-  if (IsZeroVal &&
+  if (ZeroOrLdSrc &&
       Subtarget->hasNEON() &&
       !F->getFnAttributes().hasAttribute(Attributes::NoImplicitFloat)) {
     bool Fast;
@@ -9481,10 +9481,6 @@ EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size,
   return MVT::Other;
 }
 
-bool ARMTargetLowering::isLegalMemOpType(MVT VT) const {
-  return VT.isInteger() || VT == MVT::f64 || VT == MVT::v2f64;
-}
-
 bool ARMTargetLowering::isZExtFree(SDValue Val, EVT VT2) const {
   if (Val.getOpcode() != ISD::LOAD)
     return false;
index 3e78ae3b2d5371c6dc94395910a38de5519775f3..59e2fd333fdbe4b531902ccf4b59fdd9e3c4e59c 100644 (file)
@@ -292,17 +292,10 @@ namespace llvm {
 
     virtual EVT getOptimalMemOpType(uint64_t Size,
                                     unsigned DstAlign, unsigned SrcAlign,
-                                    bool IsZeroVal,
+                                    bool ZeroOrLdSrc,
                                     bool MemcpyStrSrc,
                                     MachineFunction &MF) const;
 
-    /// isLegalMemOpType - Returns true if it's legal to use load / store of the
-    /// specified type to expand memcpy / memset inline. This is mostly true
-    /// for legal types except for some special cases. For example, on X86
-    /// targets without SSE2 f64 load / store are done with fldl / fstpl which
-    /// also does type conversion.
-    virtual bool isLegalMemOpType(MVT VT) const;
-
     using TargetLowering::isZExtFree;
     virtual bool isZExtFree(SDValue Val, EVT VT2) const;
 
index 619ae077b30cd55cf29a32e7627d7974751cbf99..5edf82bc7f00e8bac359ab704e305fb2c8df14d5 100644 (file)
@@ -3476,7 +3476,7 @@ MipsTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
 }
 
 EVT MipsTargetLowering::getOptimalMemOpType(uint64_t Size, unsigned DstAlign,
-                                            unsigned SrcAlign, bool IsZeroVal,
+                                            unsigned SrcAlign, bool ZeroOrLdSrc,
                                             bool MemcpyStrSrc,
                                             MachineFunction &MF) const {
   if (Subtarget->hasMips64())
index 4b318dc16f7ff627b5e7030e12c8bb7b43a0b83a..46986613cb29426cb698a07c22f9d25ac0f05ac4 100644 (file)
@@ -362,7 +362,7 @@ namespace llvm {
     virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
 
     virtual EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign,
-                                    unsigned SrcAlign, bool IsZeroVal,
+                                    unsigned SrcAlign, bool ZeroOrLdSrc,
                                     bool MemcpyStrSrc,
                                     MachineFunction &MF) const;
 
index 51f2192371cc9a327faee84858496acd40ec1822..59aaf6db04b580a57495daf19348a503e89e3437 100644 (file)
@@ -6815,7 +6815,7 @@ PPCTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
 /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
 /// means there isn't a need to check it against alignment requirement,
 /// probably because the source does not need to be loaded. If
-/// 'IsZeroVal' is true, that means it's safe to return a
+/// 'ZeroOrLdSrc' is true, that means it's safe to return a
 /// non-scalar-integer type, e.g. empty string source, constant, or loaded
 /// from memory. 'MemcpyStrSrc' indicates whether the memcpy source is
 /// constant so it does not need to be loaded.
@@ -6823,7 +6823,7 @@ PPCTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
 /// target-independent logic.
 EVT PPCTargetLowering::getOptimalMemOpType(uint64_t Size,
                                            unsigned DstAlign, unsigned SrcAlign,
-                                           bool IsZeroVal,
+                                           bool ZeroOrLdSrc,
                                            bool MemcpyStrSrc,
                                            MachineFunction &MF) const {
   if (this->PPCSubTarget.isPPC64()) {
index 9f15eb89d56ce6667fa9c4283468b68adac23711..a90118d3d04969e388a3ec0bb8240e19a8b5b2cf 100644 (file)
@@ -401,7 +401,7 @@ namespace llvm {
     /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
     /// means there isn't a need to check it against alignment requirement,
     /// probably because the source does not need to be loaded. If
-    /// 'IsZeroVal' is true, that means it's safe to return a
+    /// 'ZeroOrLdSrc' is true, that means it's safe to return a
     /// non-scalar-integer type, e.g. empty string source, constant, or loaded
     /// from memory. 'MemcpyStrSrc' indicates whether the memcpy source is
     /// constant so it does not need to be loaded.
@@ -409,7 +409,7 @@ namespace llvm {
     /// target-independent logic.
     virtual EVT
     getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign,
-                        bool IsZeroVal, bool MemcpyStrSrc,
+                        bool ZeroOrLdSrc, bool MemcpyStrSrc,
                         MachineFunction &MF) const;
 
     /// isFMAFasterThanMulAndAdd - Return true if an FMA operation is faster than
index 800c2012df52d78aff84a14a04a694ce295cba75..f87d1fcb88c86ea4ae111a17ed9d6612406d76a7 100644 (file)
@@ -1370,7 +1370,7 @@ unsigned X86TargetLowering::getByValTypeAlignment(Type *Ty) const {
 /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
 /// means there isn't a need to check it against alignment requirement,
 /// probably because the source does not need to be loaded. If
-/// 'IsZeroVal' is true, that means it's safe to return a
+/// 'ZeroOrLdSrc' is true, that means it's safe to return a
 /// non-scalar-integer type, e.g. empty string source, constant, or loaded
 /// from memory. 'MemcpyStrSrc' indicates whether the memcpy source is
 /// constant so it does not need to be loaded.
@@ -1379,11 +1379,11 @@ unsigned X86TargetLowering::getByValTypeAlignment(Type *Ty) const {
 EVT
 X86TargetLowering::getOptimalMemOpType(uint64_t Size,
                                        unsigned DstAlign, unsigned SrcAlign,
-                                       bool IsZeroVal,
+                                       bool ZeroOrLdSrc,
                                        bool MemcpyStrSrc,
                                        MachineFunction &MF) const {
   const Function *F = MF.getFunction();
-  if (IsZeroVal &&
+  if (ZeroOrLdSrc &&
       !F->getFnAttributes().hasAttribute(Attributes::NoImplicitFloat)) {
     if (Size >= 16 &&
         (Subtarget->isUnalignedMemAccessFast() ||
@@ -1412,12 +1412,12 @@ X86TargetLowering::getOptimalMemOpType(uint64_t Size,
   return MVT::i32;
 }
 
-bool X86TargetLowering::isLegalMemOpType(MVT VT) const {
+bool X86TargetLowering::isSafeMemOpType(MVT VT) const {
   if (VT == MVT::f32)
     return X86ScalarSSEf32;
   else if (VT == MVT::f64)
     return X86ScalarSSEf64;
-  return VT.isInteger();
+  return true;
 }
 
 bool
index 9d22da1dd9039ca2414ad23f907ea6474b57801a..601ed2b12009afef41aae3327159f2024d575ab9 100644 (file)
@@ -495,7 +495,7 @@ namespace llvm {
     /// alignment can satisfy any constraint. Similarly if SrcAlign is zero it
     /// means there isn't a need to check it against alignment requirement,
     /// probably because the source does not need to be loaded. If
-    /// 'IsZeroVal' is true, that means it's safe to return a
+    /// 'ZeroOrLdSrc' is true, that means it's safe to return a
     /// non-scalar-integer type, e.g. empty string source, constant, or loaded
     /// from memory. 'MemcpyStrSrc' indicates whether the memcpy source is
     /// constant so it does not need to be loaded.
@@ -503,15 +503,16 @@ namespace llvm {
     /// target-independent logic.
     virtual EVT
     getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign,
-                        bool IsZeroVal, bool MemcpyStrSrc,
+                        bool ZeroOrLdSrc, bool MemcpyStrSrc,
                         MachineFunction &MF) const;
 
-    /// isLegalMemOpType - Returns true if it's legal to use load / store of the
+    /// isSafeMemOpType - Returns true if it's safe to use load / store of the
     /// specified type to expand memcpy / memset inline. This is mostly true
-    /// for legal types except for some special cases. For example, on X86
+    /// for all types except for some special cases. For example, on X86
     /// targets without SSE2 f64 load / store are done with fldl / fstpl which
-    /// also does type conversion.
-    virtual bool isLegalMemOpType(MVT VT) const;
+    /// also does type conversion. Note the specified type doesn't have to be
+    /// legal as the hook is used before type legalization.
+    virtual bool isSafeMemOpType(MVT VT) const;
 
     /// allowsUnalignedMemoryAccesses - Returns true if the target allows
     /// unaligned memory accesses. of the specified type. Returns whether it