-
Notifications
You must be signed in to change notification settings - Fork 100
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
Case gnu range need to be improved #632
Comments
Hi @bcardosolopes, I'm working on this issue as we talked before, I felt it's not very trivial, so opened this issue to discuss it. IIUC, the two different codegen pipelines are as below. So the problem is cir lack the
Do you have some suggestions? I'll start the work if you confirm the solution, thanks! |
Consider this case: int test(int x) {
switch(x) {
case 1000 ... 2000:
return 1;
case 3333:
return 3;
case 4444:
return 4;
case 5555:
return 5;
default:
return 6;
}
} The original CodeGen generates: switch i32 %0, label %sw.caserange [
i32 3333, label %sw.bb1
i32 4444, label %sw.bb2
i32 5555, label %sw.bb3
]
sw.caserange:
%1 = sub i32 %0, 1000
%inbounds = icmp ule i32 %1, 1000
br i1 %inbounds, label %sw.bb, label %sw.default So to keep the same output code you cannot just replace int test(int x) {
switch(x) {
case 3333:
return 3;
case 4444:
return 4;
case 5555:
return 5;
default:
if (x >= 1000 && x <= 2000)
return 1;
return 6;
}
} |
@Lancern Your suggestion is great! |
We need a new switch case that tracks ranges.
Changing
Having the new range attribute is decoupled from the actual lowering strategy, as @Lancern pointed out - |
Make lowering result of case range smart. Resolve #632
Make lowering result of case range smart. Resolve llvm#632
Make lowering result of case range smart. Resolve llvm#632
Make lowering result of case range smart. Resolve llvm#632
Make lowering result of case range smart. Resolve llvm#632
Make lowering result of case range smart. Resolve #632
Pr #599 added support for gnu range in case statement, but the implementation need to store every integer inside the range.
For example, the following code will produce tons of repeated
While the OG codegen is smart
The text was updated successfully, but these errors were encountered: