<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/91774>91774</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir][sparse] Calling mlir-opt with sparsifier's dumped pass pipeline for GPU codegen does not emit GPU code
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir:gpu,
            mlir:sparse
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ggeorgakoudis
      </td>
    </tr>
</table>

<pre>
    First call `mlir-opt` for the sparsifier to generate GPU code and dump the pass pipeline (I'm omitting the mlir input file, reproducers contain it):
```
mlir-opt --sparsifier="enable-runtime-library=false parallelization-strategy=dense-outer-loop gpu-triple=nvptx64-nvidia-cuda gpu-chip=sm_80 gpu-features=+ptx71 gpu-format=llvm" --dump-pass-pipeline
```
Reproducer: https://godbolt.org/z/7cP8z1qcY

Then use the dumped pipeline directly in `mlir-opt`:
```
mlir-opt -pass-pipeline="builtin.module(func.func(linalg-generalize-named-ops),func.func(linalg-fuse-elementwise-ops),sparsification-and-bufferization,sparse-storage-specifier-to-llvm,func.func(canonicalize{ max-iterations=10 max-num-rewrites=-1 region-simplify=true test-convergence=false top-down=true}),func.func(finalizing-bufferize),sparse-gpu-codegen{enable-runtime-library=true num-threads=1024},gpu.module(strip-debuginfo),gpu.module(convert-scf-to-cf),gpu.module(convert-gpu-to-nvvm{has-redux=false index-bitwidth=0 use-bare-ptr-memref-call-conv=false}),func.func(convert-linalg-to-loops),func.func(convert-vector-to-scf{full-unroll=false lower-tensors=false target-rank=1}),func.func(expand-realloc{emit-deallocs=true}),func.func(convert-scf-to-cf),expand-strided-metadata,lower-affine,convert-vector-to-llvm{enable-amx=false enable-arm-neon=false enable-arm-sve=false enable-x86vector=false force-32bit-vector-indices=true reassociate-fp-reductions=false},finalize-memref-to-llvm{index-bitwidth=0 use-aligned-alloc=false use-generic-functions=false},func.func(convert-complex-to-standard),func.func(arith-expand{include-bf16=false}),func.func(convert-math-to-llvm{approximate-log1p=true}),convert-math-to-libm,convert-complex-to-libm,convert-vector-to-llvm{enable-amx=false enable-arm-neon=false enable-arm-sve=false enable-x86vector=false force-32bit-vector-indices=true reassociate-fp-reductions=false},convert-complex-to-llvm,convert-vector-to-llvm{enable-amx=false enable-arm-neon=false enable-arm-sve=false enable-x86vector=false force-32bit-vector-indices=true reassociate-fp-reductions=false},convert-func-to-llvm{index-bitwidth=0 use-bare-ptr-memref-call-conv=false},nvvm-attach-target{O=2 chip=sm_80 fast=false features=+ptx71 ftz=false  module= triple=nvptx64-nvidia-cuda},gpu-to-llvm{gpu-binary-annotation=gpu.binary use-bare-pointers-for-host=false use-bare-pointers-for-kernels=false},gpu-module-to-binary{format=llvm  opts= toolkit=},reconcile-unrealized-casts)"
```
Reproducer: https://godbolt.org/z/1zz64j895

Expected to see to same the same GPU codegen as with callng the sparsifier but output does not contain GPU code
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcV0tzK6cS_jVoQ-HSMHoutLCkq1t3dU-lkkVWKQZ6RhwzQKCRZf36FIxetnUei2ySKpdk9TR09_d90zQiRt1ZgBWZrsl0OxIJ9y6sug5c6MSLS0rHUePU22qnQ0QqhTGUzMa90YE5j2Q2pq0LFPdAoxch6lZDoOhoBxaCQKD__fIblU4BFVZRlXpfnL2IkXrtwWgLlPDF_wif99T1GlHbrvjkIFRbn5C22gDhGxrAB6eShBCpdBaFtlQj4UtSP5PxloyfyWx8_is_L4lSxm75kXpLOAcrGgMsJIu6B2Z0E0R4I_W2FSbmDIMwBow-CdTOsoi5nC47KLARmEsIgRnnPO18Yhi0N0DqrT14PM4mzB600oLJpERxkHvtSb2N_R-LcTG0IDAFiCWdtcfjvBrsLvQCSb015tATziljGTeWMWMXzB5W-8sVHlI_0z2ijxkYviN81znVOINPLnSE706E7-byy-JU_Sl_P-9VPn_dg6UpQmEghwV140npABL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