Skip to content

Commit eaa43cc

Browse files
committed
[SPIRV] Fix assertion violation caused by unexpected ConstantExpr.
1 parent 5ccf8c9 commit eaa43cc

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,13 +2816,10 @@ SPIRVEmitIntrinsics::simplifyZeroLengthArrayGepInst(GetElementPtrInst *GEP) {
28162816
ArrayType *ArrTy = dyn_cast<ArrayType>(SrcTy);
28172817
if (ArrTy && ArrTy->getNumElements() == 0 &&
28182818
PatternMatch::match(Indices[0], PatternMatch::m_Zero())) {
2819-
IRBuilder<> Builder(GEP);
28202819
Indices.erase(Indices.begin());
28212820
SrcTy = ArrTy->getElementType();
2822-
Value *NewGEP = Builder.CreateGEP(SrcTy, GEP->getPointerOperand(), Indices,
2823-
"", GEP->getNoWrapFlags());
2824-
assert(llvm::isa<GetElementPtrInst>(NewGEP) && "NewGEP should be a GEP");
2825-
return cast<GetElementPtrInst>(NewGEP);
2821+
return GetElementPtrInst::Create(SrcTy, GEP->getPointerOperand(), Indices,
2822+
GEP->getNoWrapFlags(), "", GEP);
28262823
}
28272824
return nullptr;
28282825
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
2+
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown < %s | FileCheck %s
3+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown < %s -filetype=obj | spirv-val %}
4+
5+
define spir_kernel void @_Z6kernelPi() addrspace(4) {
6+
; CHECK-LABEL: _Z6kernelPi
7+
; CHECK: %12 = OpFunction %3 None %4 ; -- Begin function _Z6kernelPi
8+
; CHECK-NEXT: %2 = OpLabel
9+
; CHECK-NEXT: %13 = OpBitcast %6 %11
10+
; CHECK-NEXT: %14 = OpInBoundsPtrAccessChain %6 %13 %10
11+
; CHECK-NEXT: %15 = OpConvertPtrToU %5 %14
12+
; CHECK-NEXT: %16 = OpBitcast %6 %11
13+
; CHECK-NEXT: OpStore %16 %15 Aligned 4
14+
; CHECK-NEXT: OpReturn
15+
; CHECK-NEXT: OpFunctionEnd
16+
entry:
17+
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
18+
ret void
19+
}

0 commit comments

Comments
 (0)