-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[SPIRV] Fix assertion violation caused by unexpected ConstantExpr. #170524
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
|
@llvm/pr-subscribers-backend-spir-v Author: Manuel Carrasco (mgcarrasco) Changes
This LLVM defect was identified via the AMD Fuzzing project. Full diff: https://github.com/llvm/llvm-project/pull/170524.diff 2 Files Affected:
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index eea49bfdaf04b..736020406ce96 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -2816,13 +2816,10 @@ SPIRVEmitIntrinsics::simplifyZeroLengthArrayGepInst(GetElementPtrInst *GEP) {
ArrayType *ArrTy = dyn_cast<ArrayType>(SrcTy);
if (ArrTy && ArrTy->getNumElements() == 0 &&
PatternMatch::match(Indices[0], PatternMatch::m_Zero())) {
- IRBuilder<> Builder(GEP);
Indices.erase(Indices.begin());
SrcTy = ArrTy->getElementType();
- Value *NewGEP = Builder.CreateGEP(SrcTy, GEP->getPointerOperand(), Indices,
- "", GEP->getNoWrapFlags());
- assert(llvm::isa<GetElementPtrInst>(NewGEP) && "NewGEP should be a GEP");
- return cast<GetElementPtrInst>(NewGEP);
+ return GetElementPtrInst::Create(SrcTy, GEP->getPointerOperand(), Indices,
+ GEP->getNoWrapFlags(), "", GEP);
}
return nullptr;
}
diff --git a/llvm/test/CodeGen/SPIRV/const-array-gep.ll b/llvm/test/CodeGen/SPIRV/const-array-gep.ll
new file mode 100644
index 0000000000000..c1dfe18aee6e6
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/const-array-gep.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown < %s | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown < %s -filetype=obj | spirv-val %}
+
+define spir_kernel void @_Z6kernelPi() addrspace(4) {
+; CHECK-LABEL: _Z6kernelPi
+; CHECK: %12 = OpFunction %3 None %4 ; -- Begin function _Z6kernelPi
+; CHECK-NEXT: %2 = OpLabel
+; CHECK-NEXT: %13 = OpBitcast %6 %11
+; CHECK-NEXT: %14 = OpInBoundsPtrAccessChain %6 %13 %10
+; CHECK-NEXT: %15 = OpConvertPtrToU %5 %14
+; CHECK-NEXT: %16 = OpBitcast %6 %11
+; CHECK-NEXT: OpStore %16 %15 Aligned 4
+; CHECK-NEXT: OpReturn
+; CHECK-NEXT: OpFunctionEnd
+entry:
+ store i32 ptrtoint (ptr addrspace(4) getelementptr inbounds ([0 x i32], ptr addrspace(4) null, i64 0, i64 1) to i32), ptr addrspace(4) null, align 4
+ ret void
+}
|
eaa43cc to
415ab60
Compare
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/162/builds/36659 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/211/builds/4393 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/28559 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/129/builds/34551 Here is the relevant piece of the build log for the reference |
…lvm#170524) `SPIRVEmitIntrinsics::simplifyZeroLengthArrayGepInst` asserted that it always expected a `GetElementPtrInst` from `IRBuilder::CreateGEP` (which returns a `Value`). `IRBuilder` can fold and return a `ConstantExpr` instead, thus violating the assertion. The patch fixes this by using `GetElementPtrInst::Create` to always return a `GetElementPtrInst`. This LLVM defect was identified via the AMD Fuzzing project.
SPIRVEmitIntrinsics::simplifyZeroLengthArrayGepInstasserted that it always expected aGetElementPtrInstfromIRBuilder::CreateGEP(which returns aValue).IRBuildercan fold and return aConstantExprinstead, thus violating the assertion. The patch fixes this by usingGetElementPtrInst::Createto always return aGetElementPtrInst.This LLVM defect was identified via the AMD Fuzzing project.