Comments (9)
Seems to be more fundamental:
$ Debug/bin/cir-opt /tmp/test.cir
module @m attributes {cir.lang = #cir.lang<c>} {
cir.global external @fnan = #cir.fp<0.000000e+00> : !cir.float
}
So the parsesr seems to throw the NaN away. I will add a LIT test in IR/globals.cir and fix the issue 😇
from clangir.
I will not bore you with the many different methods that I tried until I finally got to the only solution that worked (validated with multitudes of tests). I tried to confine myself to the MLIR tools available, but they are unfortunately lacking as it seems very difficult to extend the AsmParser implementation downstream.
Therefore the only solution I found was to extend the API surface of the AsmParser upstream by creating a small refactor of AsmParserImpl::parseFloat
to support return of arbitrary APFloat
result as well as the original double
support. On the way, I also extended upstream MLIR support for parsing f80/f128 literals that must be printed in hex format, tested upstream. Without this extended parsing support, testing long double
lowering to LLVM would be possible only "in memory" and not through any pipeline which prints and parses.
I will upload draft PR here soon while I work on the MLIR upstream PR (requires adding an attribute to the Test dialect which mimics cir::FPAttr parsing behavior to test the new parsing API)
from clangir.
Uploaded "draft" PR to #572 . The CIR commit is ready-for-review and it would be appreciated :)
The MLIR commit is lacking the Test Dialect addition as mentioned above.
from clangir.
Thanks @orbiri :D
from clangir.
While trying to understand the root cause for this issue, I came to the realization that we are reimplementing the builtin dialect in CIR.
I understand the merit of not relying on upstream dialects in the core of CIR (as long as it is downstream) as @lanza explained in #62.
Still, it is harder for me to understand that decision w.r.t specifically the builtin dialect which is (builtin dialect docs)
The builtin dialect contains a core set of Attributes, Operations, and Types that have wide applicability across a very large number of domains and abstractions. Many of the components of this dialect are also instrumental in the implementation of the core IR
…
Given the far-reaching nature of this dialect and the fact that MLIR is extensible by design, any potential additions are heavily scrutinized.
Moreover, now that we are on the way to upstream CIR, it will be almost impossible to commit a breaking change in the builtin dialect which will break CIR!
I believe that the merit for using the builtin dialect is to avoid bugs exactly like this one which comes from the maintenance and potholes that have been tripped by the many users of MLIR in the last 4 years.
——
I still need to play around with it, but I might experiment with replacing the floating point attribute (not the type) in CIR with the builtin one and see how it looks like :)
from clangir.
I couldn't find a way to avoid re-implementing the logic of the builtin float attribute parser in CIRAttr.cpp
:/
The intermediate result (no pun intended) of the roundtrip tests looks like this:
// Note - type info is attached only to bitcasted integer literals, following the guidelines of the builtin FloatAttr
// CHECK: cir.global external @fhalf = #cir.fp<5.000000e-01> : !cir.float
// CHECK: cir.global external @fnan = #cir.fp<0x7FC00000 : !cir.float> : !cir.float
// CHECK: cir.global external @dnan = #cir.fp<0x7FF8000000000000 : !cir.double> : !cir.double
Adding more rigorous tests to cover all edge cases and will post PR by (or over) the weekend.
from clangir.
Builtin dialects are great, but it's easier overall to handle ours, which should only care about C/C++ (with its own specific semantics and target variations), and lower to these builtin types whenever it makes sense for a specific lowering story.
from clangir.
I couldn't find a way to avoid re-implementing the logic of the builtin float attribute parser in CIRAttr.cpp
Depending on how big that is, probably a non-starter.
So the parsesr seems to throw the NaN away
I'm not sure I grasped what's going on here entirely, perhaps it will be clear with the PR up. Anyways, it's also possible we could have a specific attribute to represent NaNs just like we have #cir.zero
for zeros.
from clangir.
Thanks for taking the time to improve things in MLIR upstream so we can use it, awesome!
from clangir.
Related Issues (20)
- Should mark private visibility for extern symbols.
- Vector related arith missing `nsw` on addition HOT 2
- Revisit insertion point being restored by an InsertionGuard in `buildSwitchBody()` HOT 1
- [Umbrella] Switch stmt CIRGen issues
- Single-operand vector shuffling HOT 1
- [ThroughMLIR] cir-opt can not work when lowering ForOp to scf HOT 4
- Add a test for arrays of 3-component extended vectors
- Crash with try statement HOT 1
- [GSoC] Add OpenCL support to compile GPU kernels
- Reinstate #668 and #678 HOT 2
- Verify ZdlPv -> ZdlPvm in `test/CIR/CodeGen/dtors.cpp`
- Verify gep uses moving to i64
- Replace uses of `isa`/`dyn_cast`/`cast`/... member functions HOT 2
- Data layout modeling for CIR types
- Add support for `__atomic_thread_fence` HOT 3
- Add canonicalization passes for cir.complex.create
- Problem with emitting MLIR from CIR: `cir.func` gets `dsolocal` attribute HOT 4
- Non-constant memory order in atomic built-ins HOT 3
- Keep higher level abstraction for runtime memory orders on atomics
- `emit-cir-flat` is a bit broken HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from clangir.