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

Nathan Gauër via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 26 07:22:17 PST 2026


================
@@ -4537,6 +4540,9 @@ static llvm::Value *emitArraySubscriptGEP(CodeGenFunction &CGF,
                                           bool signedIndices,
                                           SourceLocation loc,
                                     const llvm::Twine &name = "arrayidx") {
+  if (CGF.getLangOpts().HLSL && inbounds && CGF.getLangOpts().EmitStructuredGEP)
+    return CGF.Builder.CreateStructuredGEP(elemType, ptr, indices);
----------------
Keenuts wrote:

For now, the SGEP instruction documentation says it assumes inbounds. So to start, I reduced the scope to calls with the inbounds bit.
They as we add more tests to the frontend (or migrate existing ones), we should encounter new variations around this and then we'll have to figure out what to do:
 - maybe sometimes emit without `inbounds` be could have, so we should fix it
 - maybe we don't mark it as `inbounds`, but in the context of SGEP, it would be fine (as the index is runtime, cannot be checked, but we can assume inbounds)

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


More information about the cfe-commits mailing list