[PATCH] D110235: [LoopVectorize] Support reductions that store intermediary result
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 18 03:44:10 PST 2021
fhahn added inline comments.
================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp:900
+ // of one of our reductions and is unconditional.
+ for (StoreInst *SI : LAI->getInvariantStores()) {
+ if (isRecurringInvariantStore(SI, &IsPredicated)) {
----------------
igor.kirillov wrote:
> fhahn wrote:
> > What about loads to the same address in the loop? At the moment, `LAA` cannot analyze dependences with invariant addresses. But if this limitation gets removed the code here may become incorrect, because it relies on this limitation IIUC?
> Loads from or stores to the same address in the loop? I'm sorry could you clarify what the problem is. As it is I don't understand the message.
The case I was thinking about was something like the snippet below, where we have a load of the invariant address in the loop (`%lv = load...` in the example below).
```
define void @reduc_store(i32* %dst, i32* readonly %src, i32* noalias %dst.2) {
entry:
%arrayidx = getelementptr inbounds i32, i32* %dst, i64 42
store i32 0, i32* %arrayidx, align 4
br label %for.body
for.body:
%0 = phi i32 [ 0, %entry ], [ %add, %for.body ]
%indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
%arrayidx1 = getelementptr inbounds i32, i32* %src, i64 %indvars.iv
%1 = load i32, i32* %arrayidx1, align 4
%add = add nsw i32 %0, %1
%lv = load i32, i32* %arrayidx
store i32 %add, i32* %arrayidx, align 4
%gep.dst.2 = getelementptr inbounds i32, i32* %dst.2, i64 %indvars.iv
store i32 %lv, i32* %gep.dst.2,
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
%exitcond = icmp eq i64 %indvars.iv.next, 1000
br i1 %exitcond, label %for.cond.cleanup, label %for.body
for.cond.cleanup:
ret void
}
```
================
Comment at: llvm/test/Transforms/LoopVectorize/reduction.ll:468
+; sum += src[i];
+; dst[42] = sum;
+; }
----------------
Could you add a brief textual explanation of what the test covers?
================
Comment at: llvm/test/Transforms/LoopVectorize/reduction.ll:482
+for.body:
+ %0 = phi i32 [ 0, %entry ], [ %add, %for.body ]
+ %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
----------------
perhaps rename to `%sum` or something like that, to make it a bit easier to read the test?
================
Comment at: llvm/test/Transforms/LoopVectorize/reduction.ll:487
+ %add = add nsw i32 %0, %1
+ store i32 %add, i32* %arrayidx, align 4
+ %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
----------------
The names for the 2 different GEPs in the tests are very similar. Could you rename them to make it easier to distinguish them (e.g. something like `%gep.src`/`%gep.dst`)..
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110235/new/
https://reviews.llvm.org/D110235
More information about the llvm-commits
mailing list