[clang] [Clang][HLSL] Start emitting structured GEP instruction (PR #177332)

Nathan Gauër via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 23 05:08:07 PST 2026


================
@@ -4497,6 +4497,17 @@ Address CodeGenFunction::EmitArrayToPointerDecay(const Expr *E,
   if (!E->getType()->isVariableArrayType()) {
     assert(isa<llvm::ArrayType>(Addr.getElementType()) &&
            "Expected pointer to array");
+
+    if (getLangOpts().HLSL && getLangOpts().EmitStructuredGEP) {
+      llvm::Value *Ptr = Addr.emitRawPointer(*this);
+      if (auto *C = dyn_cast<llvm::Constant>(Ptr))
+        return Address(C, Addr.getElementType(), Addr.getAlignment(),
+                       Addr.isKnownNonNull());
+      return Address(
+          Builder.CreateStructuredGEP(NewTy, Addr.getBasePointer(), {}),
----------------
Keenuts wrote:

You are correct: A SGEP with no indices returns the same pointer as the base pointer. Mmm seems like maybe I don't need to emit anything here. I'll take a look.

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


More information about the cfe-commits mailing list