[Issue 9097] New: Value range propagation to disable some array bound tests
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Nov 29 11:17:38 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9097
Summary: Value range propagation to disable some array bound
tests
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-11-29 11:17:33 PST ---
A little test program:
void main(string[] args) {
size_t a = 6000 + args.length;
int[200] array;
array[a % 100] = 1;
}
-----------------------
Compiled with "dmd -O -inline":
__Dmain:
L0: sub ESP, 0338h
mov ECX, 0C8h
push EDI
mov EAX, 0340h[ESP]
add EAX, 01770h
mov 0Ch[ESP], EAX
xor EAX, EAX
lea EDI, 01Ch[ESP]
rep
stosd
mov EAX, 0Ch[ESP]
mov ECX, 064h
xor EDX, EDX
div ECX
cmp EDX, 0C8h
mov 8[ESP], EDX
jb L47
mov EAX, 4
call near ptr _D5test27__arrayZ
L47: mov EDX, 8[ESP]
xor EAX, EAX
mov dword ptr 01Ch[EDX*4][ESP], 1
pop EDI
add ESP, 0338h
ret
_D5test27__arrayZ:
L0: push EAX
mov ECX, offset FLAT:_D5test212__ModuleInfoZ
push EAX
push ECX
call near ptr __d_array_bounds
-----------------------
Compiled with "dmd -O -inline -release -noboundscheck":
__Dmain:
sub ESP, 0330h
mov ECX, 0C8h
push EDI
mov EAX, 0338h[ESP]
add EAX, 01770h
mov 4[ESP], EAX
xor EAX, EAX
lea EDI, 014h[ESP]
rep
stosd
mov EAX, 4[ESP]
mov ECX, 064h
xor EDX, EDX
div ECX
xor EAX, EAX
mov dword ptr 014h[EDX*4][ESP], 1
pop EDI
add ESP, 0330h
ret
-----------------------
Value range propagation is able to tell that the value of "a % 100" can't be
outside the 0..200 bounds of the array, so there is no point in performing the
bound test even in nonrelease mode.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list