llvm-project
325a853c - [mlir] Build llvm.mlir.constant attributes from the result type (#218607)

Commit
81 days ago
[mlir] Build llvm.mlir.constant attributes from the result type (#218607) Many conversion patterns created `llvm.mlir.constant` with a value attribute whose type does not match the result type. The most common case was pairing an `index`-typed attribute with the converted index type: ``` llvm.mlir.constant(1 : index) : i64 ``` but there were also plain width and signedness mismatches, e.g. NVGPU's `makeI64Const` built `i64` constants from `i32` attributes, and the NVVM `fdiv` expansion used `ui32` attributes on `i32` values. Translation to LLVM IR ignores the attribute type and uses the result type, so the emitted IR was correct, but the attribute type is meaningless in this state and anything that reads it back sees the wrong type. Derive the attribute from the result type in every case; where the result is the converted index type, `LLVM::createIndexAttrConstant` now does this for all of its callers. In `ArithToLLVM`, retype the value attribute when the type converter maps `index` to a different integer type. Two element type changes must not be retyped: the low-precision float types that the converter maps to a same-width integer keep their float attribute, which `llvm.mlir.constant` accepts and takes the float semantics from, and a resource-backed elements attribute refers to a blob laid out for its own element type. Anything else is a malformed `arith.constant`, and the match fails rather than reinterpreting its value. `WmmaOpsToNvvm` builds its leading dimension attribute from the `i32` result, so reject a value that does not fit instead of narrowing it silently. This is in preparation for verifying that the two types agree. --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Author
Parents
Loading