[llvm] r277494 - [Hexagon] Improvements to address mode checks in TargetLowering

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 2 11:34:31 PDT 2016


Author: kparzysz
Date: Tue Aug  2 13:34:31 2016
New Revision: 277494

URL: http://llvm.org/viewvc/llvm-project?rev=277494&view=rev
Log:
[Hexagon] Improvements to address mode checks in TargetLowering

- Implement getOptimalMemOpType.
- Check BaseOffset in isLegalAddressingMode.

Modified:
    llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp
    llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h

Modified: llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp?rev=277494&r1=277493&r2=277494&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.cpp Tue Aug  2 13:34:31 2016
@@ -3055,8 +3055,12 @@ bool HexagonTargetLowering::isFPImmLegal
 bool HexagonTargetLowering::isLegalAddressingMode(const DataLayout &DL,
                                                   const AddrMode &AM, Type *Ty,
                                                   unsigned AS) const {
-  // Allows a signed-extended 11-bit immediate field.
-  if (AM.BaseOffs <= -(1LL << 13) || AM.BaseOffs >= (1LL << 13)-1)
+  unsigned A = DL.getABITypeAlignment(Ty);
+  // The base offset must be a multiple of the alignment.
+  if ((AM.BaseOffs % A) != 0)
+    return false;
+  // The shifted offset must fit in 11 bits.
+  if (!isInt<11>(AM.BaseOffs >> Log2_32(A)))
     return false;
 
   // No global is ever allowed as a base.
@@ -3139,6 +3143,35 @@ bool HexagonTargetLowering::IsEligibleFo
   return true;
 }
 
+/// Returns the target specific optimal type for load and store operations as
+/// a result of memset, memcpy, and memmove lowering.
+///
+/// If DstAlign is zero that means it's safe to destination 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 'IsMemset' is true, that means it's
+/// expanding a memset. If 'ZeroMemset' is true, that means it's a memset of
+/// zero. 'MemcpyStrSrc' indicates whether the memcpy source is constant so it
+/// does not need to be loaded.  It returns EVT::Other if the type should be
+/// determined using generic target-independent logic.
+EVT HexagonTargetLowering::getOptimalMemOpType(uint64_t Size,
+      unsigned DstAlign, unsigned SrcAlign, bool IsMemset, bool ZeroMemset,
+      bool MemcpyStrSrc, MachineFunction &MF) const {
+
+  auto Aligned = [](unsigned GivenA, unsigned MinA) -> bool {
+    return (GivenA % MinA) == 0;
+  };
+
+  if (Size >= 8 && Aligned(DstAlign, 8) && (IsMemset || Aligned(SrcAlign, 8)))
+    return MVT::i64;
+  if (Size >= 4 && Aligned(DstAlign, 4) && (IsMemset || Aligned(SrcAlign, 4)))
+    return MVT::i32;
+  if (Size >= 2 && Aligned(DstAlign, 2) && (IsMemset || Aligned(SrcAlign, 2)))
+    return MVT::i16;
+
+  return MVT::Other;
+}
+
 // Return true when the given node fits in a positive half word.
 bool llvm::isPositiveHalfWord(SDNode *N) {
   ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N);

Modified: llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h?rev=277494&r1=277493&r2=277494&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h (original)
+++ llvm/trunk/lib/Target/Hexagon/HexagonISelLowering.h Tue Aug  2 13:34:31 2016
@@ -247,6 +247,10 @@ bool isPositiveHalfWord(SDNode *N);
     /// the immediate into a register.
     bool isLegalICmpImmediate(int64_t Imm) const override;
 
+    EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign,
+        unsigned SrcAlign, bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc,
+        MachineFunction &MF) const override;
+
     bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace,
         unsigned Align, bool *Fast) const override;
 




More information about the llvm-commits mailing list