[clang] [llvm] [LV][LAA] Vectorize math lib calls with mem write-only attribute (PR #78432)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue May 14 08:11:51 PDT 2024
================
@@ -2477,6 +2493,15 @@ void LoopAccessInfo::analyzeLoop(AAResults *AA, LoopInfo *LI,
// Save 'store' instructions. Abort if other instructions write to memory.
if (I.mayWriteToMemory()) {
+ // We can safety handle math functions that have vectorized
+ // counterparts and have the memory write-only attribute set.
----------------
fhahn wrote:
I am not sure the reasoning here is correct; the writes could still alias with other accesses,
e.g. something like below would be considered as safe, but `%out2` could overlap with `%in` in a way that results in a backwards dependence at runtime.
```
define void @frexp_f64(ptr %in, ptr %out1, ptr %out2, i32 %N) {
entry:
%cmp4 = icmp sgt i32 %N, 0
br i1 %cmp4, label %for.body.preheader, label %for.cond.cleanup
for.body.preheader:
%wide.trip.count = zext nneg i32 %N to i64
br label %for.body
for.cond.cleanup:
ret void
for.body:
%indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
%arrayidx = getelementptr inbounds double, ptr %in, i64 %indvars.iv
%0 = load double, ptr %arrayidx, align 8
%add.ptr = getelementptr inbounds i32, ptr %out2, i64 %indvars.iv
%call = tail call double @frexp(double noundef %0, ptr noundef %add.ptr)
store double %call, ptr %arrayidx, align 8
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
%exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
}
declare double @frexp(double, ptr) #1
attributes #1 = { memory(argmem: write) }
```
https://github.com/llvm/llvm-project/pull/78432
More information about the llvm-commits
mailing list