| Issue |
60899
|
| Summary |
[LoopVectorizer] Loop fails to vectorize in presence of inttoptr casts.
|
| Labels |
loopoptim,
vectorization
|
| Assignees |
|
| Reporter |
danilaml
|
When there is `inttoptr` cast inside the loop the LoopVectorizer can produce especially bad code, probably because SCEV gives up and returns unknown when it sees such a cast.
This is surprising, considering the equivalent code with the cast moved out of the loop vectorizes just fine (or in this case, gets recognized as a memset). GCC has no issue with such pattern.
Example IR (compile with `opt -O3`):
```ll
define dso_local void @foo(i64 noundef %p, i64 noundef %n, i8 noundef signext %b) local_unnamed_addr #0 {
entry:
%cmp3 = icmp sgt i64 %n, 0
br i1 %cmp3, label %for.body, label %for.end
for.body: ; preds = %entry, %for.body
%i.04 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
%add = add nsw i64 %i.04, %p
%0 = inttoptr i64 %add to ptr
store i8 %b, ptr %0, align 1
%inc = add nuw nsw i64 %i.04, 1
%cmp = icmp slt i64 %inc, %n
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body, %entry
ret void
}
attributes #0 = { nofree noinline norecurse nosync nounwind memory(write, inaccessiblemem: none) uwtable "frame-pointer"="all""min-legal-vector-width"="0""no-trapping-math"="true""stack-protector-buffer-size"="8""target-cpu"="skylake""target-features"="+adx,+aes,+avx,+avx2,+bmi,+bmi2,+clflushopt,+crc32,+cx16,+cx8,+f16c,+fma,+fsgsbase,+fxsr,+invpcid,+lzcnt,+mmx,+movbe,+pclmul,+popcnt,+prfchw,+rdrnd,+rdseed,+sahf,+sgx,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsavec,+xsaveopt,+xsaves" }
```
Godbolt link for examples in C:
https://godbolt.org/z/rY4c1nex6
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs