[cfe-dev] Vectorizer and buffer overlaps

Nicola Gigante nicola.gigante at gmail.com
Sat May 3 07:12:52 PDT 2014


Il giorno 03/mag/2014, alle ore 12:55, Renato Golin <renato.golin at linaro.org> ha scritto:

> On 2 May 2014 12:04, Nicola Gigante <nicola.gigante at gmail.com> wrote:
>> How can I inform the compiler that I know the buffer won’t overlap?
> 
> As Philip said, restrict should do the trick.
> 

Yes, of course. I'm sorry I've not mentioned it in my original email,
but I know about restrict, it's only that it's not supported in C++, and yes it
may be supported as an extension, but I'm interested in writing
compliant code.

> 
>> Inputs arrays are copied (unrealistic code)... Why does it check for overlaps?
> 
> The types are different but they're not obviously different
> (templates, lists of things), so it might just be that TBAA is not
> recognizing them as different types.
> 
> Have a look at the IR, search for TBAA metadata, you may find some clues.
> 

The TBAA metadata in the IR seems to be there, in the original code (which
is left in the IR for the remainder, so I think it's there from before the vectorizer
pass) marking that data1, data2 and result are indeed of different types,
but I don't know the internals so I may misunderstand. I've attached the IR
file with the original source in comments.

The relevant piece is:

%22 = getelementptr inbounds %class.wrapper* %data1, i64 %i.01, i32 0
%23 = load float* %22, align 4, !tbaa !4
%24 = getelementptr inbounds %class.wrapper.0* %data2, i64 %i.01, i32 0
%25 = load float* %24, align 4, !tbaa !9
%26 = fmul float %23, %25
%27 = getelementptr inbounds %class.wrapper.1* %result, i64 %i.01, i32 0
store float %26, float* %27, align 4, !tbaa !11

These are the metadata:
!0 = metadata !{metadata !"Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)"}
!1 = metadata !{metadata !1, metadata !2, metadata !3}
!2 = metadata !{metadata !"llvm.vectorizer.width", i32 1}
!3 = metadata !{metadata !"llvm.vectorizer.unroll", i32 1}
!4 = metadata !{metadata !5, metadata !6, i64 0}
!5 = metadata !{metadata !"_ZTS7wrapperIf8mass_tagE", metadata !6, i64 0}
!6 = metadata !{metadata !"float", metadata !7, i64 0}
!7 = metadata !{metadata !"omnipotent char", metadata !8, i64 0}
!8 = metadata !{metadata !"Simple C/C++ TBAA"}
!9 = metadata !{metadata !10, metadata !6, i64 0}
!10 = metadata !{metadata !"_ZTS7wrapperIf16acceleration_tagE", metadata !6, i64 0}
!11 = metadata !{metadata !6, metadata !6, i64 0}
!12 = metadata !{metadata !12, metadata !2, metadata !3}

metadata !4 indirectly contains wrapper<mass_tag>
and metadata !9 indirectly contains wrapper<acceleration_tag>
It seems that metadata !11 points only to "float", not to wrapper<force_tag>,
but I'm not very proficient in the internals of the TBAA pass, and I'm not 
sure how to interpret those data.

Any clue?

> 
>> So how do I inform the compiler that it doesn’t need che memcheck block?
> 
> In this case, the compiler should pick it up. While it doesn't, you
> may try restrict on them, too.
> 
> Have a look at the Bugzilla, if there isn't anything obviously
> reported for this problem, feel free to fill a new one.
> 

I'll do.

> Thanks,
> --renato


Thanks,
Nicola

-------------- next part --------------
A non-text attachment was scrubbed...
Name: prova.ll
Type: application/octet-stream
Size: 6299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140503/a0e6e68e/attachment.obj>


More information about the cfe-dev mailing list