Skip to content

Update LLVM - #1740

Merged
rjodinchr merged 1 commit into
google:mainfrom
rjodinchr:update-llvm
Nov 12, 2026
Merged

rjodinchr merged 1 commit into
google:mainfrom
rjodinchr:update-llvm

Conversation

@rjodinchr

Copy link
Copy Markdown
Collaborator

LLVM's IRBuilder::CreateGEP now canonicalizes getelementptr instructions into i8 or [N x i8] ptradd form and elides all-zero indices.

  • Extend SimplifyPointerBitcastPass (runOnUpgradeableConstantCasts) to recognize single-index [N x i8] GEPs alongside i8 GEPs so canonicalized byte-array GEPs created by upstream LLVM passes can be upgraded to the target element type.
  • Add clspv::CreateGEP and clspv::CreateInBoundsGEP helpers in Types.h that preserve explicit GEP source element types via GetElementPtrInst::Create (after running the builder's FoldGEP), and use them across clspv passes that rely on typed GEPs.

@rjodinchr
rjodinchr enabled auto-merge (squash) November 12, 2026 09:47
LLVM's `IRBuilder::CreateGEP` now canonicalizes `getelementptr`
instructions into `i8` or `[N x i8]` `ptradd` form and elides all-zero
indices.

- Extend `SimplifyPointerBitcastPass` (`runOnUpgradeableConstantCasts`)
  to recognize single-index `[N x i8]` GEPs alongside `i8` GEPs so
  canonicalized byte-array GEPs created by upstream LLVM passes can be
  upgraded to the target element type.
- Add `clspv::CreateGEP` and `clspv::CreateInBoundsGEP` helpers in
  `Types.h` that preserve explicit GEP source element types via
  `GetElementPtrInst::Create` (after running the builder's `FoldGEP`),
  and use them across clspv passes that rely on typed GEPs.
@rjodinchr
rjodinchr merged commit 2f39180 into google:main Nov 12, 2026
17 of 18 checks passed
@rjodinchr
rjodinchr deleted the update-llvm branch November 12, 2026 12:36
rjodinchr added a commit to rjodinchr/clspv that referenced this pull request Nov 12, 2026
Follow-up to google#1740:

- Do not upgrade `[N x i8]` GEPs to struct types or upgrade GEPs to packed
  struct types in `runOnUpgradeableConstantCasts`. `RewritePackedStructs`
  lowers packed struct GEPs into `[N x i8]` GEPs and relies on
  `runOnImplicitCasts` and `ReplacePointerBitcastPass` to lower downstream
  struct users; upgrading `[N x i8]` back to the struct type undoes
  `RewritePackedStructs` and leaves unaligned packed structs in SPIR-V.
- Reject empty `[0 x i8]` arrays in `IsByteArrayTy` to avoid division by
  zero when computing GEP stride ratios.
- Require `smallerBitWidths` and `coef_target` to evenly divide each other
  (`smallerBitWidths % coef_target == 0` when `coef_target <= smallerBitWidths`,
  or `coef_target % smallerBitWidths == 0` otherwise) before upgrading
  dynamic `[N x i8]` GEPs, including in the `knownMultiple` fallback, so
  `GetIdxsForTyFromOffset` never hits an assertion or truncates non-integer
  stride ratios.
- Remove unused variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants