Skip to content

Commit 38aec4f

Browse files
authored
[DirectX] Limit GEP transformations to Arrays (#145758)
fixes #145408 Before we see the GEP we already have transformed Allocas that get passed the `isArrayOfVectors`. The bug is because we are trying to transform a gep for struct of arrays when we should only be transforming arrays. The problem with our `visitGetElementPtrInst` is that it was doing transformations for all allocas when it should be limiting it to the alloca of array cases. Technically we would have liked to make sure it was an array of vectors cases but by the time we see the GEP the type has been changed by replace all uses. There should not be a problem with looking at all Arrays since DXILDataScalarization does not change any indicies.
1 parent a8ef75e commit 38aec4f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

llvm/lib/Target/DirectX/DXILDataScalarization.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,8 @@ bool DataScalarizerVisitor::visitGetElementPtrInst(GetElementPtrInst &GEPI) {
308308
NeedsTransform = true;
309309
} else if (AllocaInst *Alloca = dyn_cast<AllocaInst>(PtrOperand)) {
310310
Type *AllocatedType = Alloca->getAllocatedType();
311-
// OrigGEPType might just be a pointer lets make sure
312-
// to add the allocated type so we have a size
313-
if (AllocatedType != OrigGEPType) {
311+
// Only transform if the allocated type is an array
312+
if (AllocatedType != OrigGEPType && isa<ArrayType>(AllocatedType)) {
314313
NewGEPType = AllocatedType;
315314
NeedsTransform = true;
316315
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -dxil-data-scalarization -mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
3+
4+
%struct.RawStruct8D = type { [8 x i32] }
5+
6+
define void @test_no_transform_of_struct() {
7+
; CHECK-LABEL: define void @test_no_transform_of_struct() {
8+
; CHECK-NEXT: [[ENTRY:.*:]]
9+
; CHECK-NEXT: [[OUTPUTSIZESLOCAL_I:%.*]] = alloca [[STRUCT_RAWSTRUCT8D:%.*]], align 4
10+
; CHECK-NEXT: [[ARRAYINIT_ELEMENT13_I76:%.*]] = getelementptr inbounds nuw [1 x %struct.RawStruct8D], ptr [[OUTPUTSIZESLOCAL_I]], i32 0, i32 0
11+
; CHECK-NEXT: ret void
12+
;
13+
entry:
14+
%outputSizesLocal.i = alloca %struct.RawStruct8D, align 4
15+
%arrayinit.element13.i76 = getelementptr inbounds nuw [1 x %struct.RawStruct8D], ptr %outputSizesLocal.i, i32 0, i32 0
16+
ret void
17+
}

0 commit comments

Comments
 (0)