Files
clang-p2996/llvm/test/Transforms/Inline/parallel-loop-md.ll
Michael Kruse 978ba61536 Introduce llvm.loop.parallel_accesses and llvm.access.group metadata.
The current llvm.mem.parallel_loop_access metadata has a problem in that
it uses LoopIDs. LoopID unfortunately is not loop identifier. It is
neither unique (there's even a regression test assigning the some LoopID
to multiple loops; can otherwise happen if passes such as LoopVersioning
make copies of entire loops) nor persistent (every time a property is
removed/added from a LoopID's MDNode, it will also receive a new LoopID;
this happens e.g. when calling Loop::setLoopAlreadyUnrolled()).
Since most loop transformation passes change the loop attributes (even
if it just to mark that a loop should not be processed again as
llvm.loop.isvectorized does, for the versioned and unversioned loop),
the parallel access information is lost for any subsequent pass.

This patch unlinks LoopIDs and parallel accesses.
llvm.mem.parallel_loop_access metadata on instruction is replaced by
llvm.access.group metadata. llvm.access.group points to a distinct
MDNode with no operands (avoiding the problem to ever need to add/remove
operands), called "access group". Alternatively, it can point to a list
of access groups. The LoopID then has an attribute
llvm.loop.parallel_accesses with all the access groups that are parallel
(no dependencies carries by this loop).

This intentionally avoid any kind of "ID". Loops that are clones/have
their attributes modifies retain the llvm.loop.parallel_accesses
attribute. Access instructions that a cloned point to the same access
group. It is not necessary for each access to have it's own "ID" MDNode,
but those memory access instructions with the same behavior can be
grouped together.

The behavior of llvm.mem.parallel_loop_access is not changed by this
patch, but should be considered deprecated.

Differential Revision: https://reviews.llvm.org/D52116

llvm-svn: 349725
2018-12-20 04:58:07 +00:00

59 lines
2.1 KiB
LLVM

; RUN: opt -S -inline < %s | FileCheck %s
; RUN: opt -S -passes='cgscc(inline)' < %s | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: norecurse nounwind uwtable
define void @Body(i32* nocapture %res, i32* nocapture readnone %c, i32* nocapture readonly %d, i32* nocapture readonly %p, i32 %i) #0 {
entry:
%idxprom = sext i32 %i to i64
%arrayidx = getelementptr inbounds i32, i32* %p, i64 %idxprom
%0 = load i32, i32* %arrayidx, align 4
%cmp = icmp eq i32 %0, 0
%arrayidx2 = getelementptr inbounds i32, i32* %res, i64 %idxprom
%1 = load i32, i32* %arrayidx2, align 4
br i1 %cmp, label %cond.end, label %cond.false
cond.false: ; preds = %entry
%arrayidx6 = getelementptr inbounds i32, i32* %d, i64 %idxprom
%2 = load i32, i32* %arrayidx6, align 4
%add = add nsw i32 %2, %1
br label %cond.end
cond.end: ; preds = %entry, %cond.false
%cond = phi i32 [ %add, %cond.false ], [ %1, %entry ]
store i32 %cond, i32* %arrayidx2, align 4
ret void
}
; Function Attrs: nounwind uwtable
define void @Test(i32* %res, i32* %c, i32* %d, i32* %p, i32 %n) #1 {
entry:
br label %for.cond
for.cond: ; preds = %for.body, %entry
%i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
%cmp = icmp slt i32 %i.0, 1600
br i1 %cmp, label %for.body, label %for.end
for.body: ; preds = %for.cond
call void @Body(i32* %res, i32* undef, i32* %d, i32* %p, i32 %i.0), !llvm.access.group !0
%inc = add nsw i32 %i.0, 1
br label %for.cond, !llvm.loop !1
for.end: ; preds = %for.cond
ret void
}
; CHECK-LABEL: @Test
; CHECK: load i32,{{.*}}, !llvm.access.group !0
; CHECK: load i32,{{.*}}, !llvm.access.group !0
; CHECK: load i32,{{.*}}, !llvm.access.group !0
; CHECK: store i32{{.*}}, !llvm.access.group !0
; CHECK: br label %for.cond, !llvm.loop !1
attributes #0 = { norecurse nounwind uwtable }
!0 = distinct !{}
!1 = distinct !{!0, !{!"llvm.loop.parallel_accesses", !0}}