[PATCH] D12853: Introduce !value.align metadata for load instruction

Artur Pilipenko via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 28 10:43:00 PDT 2015


This revision was automatically updated to reflect the committed changes.
Closed by commit rL248721: Introduce !align metadata for load instruction (authored by apilipenko).

Changed prior to commit:
  http://reviews.llvm.org/D12853?vs=35660&id=35891#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D12853

Files:
  llvm/trunk/docs/LangRef.rst
  llvm/trunk/include/llvm/IR/LLVMContext.h
  llvm/trunk/lib/Analysis/ValueTracking.cpp
  llvm/trunk/lib/IR/LLVMContext.cpp
  llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll

Index: llvm/trunk/docs/LangRef.rst
===================================================================
--- llvm/trunk/docs/LangRef.rst
+++ llvm/trunk/docs/LangRef.rst
@@ -6860,10 +6860,11 @@
 
 ::
 
-      <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.load !<index>][, !invariant.group !<index>][, !nonnull !<index>][, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>]
+      <result> = load [volatile] <ty>, <ty>* <pointer>[, align <alignment>][, !nontemporal !<index>][, !invariant.load !<index>][, !invariant.group !<index>][, !nonnull !<index>][, !dereferenceable !<deref_bytes_node>][, !dereferenceable_or_null !<deref_bytes_node>][, !align !<align_node>]
       <result> = load atomic [volatile] <ty>* <pointer> [singlethread] <ordering>, align <alignment> [, !invariant.group !<index>]
       !<index> = !{ i32 1 }
       !<deref_bytes_node> = !{i64 <dereferenceable_bytes>}
+      !<align_node> = !{ i64 <value_alignment> }
 
 Overview:
 """""""""
@@ -6948,6 +6949,14 @@
 attribute on parameters and return values. This metadata can only be applied
 to loads of a pointer type.
 
+The optional ``!align`` metadata must reference a single metadata name
+``<align_node>`` corresponding to a metadata node with one ``i64`` entry.
+The existence of the ``!align`` metadata on the instruction tells the
+optimizer that the value loaded is known to be aligned to a boundary specified
+by the integer value in the metadata node. The alignment must be a power of 2.
+This is analogous to the ''align'' attribute on parameters and return values.
+This metadata can only be applied to loads of a pointer type.
+
 Semantics:
 """"""""""
 
Index: llvm/trunk/include/llvm/IR/LLVMContext.h
===================================================================
--- llvm/trunk/include/llvm/IR/LLVMContext.h
+++ llvm/trunk/include/llvm/IR/LLVMContext.h
@@ -63,7 +63,8 @@
     MD_dereferenceable_or_null = 13, // "dereferenceable_or_null"
     MD_make_implicit = 14, // "make.implicit"
     MD_unpredictable = 15, // "unpredictable"
-    MD_invariant_group = 16 // "invariant.group"
+    MD_invariant_group = 16, // "invariant.group"
+    MD_align = 17 // "align"
   };
 
   /// getMDKindID - Return a unique non-zero ID for the specified metadata kind.
Index: llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll
===================================================================
--- llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll
+++ llvm/trunk/test/Analysis/ValueTracking/memory-dereferenceable.ll
@@ -122,6 +122,14 @@
     %load24 = load i32, i32* %deref_return, align 16
     %load25 = load i32, i32* %deref_and_aligned_return, align 16
 
+    ; Load from a dereferenceable and aligned load
+; CHECK: %d4_unaligned_load{{.*}}(unaligned)
+; CHECK: %d4_aligned_load{{.*}}(aligned)
+    %d4_unaligned_load = load i32*, i32** @globali32ptr, !dereferenceable !0
+    %d4_aligned_load = load i32*, i32** @globali32ptr, !dereferenceable !0, !align !{i64 16}
+    %load26 = load i32, i32* %d4_unaligned_load, align 16
+    %load27 = load i32, i32* %d4_aligned_load, align 16
+
     ret void
 }
 
Index: llvm/trunk/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp
@@ -2979,6 +2979,11 @@
     BaseAlign = A->getParamAlignment();
   else if (auto CS = ImmutableCallSite(Base))
     BaseAlign = CS.getAttributes().getParamAlignment(AttributeSet::ReturnIndex);
+  else if (const LoadInst *LI = dyn_cast<LoadInst>(Base))
+    if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
+      ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
+      BaseAlign = CI->getLimitedValue();
+    }
 
   if (!BaseAlign) {
     Type *Ty = Base->getType()->getPointerElementType();
Index: llvm/trunk/lib/IR/LLVMContext.cpp
===================================================================
--- llvm/trunk/lib/IR/LLVMContext.cpp
+++ llvm/trunk/lib/IR/LLVMContext.cpp
@@ -123,6 +123,10 @@
          "invariant.group kind id drifted");
   (void)InvariantGroupId;
 
+  // Create the 'align' metadata kind.
+  unsigned AlignID = getMDKindID("align");
+  assert(AlignID == MD_align && "align kind id drifted");
+  (void)AlignID;
 }
 LLVMContext::~LLVMContext() { delete pImpl; }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12853.35891.patch
Type: text/x-patch
Size: 4434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150928/37e9edf7/attachment.bin>


More information about the llvm-commits mailing list