D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6350 - Const array static usage optimization
Summary: Const array static usage optimization
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2011-07-19 16:58 UTC by bearophile_hugs
Modified: 2024-12-13 17:55 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2011-07-19 16:58:20 UTC
A D2 program:


enum int[1] array1 = [10];
int foo(int[1] v) {
    return array1[0] * v[0];
}
const int[1] array2 = [10];
int bar(int[1] v) {
    return array2[0] * v[0];
}
void main() {}


The asm of the two functions (dmd 2.054, -O -release), inside bar() the contents of array2 are loaded with a mov instruction:

_D4test3fooFG1iZi   comdat
        push    EAX
        lea EAX,[EAX*4][EAX]
        add EAX,EAX
        pop ECX
        ret

_D4test3barFG1iZi   comdat
        push    EAX
        mov EAX,_D4test6array2xG1i
        imul    EAX,[ESP]
        pop ECX
        ret


Is it possible for the compiler for such common case of const array to remove the mov instruction from the bar () function too?
Comment 1 dlangBugzillaToGithub 2024-12-13 17:55:53 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18357

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB