-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refine the design of cir.while #1342
Comments
Here is a more detailed explanation about this issue. Consider the following C/C++ code: while (int x = foo()) { /* body */ } According to the standard12, the code above is strictly equivalent to the following code: label: {
int x = foo();
if (x) {
/* body */
goto label;
}
} However, currently CIRGen emits the following CIR from the code (simplified for simplicity): cir.scope {
%x.slot = cir.alloca !s32i
cir.while {
%0 = cir.call @foo()
cir.store %0, %x.slot
%1 = cir.load %x.slot
%2 = cir.cast int_to_bool %1
cir.condition(%2)
} do {
// body
}
} The problem here is the Footnotes |
In general, I have put my eyes on the IR design of CIR loops and wanted to find time moving it to something that would allow this to happen. You can see #1267 for example. I believe that there’s a big overlap here: if we harmonize the do-while and while loops similarly to how scf does, and also add support for region arguments we may easily allow the construct like you are describing above: defining the alloca in the condition region and passing its result into the body region without and not carrying it over again. If not actually contributing this, as my free time lately has been on the scarce side, I’d be happy to actively participate in the design process and to lend initial review guidance :) |
Thanks @orbiri |
Originally posted by @Lancern in #1261 (comment)
The text was updated successfully, but these errors were encountered: