[X86] Create mergeable constant pool entries for AVX
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 22 Feb 2016 22:23:11 +0000 (22:23 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 22 Feb 2016 22:23:11 +0000 (22:23 +0000)
We supported creating mergeable constant pool entries for smaller
constants but not for 32-byte AVX constants.

llvm-svn: 261584

llvm/include/llvm/MC/MCObjectFileInfo.h
llvm/include/llvm/MC/SectionKind.h
llvm/lib/CodeGen/MachineFunction.cpp
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/MC/MCObjectFileInfo.cpp
llvm/lib/Target/TargetLoweringObjectFile.cpp
llvm/lib/Target/X86/X86TargetObjectFile.cpp
llvm/test/CodeGen/X86/global-sections.ll
llvm/test/CodeGen/X86/win_cst_pool.ll

index f8346f22a23570269578b446813b14a6d00d8371..d0e34e63ff8226e53fcc4349995cfb62c365e8af 100644 (file)
@@ -159,6 +159,7 @@ protected:
   MCSection *MergeableConst4Section;
   MCSection *MergeableConst8Section;
   MCSection *MergeableConst16Section;
+  MCSection *MergeableConst32Section;
 
   // MachO specific sections.
 
@@ -298,6 +299,9 @@ public:
   const MCSection *getMergeableConst16Section() const {
     return MergeableConst16Section;
   }
+  const MCSection *getMergeableConst32Section() const {
+    return MergeableConst32Section;
+  }
 
   // MachO specific sections.
   const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
index b09b93cfc377a429018d7e97555331a4bd2ee59f..02fb22623cf755e055a69e7b383b7e0f2b76eb03 100644 (file)
@@ -63,6 +63,10 @@ class SectionKind {
             /// for example, vectors.
             MergeableConst16,
 
+            /// MergeableConst32 - This is a section used by 32-byte constants,
+            /// for example, vectors.
+            MergeableConst32,
+
     /// Writeable - This is the base of all segments that need to be written
     /// to during program runtime.
 
@@ -125,11 +129,12 @@ public:
 
   bool isMergeableConst() const {
     return K == MergeableConst4 || K == MergeableConst8 ||
-           K == MergeableConst16;
+           K == MergeableConst16 || K == MergeableConst32;
   }
   bool isMergeableConst4() const { return K == MergeableConst4; }
   bool isMergeableConst8() const { return K == MergeableConst8; }
   bool isMergeableConst16() const { return K == MergeableConst16; }
+  bool isMergeableConst32() const { return K == MergeableConst32; }
 
   bool isWriteable() const {
     return isThreadLocal() || isGlobalWriteableData();
@@ -180,6 +185,7 @@ public:
   static SectionKind getMergeableConst4() { return get(MergeableConst4); }
   static SectionKind getMergeableConst8() { return get(MergeableConst8); }
   static SectionKind getMergeableConst16() { return get(MergeableConst16); }
+  static SectionKind getMergeableConst32() { return get(MergeableConst32); }
   static SectionKind getThreadBSS() { return get(ThreadBSS); }
   static SectionKind getThreadData() { return get(ThreadData); }
   static SectionKind getBSS() { return get(BSS); }
index a2823500fa6729d950667668743b234e047926ed..e93299fccb20104d38c6c970b98a14034c39bd8c 100644 (file)
@@ -852,6 +852,8 @@ MachineConstantPoolEntry::getSectionKind(const DataLayout *DL) const {
     return SectionKind::getMergeableConst8();
   case 16:
     return SectionKind::getMergeableConst16();
+  case 32:
+    return SectionKind::getMergeableConst32();
   default:
     return SectionKind::getReadOnly();
   }
index 624eaec73b48e02a8bbfacc4add1649d2ad9bd6c..4229741cf5ae151b3ee6572f6ad877c4add35491 100644 (file)
@@ -270,9 +270,11 @@ selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV,
       EntrySize = 4;
     } else if (Kind.isMergeableConst8()) {
       EntrySize = 8;
-    } else {
-      assert(Kind.isMergeableConst16() && "unknown data width");
+    } else if (Kind.isMergeableConst16()) {
       EntrySize = 16;
+    } else {
+      assert(Kind.isMergeableConst32() && "unknown data width");
+      EntrySize = 32;
     }
   }
 
@@ -375,6 +377,8 @@ MCSection *TargetLoweringObjectFileELF::getSectionForConstant(
     return MergeableConst8Section;
   if (Kind.isMergeableConst16() && MergeableConst16Section)
     return MergeableConst16Section;
+  if (Kind.isMergeableConst32() && MergeableConst32Section)
+    return MergeableConst32Section;
   if (Kind.isReadOnly())
     return ReadOnlySection;
 
index a3f9937f4104e96ef87d20e46ad5be5a98ddf74a..2948f69aee87d7f0ca27da09cc85515c21f00c29 100644 (file)
@@ -469,6 +469,10 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
       Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,
                          ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, "");
 
+  MergeableConst32Section =
+      Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,
+                         ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, "");
+
   StaticCtorSection = Ctx->getELFSection(".ctors", ELF::SHT_PROGBITS,
                                          ELF::SHF_ALLOC | ELF::SHF_WRITE);
 
