[llvm] [DirectX] Support ConstExpr GEPs (PR #148986)

Deric C. via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 15 18:54:59 PDT 2025


================
@@ -305,6 +305,33 @@ bool DataScalarizerVisitor::visitGetElementPtrInst(GetElementPtrInst &GEPI) {
   Type *OrigGEPType = GEPI.getSourceElementType();
   Type *NewGEPType = OrigGEPType;
   bool NeedsTransform = false;
+  // Check if the pointer operand is a ConstantExpr GEP
+  if (auto *PtrOpGEPCE = dyn_cast<ConstantExpr>(PtrOperand);
+      PtrOpGEPCE && PtrOpGEPCE->getOpcode() == Instruction::GetElementPtr) {
+    if (GlobalVariable *NewGlobal =
----------------
Icohedron wrote:

I don't think it will ever naturally occur though. It may suffice to assert that the ConstantExpr GEP's pointer operand is a global variable and deal with it later if it does become an actual problem.

AFAIK there isn't a good reason to codegen a multiply-nested ConstantExpr GEP in the first place when you can codegen a single ConstantExpr GEP instead because all the indices are ConstantInts.

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


More information about the llvm-commits mailing list