Skip to content

[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

Merged
merged 11 commits into from Jan 20, 2022
Merged

[sycl-post-link] Add handling for zero-initialized array constants #5321

merged 11 commits into from Jan 20, 2022

Conversation

ghost
Copy link

@ghost ghost commented Jan 17, 2022

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:

assert(i < NumUserOperands && "getOperand() out of range!");

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).

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.
@ghost ghost requested review from AlexeySachkov and vmaksimo January 17, 2022 13:13
@ghost ghost self-requested a review as a code owner January 17, 2022 13:13
@ghost
Copy link
Author

ghost commented Jan 17, 2022

/verify with intel/llvm-test-suite#747

@mlychkov
Copy link
Contributor

Could you please also attach LIT test?

vmaksimo
vmaksimo previously approved these changes Jan 17, 2022
@vmaksimo vmaksimo dismissed their stale review January 17, 2022 13:42

The test is needed to proceed with the change. Fix itself LGTM

@ghost
Copy link
Author

ghost commented Jan 17, 2022

@vmaksimo @mlychkov Thank you for the comments, I'm working on the test.

@ghost
Copy link
Author

ghost commented Jan 17, 2022

@vmaksimo @mlychkov The lit test has been added.

@ghost
Copy link
Author

ghost commented Jan 17, 2022

/verify with intel/llvm-test-suite#747

Copy link
Contributor

@vmaksimo vmaksimo left a 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.

Comment on lines 74 to 123
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}
Copy link
Contributor

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).

Copy link
Author

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.

@ghost
Copy link
Author

ghost commented Jan 18, 2022

/verify with intel/llvm-test-suite#747

AlexeySachkov
AlexeySachkov previously approved these changes Jan 18, 2022
Signed-off-by: Pavel Samolysov <[email protected]>
Co-authored-by: Mikhail Lychkov <[email protected]>
@ghost
Copy link
Author

ghost commented Jan 18, 2022

@mlychkov I've applied your suggestions about the lit test in 9687d41, the code of the solution itself should be re-designed.

@ghost ghost marked this pull request as draft January 18, 2022 10:27
Pavel Samolysov added 3 commits January 18, 2022 16:24
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).
@ghost
Copy link
Author

ghost commented Jan 18, 2022

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 zeroinitializer. Please, have a look.

@ghost ghost marked this pull request as ready for review January 18, 2022 17:06
@ghost ghost requested a review from vmaksimo January 18, 2022 17:06
@ghost ghost requested review from mlychkov, AlexeySachkov and bader January 18, 2022 17:06
Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better. Thanks.

Pavel Samolysov and others added 2 commits January 19, 2022 10:56
Also some local variables were inlined into function calls.

Signed-off-by: Pavel Samolysov <[email protected]>
Co-authored-by: Alexey Bader <[email protected]>
@ghost ghost requested a review from bader January 19, 2022 08:14
@ghost
Copy link
Author

ghost commented Jan 19, 2022

I've changed the description to make it clearer and describe all the changes in the PR.

AlexeySachkov
AlexeySachkov previously approved these changes Jan 19, 2022
Copy link
Contributor

@AlexeySachkov AlexeySachkov left a 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

@ghost
Copy link
Author

ghost commented Jan 19, 2022

/verify with intel/llvm-test-suite#747

@ghost
Copy link
Author

ghost commented Jan 19, 2022

/verify with intel/llvm-test-suite#747

@ghost
Copy link
Author

ghost commented Jan 19, 2022

I would like to test the vector-convolution-demo example in the llvm-test-suite project. The test fails due to errors in the test itself and it should not block merging this PR.

@ghost
Copy link
Author

ghost commented Jan 19, 2022

/verify with intel/llvm-test-suite#747

1 similar comment
@ghost
Copy link
Author

ghost commented Jan 20, 2022

/verify with intel/llvm-test-suite#747

@AlexeySachkov AlexeySachkov merged commit eec22ed into intel:sycl Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants