ldc doesn't elide bounds check
kinke
noone at nowhere.com
Wed Mar 7 19:57:02 UTC 2018
On Monday, 5 March 2018 at 19:36:20 UTC, Kagamin wrote:
> void f(byte[] a, byte[] b)
> {
> if(a.length<b.length)b=b[0..a.length];
> foreach(i,c;b)
> {
> a[i]=c;
> if(c==10)break;
> }
> }
> void g(ulong a, ulong b)
> {
> if(a<b)b=a;
> foreach(i;0..b)
> {
> assert(i<=a);
> if(i==10)break;
> }
> }
>
> In the function f the code for assert failure is retained, but
> in the function g it disappears at optimization levels -Os and
> above. Is it just me is there some limit for the optimizer?
Thx for noticing; I filed an LDC issue about it
(https://github.com/ldc-developers/ldc/issues/2607), although gcc
and clang are also unable to optimize away these checks for
analogous C code: https://godbolt.org/g/AfyMJM
More information about the digitalmars-d-ldc
mailing list