<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - [LV] Vectorize loops with store to uniform addresses as profitability rather than legality check"
href="https://bugs.llvm.org/show_bug.cgi?id=38546">38546</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[LV] Vectorize loops with store to uniform addresses as profitability rather than legality check
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Loop Optimizer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>anna@azul.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Currently in the loop vectorizer, we prevent vectorization when we're storing
to a uniform address (loop invariant address).
It could be the case that for some reason store promotion in LICM didn't kick
in, but vectorizing stores to uniform addresses should be a cost model decision
right?
I think the vectorization of uniform stores should be a profitability check and
not a legality check. Is there something I'm missing here?
Today we do not vectorize a loop that contains either of the following:
1. Loop varying value stored into a loop invariant address (uniform stores)
2. Loop invariant value stored into a loop invariant address
Consider this example where we're storing the IV into a loop invariant address.
If I have this diff [A] and force-vectorize, we will vectorize the loop and the
store is a pattern of "extractelement + store", i.e. a scalarized store. Note
that with avx512 support, this just becomes a masked store, rather than a
extractelement + store.
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define i32 @consecutive_ptr_forward(i32* %a, i64 %n, i32* %b) {
entry:
br label %for.body
for.body: ; preds = %for.body, %entry
%i = phi i64 [ %i.next, %for.body ], [ 0, %entry ]
%tmp0 = phi i32 [ %tmp3, %for.body ], [ 0, %entry ]
%tmp1 = getelementptr inbounds i32, i32* %b, i64 %i
%tmp2 = load i32, i32* %tmp1, align 8
%tmp3 = add i32 %tmp0, %tmp2
%i.trunc = trunc i64 %i to i32
store i32 %i.trunc, i32* %a
%i.next = add nuw nsw i64 %i, 1
%cond = icmp slt i64 %i.next, %n
br i1 %cond, label %for.body, label %for.end
for.end: ; preds = %for.body
%tmp4 = phi i32 [ %tmp3, %for.body ]
ret i32 %tmp4
}
[A] Diff allowing vectorization to uniform stores
--- a/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
+++ b/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
@@ -754,7 +754,7 @@ bool LoopVectorizationLegality::canVectorizeMemory() {
if (!LAI->canVectorizeMemory())
return false;
- if (LAI->hasStoreToLoopInvariantAddress()) {
+ if (false && LAI->hasStoreToLoopInvariantAddress()) {
ORE->emit(createMissedAnalysis("CantVectorizeStoreToLoopInvariantAddress")
<< "write to a loop invariant address could not be vectorized");
LLVM_DEBUG(dbgs() << "LV: We don't allow storing to uniform addresses\n");</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>