[Issue 14436] Optimizer fails to remove comparison loop when comparing array against null

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Apr 16 00:36:32 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14436

--- Comment #5 from Marc Schütz <schuetzm at gmx.net> ---
(In reply to yebblies from comment #4)
> By empty array do you mean empty array literal?
> 
> eg assert(x != []);

Yes, it should read "empty array [literal] or string literal".

In fact, the code generated for `int[]` instead of `string` looks even worse;
there is a "call" instruction in it:

0000000000000000 <_D2xx7isEmptyFAiZb>:
   0:    55                       push   %rbp
   1:    48 8b ec                 mov    %rsp,%rbp
   4:    48 83 ec 30              sub    $0x30,%rsp
   8:    48 89 7d f0              mov    %rdi,-0x10(%rbp)
   c:    48 89 75 f8              mov    %rsi,-0x8(%rbp)
  10:    48 31 f6                 xor    %rsi,%rsi
  13:    48 bf 00 00 00 00 00     movabs $0x0,%rdi
  1a:    00 00 00 
  1d:    e8 00 00 00 00           callq  22 <_D2xx7isEmptyFAiZb+0x22>
  22:    48 89 c1                 mov    %rax,%rcx
  25:    48 31 c0                 xor    %rax,%rax
  28:    48 89 45 e0              mov    %rax,-0x20(%rbp)
  2c:    48 89 4d e8              mov    %rcx,-0x18(%rbp)
  30:    48 89 45 d0              mov    %rax,-0x30(%rbp)
  34:    48 89 4d d8              mov    %rcx,-0x28(%rbp)
  38:    48 8b 55 f0              mov    -0x10(%rbp),%rdx
  3c:    48 3b 55 e0              cmp    -0x20(%rbp),%rdx
  40:    75 1a                    jne    5c <_D2xx7isEmptyFAiZb+0x5c>
  42:    48 85 d2                 test   %rdx,%rdx
  45:    74 19                    je     60 <_D2xx7isEmptyFAiZb+0x60>
  47:    48 8b 75 f8              mov    -0x8(%rbp),%rsi
  4b:    48 8b 7d d8              mov    -0x28(%rbp),%rdi
  4f:    48 89 d1                 mov    %rdx,%rcx
  52:    48 c1 e1 02              shl    $0x2,%rcx
  56:    33 c0                    xor    %eax,%eax
  58:    f3 a6                    repz cmpsb %es:(%rdi),%ds:(%rsi)
  5a:    74 04                    je     60 <_D2xx7isEmptyFAiZb+0x60>
  5c:    31 c0                    xor    %eax,%eax
  5e:    eb 05                    jmp    65 <_D2xx7isEmptyFAiZb+0x65>
  60:    b8 01 00 00 00           mov    $0x1,%eax
  65:    48 8b e5                 mov    %rbp,%rsp
  68:    5d                       pop    %rbp
  69:    c3                       retq

--


More information about the Digitalmars-d-bugs mailing list