<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Dead Code Elimination Regression at -O3 (trunk vs 13.0.0)"
   href="https://bugs.llvm.org/show_bug.cgi?id=52253">52253</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Dead Code Elimination Regression at -O3 (trunk vs 13.0.0)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>theodort@inf.ethz.ch
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>cat test.c
void foo(void);

static int c, d;
static char e, f;
static char a(char h, int i) { return h ? h : h << i; }

int main() {
  int j = 1;
  for (; d < 1; d++) {
    f = c;
    if ((c = f + 979) ^ a(j, 1)) {
      a(0, 0);
      j = e;
    } else
      foo();
  }
}

13.0.0 at -O3 can eliminate the call to foo but trunk cannot:

clang-13 -O3 -S -o /dev/stdout test.c 
...
main:                                   # @main
        .cfi_startproc
# %bb.0:
        movl    d(%rip), %eax
        testl   %eax, %eax
        jle     .LBB0_1
# %bb.9:
        xorl    %eax, %eax
        retq
.LBB0_1:
        movl    c(%rip), %ecx
        movl    $1, %esi
        subl    %eax, %esi
        movl    %eax, %edx
        negl    %edx
        andl    $3, %esi
        je      .LBB0_2
# %bb.3:
        negl    %esi
        xorl    %edi, %edi
        .p2align        4, 0x90
.LBB0_4:                                # =>This Inner Loop Header: Depth=1
        movsbl  %cl, %ecx
        addl    $979, %ecx                      # imm = 0x3D3
        addl    $-1, %edi
        cmpl    %edi, %esi
        jne     .LBB0_4
# %bb.5:
        subl    %edi, %eax
        movl    %eax, %esi
        cmpl    $3, %edx
        jb      .LBB0_8
        .p2align        4, 0x90
.LBB0_7:                                # =>This Inner Loop Header: Depth=1
        addb    $121, %cl
        movsbl  %cl, %ecx
        addl    $979, %ecx                      # imm = 0x3D3
        leal    4(%rax), %esi
        cmpl    $-3, %eax
        movl    %esi, %eax
        jl      .LBB0_7
.LBB0_8:
        movl    %ecx, c(%rip)
        movl    %esi, d(%rip)
        xorl    %eax, %eax
        retq
.LBB0_2:
                                        # implicit-def: $esi
        cmpl    $3, %edx
        jae     .LBB0_7
        jmp     .LBB0_8

clang-trunk -O3 -S -o /dev/stdout test.c
...
main:                                   # @main
        .cfi_startproc
# %bb.0:
        pushq   %rbx
        .cfi_def_cfa_offset 16
        .cfi_offset %rbx, -16
        movl    d(%rip), %esi
        testl   %esi, %esi
        jle     .LBB0_1
.LBB0_5:
        xorl    %eax, %eax
        popq    %rbx
        .cfi_def_cfa_offset 8
        retq
.LBB0_1:
        .cfi_def_cfa_offset 16
        movl    $1, %ebx
        movl    c(%rip), %edx
        jmp     .LBB0_2
        .p2align        4, 0x90
.LBB0_4:                                #   in Loop: Header=BB0_2 Depth=1
        leal    1(%rsi), %eax
        movl    %eax, d(%rip)
        movl    %ecx, %ebx
        testl   %esi, %esi
        movl    %eax, %esi
        jns     .LBB0_5
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
        movsbl  %dl, %edx
        addl    $979, %edx                      # imm = 0x3D3
        testb   %bl, %bl
        sete    %cl
        movl    %ebx, %eax
        shlb    %cl, %al
        movl    %edx, c(%rip)
        movzbl  %al, %eax
        xorl    %ecx, %ecx
        cmpl    %eax, %edx
        jne     .LBB0_4
# %bb.3:                                #   in Loop: Header=BB0_2 Depth=1
        callq   foo
        movl    c(%rip), %edx
        movl    d(%rip), %esi
        movl    %ebx, %ecx
        jmp     .LBB0_4


clang-trunk -v
clang version 14.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
7ff4f48adb26429086d6fd85a14336e57cd340dc)
Target: x86_64-unknown-linux-gnu
Thread model: posix

This was introduced by
<a href="https://github.com/llvm/llvm-project/commit/1f3e35b6d165715ec7bf7ba80d5b982719c7752a">https://github.com/llvm/llvm-project/commit/1f3e35b6d165715ec7bf7ba80d5b982719c7752a</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>