Issue 64643
Summary Dead Code Elimination Regression at -O3 (trunk vs. llvmorg-16.0.6)
Labels new issue
Assignees
Reporter SvenjaScherrer
    ```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 ([email protected]: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 ([email protected]:llvm/llvm-project.git 7cbf1a2591520c2491aa35339f227775f4d3adf6)"}
```


</p></details>

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

Bisects to 7553bad1ac619d5de72489ec06b63a2ace356c22
Committed by: @nikic
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to