[PATCH] D25512: [SDAG] Use ABI type alignment for constant pools when optimizing for size

James Molloy via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 12 05:11:22 PDT 2016


jmolloy created this revision.
jmolloy added reviewers: sanjoy, olista01, hfinkel.
jmolloy added a subscriber: llvm-commits.
jmolloy set the repository for this revision to rL LLVM.

SelectionDAG::getConstantPool will automatically determine an appropriate alignment if one is not specified. It does this by querying the type's preferred alignment. This can end up creating quite a lot of padding when the preferred alignment for vectors is 128.

In optimize-for-size mode, it makes sense to instead query the ABI type alignment which is often smaller and causes less padding.


Repository:
  rL LLVM

https://reviews.llvm.org/D25512

Files:
  lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  test/CodeGen/ARM/constantpool-align.ll


Index: test/CodeGen/ARM/constantpool-align.ll
===================================================================
--- /dev/null
+++ test/CodeGen/ARM/constantpool-align.ll
@@ -0,0 +1,19 @@
+; RUN: llc < %s | FileCheck %s
+target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
+target triple = "thumbv7-arm-none-eabi"
+
+; CHECK-LABEL: f:
+; CHECK: vld1.64 {{.*}}, [r1:128]
+; CHECK: .p2align 4
+define void @f(<4 x i32>* %p) {
+  store <4 x i32> <i32 -1, i32 0, i32 0, i32 -1>, <4 x i32>* %p, align 4
+  ret void 
+}
+
+; CHECK-LABEL: f_optsize:
+; CHECK: vld1.64 {{.*}}, [r1]
+; CHECK: .p2align 3
+define void @f_optsize(<4 x i32>* %p) optsize {
+  store <4 x i32> <i32 -1, i32 0, i32 0, i32 -1>, <4 x i32>* %p, align 4
+  ret void 
+}
Index: lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -1315,7 +1315,9 @@
   assert((TargetFlags == 0 || isTarget) &&
          "Cannot set target flags on target-independent globals");
   if (Alignment == 0)
-    Alignment = getDataLayout().getPrefTypeAlignment(C->getType());
+    Alignment = MF->getFunction()->optForSize()
+                    ? getDataLayout().getABITypeAlignment(C->getType())
+                    : getDataLayout().getPrefTypeAlignment(C->getType());
   unsigned Opc = isTarget ? ISD::TargetConstantPool : ISD::ConstantPool;
   FoldingSetNodeID ID;
   AddNodeIDNode(ID, Opc, getVTList(VT), None);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25512.74362.patch
Type: text/x-patch
Size: 1530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161012/b465811c/attachment.bin>


More information about the llvm-commits mailing list