[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:35:46 PST 2026


================
@@ -1108,12 +1109,19 @@ static void initializeBuffer(CodeGenModule &CGM, llvm::GlobalVariable *GV,
   // Make sure the global variable is buffer resource handle
   llvm::Type *HandleTy = GV->getValueType();
   assert(HandleTy->isTargetExtTy() && "unexpected type of the buffer global");
+  llvm::Type *UnderlyingType =
+      cast<TargetExtType>(HandleTy)->getTypeParameter(0);
 
   llvm::Value *CreateHandle = Builder.CreateIntrinsic(
       /*ReturnType=*/HandleTy, IntrID, Args, nullptr,
       Twine(GV->getName()).concat("_h"));
 
-  llvm::Value *HandleRef = Builder.CreateStructGEP(GV->getValueType(), GV, 0);
+  llvm::Value *HandleRef =
+      CGM.getLangOpts().EmitStructuredGEP
+          ? Builder.CreateStructuredGEP(UnderlyingType, GV,
+                                        llvm::ConstantInt::get(CGM.IntTy, 0))
+          : Builder.CreateStructGEP(GV->getValueType(), GV, 0);
----------------
Keenuts wrote:

Sent out https://github.com/llvm/llvm-project/pull/177584

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


More information about the cfe-commits mailing list