From 2c71fc8bb7f9c38d0ed1855efee601fa9dc0a45a Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Sun, 11 Sep 2016 01:39:08 +0000 Subject: [PATCH] Add handling of !invariant.load to PropagateMetadata. Summary: This will let e.g. the load/store vectorizer propagate this metadata appropriately. Reviewers: arsenm Subscribers: tra, jholewinski, hfinkel, mzolotukhin Differential Revision: https://reviews.llvm.org/D23479 llvm-svn: 281153 --- lib/Analysis/VectorUtils.cpp | 12 ++++++------ .../NVPTX/propagate-invariance-metadata.ll | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 test/Transforms/LoadStoreVectorizer/NVPTX/propagate-invariance-metadata.ll diff --git a/lib/Analysis/VectorUtils.cpp b/lib/Analysis/VectorUtils.cpp index 53e7153a350..5a51fd8a524 100644 --- a/lib/Analysis/VectorUtils.cpp +++ b/lib/Analysis/VectorUtils.cpp @@ -454,9 +454,10 @@ Instruction *llvm::propagateMetadata(Instruction *Inst, ArrayRef VL) { SmallVector, 4> Metadata; I0->getAllMetadataOtherThanDebugLoc(Metadata); - for (auto Kind : { LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope, - LLVMContext::MD_noalias, LLVMContext::MD_fpmath, - LLVMContext::MD_nontemporal }) { + for (auto Kind : + {LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope, + LLVMContext::MD_noalias, LLVMContext::MD_fpmath, + LLVMContext::MD_nontemporal, LLVMContext::MD_invariant_load}) { MDNode *MD = I0->getMetadata(Kind); for (int J = 1, E = VL.size(); MD && J != E; ++J) { @@ -469,13 +470,12 @@ Instruction *llvm::propagateMetadata(Instruction *Inst, ArrayRef VL) { case LLVMContext::MD_alias_scope: MD = MDNode::getMostGenericAliasScope(MD, IMD); break; - case LLVMContext::MD_noalias: - MD = MDNode::intersect(MD, IMD); - break; case LLVMContext::MD_fpmath: MD = MDNode::getMostGenericFPMath(MD, IMD); break; + case LLVMContext::MD_noalias: case LLVMContext::MD_nontemporal: + case LLVMContext::MD_invariant_load: MD = MDNode::intersect(MD, IMD); break; default: diff --git a/test/Transforms/LoadStoreVectorizer/NVPTX/propagate-invariance-metadata.ll b/test/Transforms/LoadStoreVectorizer/NVPTX/propagate-invariance-metadata.ll new file mode 100644 index 00000000000..ac0660e7833 --- /dev/null +++ b/test/Transforms/LoadStoreVectorizer/NVPTX/propagate-invariance-metadata.ll @@ -0,0 +1,17 @@ +; RUN: opt -load-store-vectorizer -march=nvptx64 -mcpu=sm_35 -S < %s | FileCheck %s + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64" +target triple = "nvptx64-nvidia-cuda" + +; CHECK-LABEL: @foo +define i32 @foo(i32* %ptr) { + %ptr1 = getelementptr i32, i32* %ptr, i32 1 + %p1 = addrspacecast i32* %ptr1 to i32 addrspace(1)* + ; CHECK: load <2 x i32>, <2 x i32>* %{{[0-9]+}}, align 8, !invariant.load !0 + %v0 = load i32, i32* %ptr, align 8, !invariant.load !0 + %v1 = load i32, i32* %ptr1, align 4, !invariant.load !0 + %sum = add i32 %v0, %v1 + ret i32 %sum +} + +!0 = !{}