-
Notifications
You must be signed in to change notification settings - Fork 787
[sycl-post-link] Add handling for zero-initialized array constants #5321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When a specialization constant, wich is an array, is defined in the IR as zeroinitializer, the corresponding llvm::Constant object has no operands and a zero constant of arbitrary type must be created for each array element.
/verify with intel/llvm-test-suite#747 |
Could you please also attach LIT test? |
The test is needed to proceed with the change. Fix itself LGTM
/verify with intel/llvm-test-suite#747 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test is OK, but some improvements are welcome to simplify it.
llvm/test/tools/sycl-post-link/spec-constants/SYCL-2020-zeroinitializer-array-of-arrays.ll
Outdated
Show resolved
Hide resolved
attributes #0 = { convergent mustprogress norecurse "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="spec-constant-convolution-test.cpp" "uniform-work-group-size"="true" } | ||
attributes #1 = { argmemonly nofree nosync nounwind willreturn } | ||
attributes #2 = { convergent norecurse "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #3 = { argmemonly nofree nounwind willreturn } | ||
attributes #4 = { convergent mustprogress norecurse "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #5 = { convergent inlinehint mustprogress norecurse "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #6 = { convergent norecurse nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #7 = { convergent mustprogress norecurse nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #8 = { argmemonly nofree nounwind willreturn writeonly } | ||
attributes #9 = { convergent inlinehint norecurse nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #10 = { convergent "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } | ||
attributes #11 = { convergent mustprogress norecurse "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="C:/Users/psamolys/Dev/sycl/libdevice/fallback-cassert.cpp" } | ||
attributes #12 = { nounwind } | ||
attributes #13 = { convergent } | ||
attributes #14 = { convergent nounwind } | ||
|
||
!llvm.dependent-libraries = !{!0, !0, !0} | ||
!opencl.spir.version = !{!1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1, !1} | ||
!spirv.Source = !{!2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2} | ||
!llvm.ident = !{!3, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4, !4} | ||
!llvm.module.flags = !{!5, !6} | ||
|
||
!0 = !{!"libcpmt"} | ||
!1 = !{i32 1, i32 2} | ||
!2 = !{i32 4, i32 100000} | ||
!3 = !{!"clang version 14.0.0 (https://github.com/intel/llvm.git bb0055ccd006e861d781dc6332df658364590350)"} | ||
!4 = !{!"clang version 14.0.0 (https://github.com/intel/llvm.git 23e180bce8024817348ea07b1f5eefe15c7ace32)"} | ||
!5 = !{i32 1, !"wchar_size", i32 2} | ||
!6 = !{i32 7, !"frame-pointer", i32 2} | ||
!7 = !{i32 -1, i32 -1, i32 -1, i32 -1} | ||
!8 = !{!9, !9, i64 0} | ||
!9 = !{!"any pointer", !10, i64 0} | ||
!10 = !{!"omnipotent char", !11, i64 0} | ||
!11 = !{!"Simple C++ TBAA"} | ||
!12 = !{!10, !10, i64 0} | ||
!13 = !{!14, !14, i64 0} | ||
!14 = !{!"int", !10, i64 0} | ||
!15 = !{!16, !16, i64 0} | ||
!16 = !{!"long long", !10, i64 0} | ||
!17 = distinct !{!17, !18, !19} | ||
!18 = !{!"llvm.loop.mustprogress"} | ||
!19 = !{!"llvm.loop.unroll.enable"} | ||
!20 = !{i32 -1} | ||
!21 = !{i64 0, i64 8, !8} | ||
!22 = !{!23, !9, i64 0} | ||
!23 = !{!"_ZTSN2cl4sycl14kernel_handlerE", !9, i64 0} | ||
!24 = !{!25, !14, i64 0} | ||
!25 = !{!"_ZTS14AssertHappened", !14, i64 0, !10, i64 4, !10, i64 261, !10, i64 518, !14, i64 648, !16, i64 656, !16, i64 664, !16, i64 672, !16, i64 680, !16, i64 688, !16, i64 696} | ||
!26 = distinct !{!26, !18} | ||
!27 = !{i64 0, i64 4, !13, i64 4, i64 257, !12, i64 261, i64 257, !12, i64 518, i64 129, !12, i64 648, i64 4, !13, i64 656, i64 8, !15, i64 664, i64 8, !15, i64 672, i64 8, !15, i64 680, i64 8, !15, i64 688, i64 8, !15, i64 696, i64 8, !15} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest simplifying the test a bit - many of these metadata and attributes are not needed to check spec constants instructions.
And it'd be nice to remove unused type definitions at the beginning of the test (e.g., %"struct.cl::sycl::detail::AssertHappened"
), it'll make the test more "unit". Also you can remove some unrelated instructions from the test function itself (like @llvm.lifetime
intrinsic) - they should not affect the tested change).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vmaksimo Thank you for the suggestions. I've simplified the test a bit.
/verify with intel/llvm-test-suite#747 |
llvm/test/tools/sycl-post-link/spec-constants/SYCL-2020-zeroinitializer-array-of-arrays.ll
Outdated
Show resolved
Hide resolved
llvm/test/tools/sycl-post-link/spec-constants/SYCL-2020-zeroinitializer-array-of-arrays.ll
Outdated
Show resolved
Hide resolved
llvm/test/tools/sycl-post-link/spec-constants/SYCL-2020-zeroinitializer-array-of-arrays.ll
Outdated
Show resolved
Hide resolved
llvm/test/tools/sycl-post-link/spec-constants/SYCL-2020-zeroinitializer-array-of-arrays.ll
Outdated
Show resolved
Hide resolved
Signed-off-by: Pavel Samolysov <[email protected]> Co-authored-by: Mikhail Lychkov <[email protected]>
Also a check that the expected .prop file has been generated and contains the definitions of the specialization constants has been added.
To make processing constants with different types more robust, dynamic casting of the constant itself (dyn_cast<ConstantType>(C)) should be used instead of casting the constant's type since the type can be incosistent with the constant behavior, for example not every constant with the type equals to ArrayType has any components (the zeroinitializer has not).
I've pushed a commit that replaces dynamic casts for the constant's types with dynamic casts to the constant's subtypes, I believe this should make the code more robust. Also, an additional case is used to check for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better. Thanks.
Also some local variables were inlined into function calls. Signed-off-by: Pavel Samolysov <[email protected]> Co-authored-by: Alexey Bader <[email protected]>
I've changed the description to make it clearer and describe all the changes in the PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that test RUN
lines could be cleaned up a bit
llvm/test/tools/sycl-post-link/spec-constants/SYCL-2020-zeroinitializer-array-of-arrays.ll
Outdated
Show resolved
Hide resolved
/verify with intel/llvm-test-suite#747 |
/verify with intel/llvm-test-suite#747 |
I would like to test the |
/verify with intel/llvm-test-suite#747 |
1 similar comment
/verify with intel/llvm-test-suite#747 |
The problem is the following, when the getOperand method is invoked for a
zeroinitializer array: C->getOperand(i), the assert from User.h was triggered:
This is because zeroinitializer has no operands. The problem occurs only when
the specialization constant was not initialized directly in the point of definition.
When a specialization constant is defined in the IR as zeroinitializer, its default
value is just an array of zeros of the arbitrary size. No recursive calls of the
collectCompositeElementsDefaultValuesRecursive function is required in the case.
Also, to make processing constants with different types more robust, dynamic
casting of the constant itself (dyn_cast(C)) should be used
instead of casting the constant's type since the type can be inconsistent with
the constant behavior, for example not every constant with the type equals to
ArrayType has any components (the zeroinitializer has not).