<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64679>64679</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 int b;
static short c = 5, e;
static char ah, am, f;
void foo(void);
void bar155_(void);
void bar149_(void);
static short(a)(short g, short i) { return g + i; }
static short(d)(short g, short i) { return g - i; }
static void ab() { b = 2905239065; }
static void h(int g) {
int ar = g;
ab();
am = 0;
for (; am > -7; am = d(am, 6)) {
if (ar)
bar155_();
if (ar < a(g, 0 > b))
;
else
continue;
e = 61690;
c = ah;
ar = e;
}
if (!ar)
bar149_();
}
int main() {
f = b;
h(f);
if (c)
foo();
}
```
`clang-87a8e2247536 (trunk) -O3` cannot eliminate the call to foo but `clang-llvmorg-16.0.6 -O3` can.
-----------------------------------------------------------------------
`clang-87a8e22475364b79d43515159de1b7947554d868 -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"
@b = internal unnamed_addr global i1 false, align 4
@c = internal unnamed_addr global i1 false, align 2
@am = internal unnamed_addr global i8 0, align 1
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
%1 = load i1, ptr @b, align 4
%2 = select i1 %1, i32 25, i32 0
store i1 true, ptr @b, align 4
store i8 0, ptr @am, align 1, !tbaa !5
br label %3
3: ; preds = %22, %0
%4 = phi i8 [ %24, %22 ], [ 0, %0 ]
%5 = phi i32 [ -3846, %22 ], [ %2, %0 ]
%6 = icmp eq i32 %5, 0
%7 = sub nsw i32 %5, %2
br i1 %6, label %10, label %8
8: ; preds = %3
%9 = icmp slt i32 %7, 1
br label %17
10: ; preds = %3
%11 = icmp slt i32 %7, 1
br i1 %11, label %22, label %12
12: ; preds = %10, %12
%13 = phi i8 [ %14, %12 ], [ %4, %10 ]
%14 = add nsw i8 %13, -6
%15 = icmp ult i8 %13, -122
br i1 %15, label %12, label %16, !llvm.loop !8
16: ; preds = %12
store i8 %14, ptr @am, align 1, !tbaa !5
tail call void @bar149_() #2
br label %26
17: ; preds = %8, %19
tail call void @bar155_() #2
%18 = load i8, ptr @am, align 1, !tbaa !5
br i1 %9, label %22, label %19
19: ; preds = %17
%20 = add i8 %18, -6
store i8 %20, ptr @am, align 1, !tbaa !5
%21 = icmp ult i8 %18, -122
br i1 %21, label %17, label %26, !llvm.loop !8
22: ; preds = %17, %10
%23 = phi i8 [ %4, %10 ], [ %18, %17 ]
store i1 true, ptr @c, align 2
%24 = add i8 %23, -6
store i8 %24, ptr @am, align 1, !tbaa !5
%25 = icmp ult i8 %23, -122
br i1 %25, label %3, label %29, !llvm.loop !8
26: ; preds = %19, %16
%27 = load i1, ptr @c, align 2
br i1 %27, label %29, label %28
28: ; preds = %26
tail call void @foo() #2
br label %29
29: ; preds = %22, %28, %26
ret i32 0
}
declare void @foo() local_unnamed_addr #1
declare void @bar155_() local_unnamed_addr #1
declare void @bar149_() 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 87a8e22475364b79d43515159de1b7947554d868)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
```
</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"
@b = internal unnamed_addr global i1 false, align 4
@c = internal unnamed_addr global i1 false, align 2
@am = internal unnamed_addr global i8 0, align 1
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
%1 = load i1, ptr @b, align 4
store i1 true, ptr @b, align 4
store i8 0, ptr @am, align 1, !tbaa !5
br i1 %1, label %2, label %4
2: ; preds = %0
tail call void @bar155_() #2
%3 = load i8, ptr @am, align 1, !tbaa !5
br label %4
4: ; preds = %2, %0
%5 = phi i8 [ %3, %2 ], [ 0, %0 ]
store i1 true, ptr @c, align 2
%6 = add i8 %5, -6
store i8 %6, ptr @am, align 1, !tbaa !5
%7 = icmp ult i8 %5, -122
br i1 %7, label %8, label %13
8: ; preds = %4, %8
%9 = phi i8 [ %11, %8 ], [ %6, %4 ]
tail call void @bar155_() #2
%10 = load i8, ptr @am, align 1, !tbaa !5
store i1 true, ptr @c, align 2
%11 = add i8 %10, -6
store i8 %11, ptr @am, align 1, !tbaa !5
%12 = icmp ult i8 %10, -122
br i1 %12, label %8, label %13, !llvm.loop !8
13: ; preds = %8, %4
ret i32 0
}
declare void @bar155_() 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"="+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"="+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 16.0.6 (git@github.com:llvm/llvm-project.git 7cbf1a2591520c2491aa35339f227775f4d3adf6)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.peeled.count", i32 1}
```
</p></details>
-----------------------------------------------------------------------
Bisects to 0d95b20b63d7acc459dc0b2a7b2e4f9924c0adce
Committed by: @xortator
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsOllv4zjSv4Z5IWSIRep6yEPsdIABvg-7mN73gBIpmzM6vBSVpPfXL0jdtuy0k15gMZsgsCmyLtalqoJ506h9JeU9CrYoeLzjrTnU-v77i6z-4N-zg9Ra6ru0Fj_uUeh3_xnyH5H_0BhuVIZVZXCK6Hax2RxqbXCGEX3EAYIdlqcQ2YFrzA_2jJf2Mx8hXmolcF7XCGK7RJAsj1KuSRA8XztmydrxXDgEMbdnEHey7q0M3VIhSDCKtlhL0-oK7zGCLVaIbjGKHldJiZ8m5a0TcpLzFEE8YKROeZD4AdDED4OLWAcEsTXCvsfsILAzD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