Dynamic array comparison optimization: check for equal pointers?

Steven Schveighoffer schveiguy at gmail.com
Tue Jun 2 22:44:24 UTC 2020


On 6/2/20 6:20 PM, Stanislav Blinov wrote:
> On Tuesday, 2 June 2020 at 22:01:20 UTC, Johan wrote:
>> On Tuesday, 2 June 2020 at 20:54:39 UTC, Stanislav Blinov wrote:
> 
>>> That's, worst case, two branches and a scan, and best case one branch 
>>> which may or may not be slower than the actual scan.
>>
>> The "actual scan" is a function call, which will be super slow (note 
>> that in druntime's implementation it cannot be optimized to a tail 
>> call) compared to the comparison and early return.
> 
> LDC (and I'm assuming GDC as well) is well aware of memcmp, it should 
> not be a function call. At the very least in -Ox builds.

Let's assume LDC knows how to optimize this. How do you think it would 
do so? I'd imagine very similarly to how Johan wrote it.

What makes you think LDC can't optimize out the check if there's a 
better way? Then the check is there in case the optimizer you are 
dealing with is going to call an opaque memcmp in all cases.

-Steve


More information about the Digitalmars-d mailing list