Skip to content

[Enh] Add verifier for RecastIterOp to reject unsound pointer recasts#598

Open
Peter9606 wants to merge 1 commit into
ROCm:mainfrom
Deep-Spark:fujun.han/enhance-recastiterop
Open

[Enh] Add verifier for RecastIterOp to reject unsound pointer recasts#598
Peter9606 wants to merge 1 commit into
ROCm:mainfrom
Deep-Spark:fujun.han/enhance-recastiterop

Conversation

@Peter9606
Copy link
Copy Markdown
Contributor

Summary
fly.recast_iter reinterprets a pointer's element type, but its result type is supplied by the caller. Previously the result pointer was not validated at all — e.g. recasting a shared-memory pointer into global would silently flow through to lowering and cause undefined runtime behavior.

This PR adds a verifier for RecastIterOp that requires the result pointer to:

keep the same address space as the source (a reinterpret cannot move memory across address spaces);
only narrow the alignment guarantee (result alignment must divide source alignment) — narrowing is sound, widening is not;
keep the same swizzle.
Narrowing is intentionally allowed: existing kernels (e.g. preshuffle_gemm_v2) recast the 1024B-aligned dynamic shared base down to a 512B-aligned typed pointer.

Test
Adds tests/mlir/Conversion/recast_iter_invalid.mlir with FileCheck negative tests covering each rejected case (address-space change / alignment widening / swizzle change).

fly.recast_iter reinterprets a pointer's element type, but its result
type is supplied by the caller, so an invalid result pointer (e.g. one
that silently changes the address space) previously passed through to
lowering and could produce undefined runtime behavior.

Add a verifier enforcing that the result pointer:
- keeps the same address space as the source (a reinterpret cannot move
  shared memory into global, etc.);
- only narrows the alignment guarantee (result alignment must divide the
  source alignment) -- narrowing is sound, widening is not;
- keeps the same swizzle.

Add FileCheck negative tests covering each rejected case.

Assisted-by: Cursor (Opus4.8)
Signed-off-by: Fujun Han <fujun.han@iluvatar.com>
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.

1 participant