diff options
| author | Rik Huijzer <github@huijzer.xyz> | 2023-12-05 12:31:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-05 12:31:49 +0100 |
| commit | 13da9a58c5c823eeda6af125ef6df9d8b0748bd2 (patch) | |
| tree | de2834d6321470b1fdfa3bcc6867545eb81369cd /llvm/lib/Transforms/Utils/Local.cpp | |
| parent | 17de468df1af6479f31bb8c02973e01702f7b240 (diff) | |
| download | llvm-13da9a58c5c823eeda6af125ef6df9d8b0748bd2.zip llvm-13da9a58c5c823eeda6af125ef6df9d8b0748bd2.tar.gz llvm-13da9a58c5c823eeda6af125ef6df9d8b0748bd2.tar.bz2 | |
[mlir][llvm] Fix verifier for const int and dense (#74340)
Continuation of https://github.com/llvm/llvm-project/pull/74247 to fix
https://github.com/llvm/llvm-project/issues/56962. Fixes verifier for
(Integer Attr):
```mlir
llvm.mlir.constant(1 : index) : f32
```
and (Dense Attr):
```mlir
llvm.mlir.constant(dense<100.0> : vector<1xf64>) : f32
```
## Integer Attr
The addition that this PR makes to `LLVM::ConstantOp::verify` is meant
to be exactly verifying the code in
`mlir::LLVM::detail::getLLVMConstant`:
https://github.com/llvm/llvm-project/blob/9f78edbd20ed922cced9482f7791deb9899a6d82/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp#L350-L353
One failure mode is when the `type` (`llvm.mlir.constant(<value>) :
<type>`) is not an `Integer`, because then the `cast` in
`getIntegerBitWidth` will crash:
https://github.com/llvm/llvm-project/blob/dca432cb7b1c282f5dc861095813c4f40f109619/llvm/include/llvm/IR/DerivedTypes.h#L97-L99
So that's now caught in the verifier.
Apart from that, I don't see anything we could check for. `sextOrTrunc`
means "Sign extend or truncate to width" and that one is quite
permissive. For example, the following doesn't have to be caught in the
verifier as it doesn't crash during `mlir-translate -mlir-to-llvmir`:
```mlir
llvm.func @main() -> f32 {
%cst = llvm.mlir.constant(100 : i64) : f32
llvm.return %cst : f32
}
```
## Dense Attr
Crash if not either a MLIR Vector type or one of these:
https://github.com/llvm/llvm-project/blob/9f78edbd20ed922cced9482f7791deb9899a6d82/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp#L375-L391
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
0 files changed, 0 insertions, 0 deletions
