llvm-project
aecfaf11 - [flang][acc] Handle fir.undefined with OutlineRematerializationOpInterface in OffloadLiveInValueCanonicalization (#188325)

Commit
2 days ago
[flang][acc] Handle fir.undefined with OutlineRematerializationOpInterface in OffloadLiveInValueCanonicalization (#188325) Example: ```fortran !$ACC KERNELS PRESENT(CG, W1) CG(1:W1%WDES1%NPL, NN) = W1%CPTWFP(1:W1%WDES1%NPL) CPROJ(:, NN) = W1%CPROJ(1:SIZE(CPROJ,1)) !$ACC END KERNELS ``` When compiling OpenACC kernels containing array section assignments of rank-2 arrays with a scalar index in one dimension (e.g. `CG(1:NPL, NN)`), the Fortran lowering creates a `fir.slice` where collapsed (scalar) dimensions use `fir.undefined index` as the stop/step values. `SliceOp::getOutputRank()` relies on `getDefiningOp()` returning `fir::UndefOp` to identify these collapsed dimensions and compute the correct output rank. When `fir.undefined` values defined outside an offload region are used inside it, `gpu-kernel-outlining` turns them into function arguments. Since function arguments have no defining op (`getDefiningOp()` returns `nullptr`), `getOutputRank()` no longer recognizes the collapsed dimensions, computing rank 2 instead of rank 1. This causes the `fir.rebox` verifier to fail with: ``` 'fir.rebox' op result type rank and rank after applying slice operand must match ``` Fix: Register `OutlineRematerializationOpInterface` for `fir::UndefOp` (and `fir::SliceOp`) in `RegisterOpenACCExtensions.cpp`. This causes `OffloadLiveInValueCanonicalization` to clone these operations inside the offload region before outlining, preserving the `fir::UndefOp` identity so that `getOutputRank()` correctly identifies collapsed dimensions.
Author
Parents
Loading