[llvm] [DirectX] Limit GEP transformations to Arrays (PR #145758)

Finn Plummer via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 25 12:13:56 PDT 2025


================
@@ -308,9 +308,8 @@ bool DataScalarizerVisitor::visitGetElementPtrInst(GetElementPtrInst &GEPI) {
     NeedsTransform = true;
   } else if (AllocaInst *Alloca = dyn_cast<AllocaInst>(PtrOperand)) {
     Type *AllocatedType = Alloca->getAllocatedType();
-    // OrigGEPType might just be a pointer lets make sure
-    // to add the allocated type so we have a size
-    if (AllocatedType != OrigGEPType) {
+    // Only transform if the allocated type is an array
+    if (AllocatedType != OrigGEPType && isa<ArrayType>(AllocatedType)) {
----------------
inbelic wrote:

I guess we should be more restrictive here to be consistent with the `visitAllocaInst`: https://github.com/llvm/llvm-project/blob/2f817d1c9e7341d634931e3deb3f849ce67035da/llvm/lib/Target/DirectX/DXILDataScalarization.cpp#L127.

In general, this pass only seems interested to transform arrays of vectors. so we shouldn't need to transform a simple array of eg i32. Can we extend the testcase to demonstrate this scenario as well?

https://github.com/llvm/llvm-project/pull/145758


More information about the llvm-commits mailing list