[llvm] [DirectX] Fix the writing of ConstantExpr GEPs to DXIL bitcode (PR #154446)

Deric C. via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 26 09:49:53 PDT 2025


================
@@ -343,9 +343,7 @@ bool DataScalarizerVisitor::visitGetElementPtrInst(GetElementPtrInst &GEPI) {
 
   GOp->replaceAllUsesWith(NewGEP);
 
-  if (auto *CE = dyn_cast<ConstantExpr>(GOp))
-    CE->destroyConstant();
-  else if (auto *OldGEPI = dyn_cast<GetElementPtrInst>(GOp))
+  if (auto *OldGEPI = dyn_cast<GetElementPtrInst>(GOp))
----------------
Icohedron wrote:

`GOp` is indeed a GEPOperator, but it could have been a ConstantExpr GEP or an Instruction.
The original implementation here checked if `GOp` was a ConstantExpr or an Instruction and then called `destroyConstant` or `eraseFromParent` respectively.
The change/diff is that `destroyConstant` is no longer called on `GOp` if it is a ConstantExpr. But `eraseFromParent` will still be called if `GOp` is an Instruction.

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


More information about the llvm-commits mailing list