<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/225260>225260</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[mlir][spirv] Spec-constant custom printers drop discardable attributes
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
snarang181
</td>
</tr>
</table>
<pre>
## Summary
The custom text formats for SPIR-V scalar, composite, and replicated
specialization constants omit their discardable attribute dictionaries. The
same stored operation retains the attribute in generic syntax and bytecode,
but ordinary printing silently removes it and reparsing makes the loss permanent.
## Reproducer
```mlir
spirv.module @m Logical GLSL450 {
"spirv.SpecConstant"() <{
default_value = 1 : i32,
sym_name = "scalar"
}> {test.marker = "keep"} : () -> ()
}
```
Verified at `b2b38d4b3352`:
```console
$ mlir-opt repro.mlir -allow-unregistered-dialect | grep SpecConstant
spirv.SpecConstant @scalar = 1 : i32
$ mlir-opt repro.mlir -allow-unregistered-dialect -mlir-print-op-generic | grep test.marker
"spirv.SpecConstant"() <{default_value = 1 : i32, sym_name = "scalar"}> {test.marker = "keep"} : () -> ()
```
The pin `57b5017e0102` produces the same pair:
```console
$ mlir-opt repro.mlir -allow-unregistered-dialect | grep SpecConstant
spirv.SpecConstant @scalar = 1 : i32
$ mlir-opt repro.mlir -allow-unregistered-dialect -mlir-print-op-generic | grep test.marker
"spirv.SpecConstant"() <{default_value = 1 : i32, sym_name = "scalar"}> {test.marker = "keep"} : () -> ()
```
Expected: custom syntax round-trips `test.marker`.
Actual: only generic output retains it.
## Agent Analysis
At `b2b38d4b3352`, `mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp:1879-2110`
contains no optional attribute-dictionary parse/print path for
`SpecConstant`, `SpecConstantComposite`, or
`EXTSpecConstantCompositeReplicate`. Parse and print the discardable dictionary.
**Related:** PR #218920 added inherent visibility handling to these printers;
it does not serialize arbitrary discardable attributes and is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