<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64643>64643</a>
        </td>
    </tr>

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

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          SvenjaScherrer
      </td>
    </tr>
</table>

<pre>
    ```c
static char c = 10;
static int d, e;
static short f = 7;
void foo(void);
char(a)();
static short(b)(short g) { return g; }
static short h(int g) {
  b(2);
  if (!g)
    foo();
  c = 0;
  for (; c; c = a())
    ;
  if (e)
    return 0;
i:
  for (f = 0;;)
    if (d)
      goto i;
}
int main() {
  if (b(1) & 1)
    d = 4;
  e = d;
 h(f);
}
```

`clang-bd7c6e3c48e9 (trunk) -O3` cannot eliminate the call to foo but `clang-llvmorg-16.0.6 -O3` can.

-----------------------------------------------------------------------

`clang-bd7c6e3c48e9281ceeaae3a93cc493b35a3c9f29 -O3 case.c -S -emit-llvm -o case.ll`
<details ><summary>Emitted IR</summary><p>

```ll
; ModuleID = 'case.c'
source_filename = "case.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@f = internal unnamed_addr global i1 false, align 2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
  %1 = load i1, ptr @f, align 2
  br i1 %1, label %2, label %3

2: ; preds = %0
  tail call void @foo() #2
  br label %3

3:                                                ; preds = %0, %2
  ret i32 0
}

declare void @foo() local_unnamed_addr #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 18.0.0 (git@github.com:llvm/llvm-project.git bd7c6e3c48e9281ceeaae3a93cc493b35a3c9f29)"}
```


</p></details>

-----------------------------------------------------------------------

`clang-af2ed9f794c422923414d162dd1f48d986e2d6e3 -O3 case.c -S -emit-llvm -o case.ll`
<details ><summary>Emitted IR</summary><p>

```ll
; ModuleID = 'case.c'
source_filename = "case.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
  ret i32 0
}

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 16.0.6 (git@github.com:llvm/llvm-project.git 7cbf1a2591520c2491aa35339f227775f4d3adf6)"}
```


</p></details>

-----------------------------------------------------------------------

Bisects to 7553bad1ac619d5de72489ec06b63a2ace356c22
Committed by: @nikic
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWN2O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