On Wednesday, 23 October 2019 at 11:20:59 UTC, Per Nordlöw wrote:
Does DMD/LDC avoid range-checking in slice-expressions such as
the one in my array-overload of `startsWith` defined as
bool startsWith(T)(scope const(T)[] haystack,
scope const(T)[] needle)
{
if (haystack.length >= needle.length)
{
return haystack[0 .. needle.length] == needle; // is
slice range checking avoid here?
}
return false;
}
///
@safe pure nothrow @nogc unittest
{
auto x = "beta version";
assert(x.startsWith("beta"));
}
when building in release mode?
I remember a DMD pull from Ian Buclaw that enabled some eliding
but I don't remember if it includes the case above.
How can I investigate the codegen myself here?
I remember in some video Chandler Carruth said that value range
propagation across function boundary was implemented in llvm but
later removed because it produced no performance improvement for
C and C++ code. I wonder how it fare when used on D code.