index 3c04a214fadadbb269e9c22261859ff6df91f535..4169237aa309a1990e9a4b432259b8346256e1cd 100644 (file)
@@ -202,6 +202,7 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
       case 4:  return SectionKind::getMergeableConst4();
       case 8:  return SectionKind::getMergeableConst8();
       case 16: return SectionKind::getMergeableConst16();
+      case 32: return SectionKind::getMergeableConst32();
       default:
         return SectionKind::getReadOnly();
       }
index 0d37fcd1b437c9f3c62ab5ff5be270581b4985a7..e72f3a7a2e8ea247dbb775a1d1db36b05b4e8f8b 100644 (file)
@@ -176,6 +176,11 @@ MCSection *X86WindowsTargetObjectFile::getSectionForConstant(
         COMDATSymName = "__xmm@" + scalarConstantToHexString(C);
         Align = 16;
       }
+    } else if (Kind.isMergeableConst32()) {
+      if (Align <= 32) {
+        COMDATSymName = "__ymm@" + scalarConstantToHexString(C);
+        Align = 32;
+      }
     }
 
     if (!COMDATSymName.empty())
index a18b662625610f1f6495a9f3f743e8f99c383504..1401218da5f848ce010757ab145bf7f127027636 100644 (file)
@@ -298,3 +298,14 @@ bb7:
 
 ; WIN32-SECTIONS: .section      .rdata,"dr",one_only,_G15
 ; WIN32-SECTIONS: _G15:
+
+@G16 = unnamed_addr constant i256 0
+
+; LINUX: .section        .rodata.cst32,"aM",@progbits,32
+; LINUX: G16:
+
+; LINUX-SECTIONS: .section      .rodata.cst32,"aM",@progbits,32
+; LINUX-SECTIONS: G16:
+
+; WIN32-SECTIONS: .section      .rdata,"dr",one_only,_G16
+; WIN32-SECTIONS: _G16:
index 2856a08b54d80c17730de8503c39b5e087d6a429..a674d8c080af303a9c4592ce8bdac688d75eb912 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -mtriple=x86_64-win32 -mattr=sse2 | FileCheck %s
+; RUN: llc < %s -mtriple=x86_64-win32 -mattr=sse2 -mattr=avx | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-pc-windows-msvc"
 
@@ -77,3 +77,17 @@ define float @pr23966(i32 %a) {
 ; CHECK-NEXT: __real@bf8000003f800000:
 ; CHECK-NEXT:         .long   1065353216
 ; CHECK-NEXT:         .long   3212836864
+
+define <4 x i64> @ymm() {
+entry:
+  ret <4 x i64> <i64 8589934593, i64 17179869187, i64 8589934593, i64 17179869187>
+}
+
+; CHECK:       .globl  __ymm@0000000400000003000000020000000100000004000000030000000200000001
+; CHECK:       .section        .rdata,"dr",discard,__ymm@0000000400000003000000020000000100000004000000030000000200000001
+; CHECK:       .p2align        5
+; CHECK: __ymm@0000000400000003000000020000000100000004000000030000000200000001:
+; CHECK:       .quad   8589934593              # 0x200000001
+; CHECK:       .quad   17179869187             # 0x400000003
+; CHECK:       .quad   8589934593              # 0x200000001
+; CHECK:       .quad   17179869187