safety and auto vectorization

Bruce Carneal bcarneal at gmail.com
Sun Aug 2 17:31:45 UTC 2020


import std;

void f0(int[] a, int[] b, int[] dst) @safe {
     dst[] = a[] + b[];
}

void f1(int[] a, int[] b, int[] dst) @trusted {
     const minLen = min(a.length, b.length, dst.length);
     dst[0..minLen] = a[0..minLen] + b[0..minLen];
     assert(dst.length == minLen);
}

I was surprised that f0 ran just fine with a.length and b.length 
geq dst.length.  Is that a bug or a feature?

Assuming it's a feature, are f0 and f1 morally equivalent?  I ask 
because f1 auto-vectorizes in ldc while f0 does not.  Not sure 
why.  As a guess I'd say that the front end doesn't hoist bounds 
checks in f0 or at least doesn't convey the info to the back end 
in a comprehensible fashion.  Non-guesses welcome.






More information about the Digitalmars-d-learn mailing list