Skip to content
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

No bounds checks should be emitted for static arrays #553

Closed
dnadlinger opened this issue Dec 12, 2013 · 2 comments
Closed

No bounds checks should be emitted for static arrays #553

dnadlinger opened this issue Dec 12, 2013 · 2 comments

Comments

@dnadlinger
Copy link
Member

Reported by @bearophile:

I am trying the following program with both the latest dmd 2.065alpha and ldc2 2.063.2, with no optimizations:

int fun(int[3] a) {
    return a[0]+ a[1] + a[2];
}
int main() {
    int total = 0;
    foreach (immutable _; 0 .. 100_000_000)
        total += fun([1, 2, 3]);
    return total;
}
__D5test23funFG3iZi:
    subl    $28, %esp
    leal    32(%esp), %eax
    movb    $1, %cl
    testb   $1, %cl
    movl    %eax, 24(%esp)
    jne LBB0_2
    jmp LBB0_1
LBB0_1:
    leal    __D5test212__ModuleInfoZ, %eax
    movl    $2, %ecx
    movl    %eax, (%esp)
    movl    $2, 4(%esp)
    movl    %ecx, 20(%esp)
    calll   __d_array_bounds
LBB0_2:
    movb    $1, %al
    testb   $1, %al
    jne LBB0_4
    leal    __D5test212__ModuleInfoZ, %eax
    movl    $2, %ecx
    movl    %eax, (%esp)
    movl    $2, 4(%esp)
    movl    %ecx, 16(%esp)
    calll   __d_array_bounds
LBB0_4:
    movb    $1, %al
    movl    24(%esp), %ecx
    movl    (%ecx), %edx
    addl    4(%ecx), %edx
    testb   $1, %al
    movl    %edx, 12(%esp)
    jne LBB0_6
    leal    __D5test212__ModuleInfoZ, %eax
    movl    $2, %ecx
    movl    %eax, (%esp)
    movl    $2, 4(%esp)
    movl    %ecx, 8(%esp)
    calll   __d_array_bounds
LBB0_6:
    movl    24(%esp), %eax
    movl    8(%eax), %ecx
    movl    12(%esp), %edx
    addl    %ecx, %edx
    movl    %edx, %eax
    addl    $28, %esp
    ret $12
redstar added a commit to redstar/ldc that referenced this issue Dec 13, 2013
Check if a static array is accessed with a known index. In this case the
bounds check can be omitted.
redstar added a commit that referenced this issue Dec 14, 2013
Check if a static array is accessed with a known index. In this case the
bounds check can be omitted.
redstar added a commit to redstar/ldc that referenced this issue Dec 16, 2013
Check if a static array is accessed with a known index. In this case the
bounds check can be omitted.
@redstar
Copy link
Member

redstar commented Dec 16, 2013

Fixes in 0.12 with pull request #554.

redstar added a commit that referenced this issue Dec 16, 2013
This version uses the skipboundscheck member variable.
@redstar
Copy link
Member

redstar commented Dec 16, 2013

In the merge-2.064 branch, skipboundscheck is now honored.

@redstar redstar closed this as completed Dec 16, 2013
redstar pushed a commit that referenced this issue Sep 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants