-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL][ESIMD] Fix the crash in sycl-post-link while processing global spirv functions. #7590
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
bool IsVectorCall) { | ||
uint64_t IndexValue = isa<ExtractElementInst>(EEI) | ||
? getIndexFromExtract(cast<ExtractElementInst>(EEI)) | ||
: 0; |
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 using '0' for the getelementptr case is wrong. Instead, index from the GEP instruction should be extracted (marked below)
%0 = load i64, i64 addrspace(1)* getelementptr (<3 x i64>, <3 x i64> addrspace(1)* @__spirv_BuiltInGlobalInvocationId, i64 0, i64 0
), align 32
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.
It is actually for trunc instruction. In the pathological case there is no getElementptr
i.e. for
%0 = load i64, i64 addrspace(1)* getelementptr (<3 x i64>, <3 x i64> addrspace(1)* @__spirv_BuiltInGlobalInvocationId, i64 0, i64 0), align 32
%conv = trunc i64 %0 to i32
case and that is why index doesn't matter much here.
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 don't understand why index does not matter.
%ref.tmp.i = alloca %"class.sycl::_V1::ext::intel::esimd::simd.0", align 32 | ||
%0 = load i64, i64 addrspace(1)* getelementptr (<3 x i64>, <3 x i64> addrspace(1)* @__spirv_BuiltInGlobalInvocationId, i64 0, i64 0), align 32 | ||
%conv = trunc i64 %0 to i32 | ||
%1 = bitcast %"class.sycl::_V1::ext::intel::esimd::simd.0"* %ref.tmp.i to i8* |
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.
- Please simplify the test. Only instructions participating in pattern matching should be left.
- Please inline //CHECK: directives right after source IR instruction they are supposed to verify
transformation of
!opencl.compiler.options = !{!45} | ||
!llvm.ident = !{!46} | ||
|
||
!0 = !{i32 1, !"wchar_size", i32 4} |
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.
likewise, all unnecessary metadata should be removed.
@@ -0,0 +1,153 @@ | |||
; RUN: sycl-post-link -split-esimd -lower-esimd -O2 -S %s -o %t.table |
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.
please move the test to llvm/test/tools/sycl-post-link
BTW can we instead of handling this GEP(0,0) in sycl-post-link - remove this GEP at all here? It seems to be incorrect to access a vector via GEP and GEP(0,0) is quite useless anyway. Though, unfortunately, we can't just call replaceAllUsesWith... |
Good catch. |
sorry, hit wrong button |
This IR appeared during the pulldown after llvm/llvm-project@163bb6d. |
I take this back. |
Can we proceed with this patch? The pulldown is blocked by the crash being fixed here. |
auto *GEPCE = | ||
dyn_cast<GetElementPtrConstantExpr>(LI->getPointerOperand()); | ||
if (GEPCE) { | ||
IndexValue = cast<Constant>(GEPCE->getOperand(2)) | ||
->getUniqueInteger() | ||
.getZExtValue(); |
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 above code silently produces invalid IR if it gets unexpected IR. Please fix.
auto *GEPCE = | |
dyn_cast<GetElementPtrConstantExpr>(LI->getPointerOperand()); | |
if (GEPCE) { | |
IndexValue = cast<Constant>(GEPCE->getOperand(2)) | |
->getUniqueInteger() | |
.getZExtValue(); | |
auto *GEPCE = | |
cast<GetElementPtrConstantExpr>(LI->getPointerOperand()); | |
IndexValue = cast<Constant>(GEPCE->getOperand(2)) | |
->getUniqueInteger() | |
.getZExtValue(); |
not yet, there is still a bug to be fixed. (see above comment). I believe the patch can be merged once it is addressed. |
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.
This comment hasn't been addressed:
Please inline //CHECK: directives right after source IR instruction they are supposed to verify transformation of
Approving for the sake of urgency. Please address with follow-up patch.
@intel/dpcpp-tools-reviewers Could you please take a look ? |
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.
Approving for urgency, leaving correctness review to Konst and other reviewers
HIP Failures are unrelated: Unresolved Tests (5): Timed Out Tests (1): |
The guilty llvm change that caused crash just enables an additional optimization. To unblock pulldown the change that disables the optimization for sycl device code was merged. But this is not a proper solution. I've been testing workaround in SPIR-V translator together with reverting change that disables guilty optimization and also cherry-picked changes from this PR for testing. I've started testing here https://github.com/intel/llvm/actions/runs/3623046607/jobs/6108488479 . The thing is, with changes from this PR, I still see one of the tests failing, but with another error:
Could you please double check that everything is correct? |
@fineg74, please take a look at the issue reported above. |
ExtractElementInst *EEI = cast<ExtractElementInst>(LU); | ||
assert( | ||
(isa<ExtractElementInst>(LU) || isa<TruncInst>(LU)) && | ||
"SPIRV global users should be either ExtractElementInst or TruncInst"); |
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.
Sorry for being late for the review, I don't see such restrictions in SPIR-V spec, could you please help me finding it?
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.
These restrictions are to protect the code to make sure it processes only the code it is expected to process and not to enforce SPIR-V spec.
Currently for
int i = __spirv_GlobalInvocationId_x();
c++ code followinf IR code is generated:This IR is what sycl-post-link is expecting and is able to process successfully.
However, following IR code was generated during the testing:
and it caused sycl-post-link to crash.
The fix resolves the issue