<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64641>64641</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 a, b, c;
static int *e = &a, *f = &a;
void bar25_(void);
void foo(void);
static void d() { *f = 1; }
int main() {
{
int g = 0;
char h;
d();
b = b - 3;
for (; b;) {
if (g)
foo();
int *i[] = {&g, &g};
h = 1;
for (; h >= 0; h--) {
if (h)
bar25_();
c |= i[h] != 0;
if (*e)
break;
}
}
}
}
```
`clang-f36e909da037 (trunk) -O3` cannot eliminate the call to foo but `clang-llvmorg-16.0.6 -O3` can.
-----------------------------------------------------------------------
`clang-f36e909da03767c317eaa5ded9abbf3214299ff5 -O3 case.c -S -emit-llvm -o case.suc20p.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 i32 0, align 4
@c = internal unnamed_addr global i32 0, align 4
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
%1 = alloca i32, align 4
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
store i32 0, ptr %1, align 4, !tbaa !5
%2 = load i32, ptr @b, align 4, !tbaa !5
%3 = add nsw i32 %2, -3
store i32 %3, ptr @b, align 4, !tbaa !5
%4 = icmp eq i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %0
%6 = load i32, ptr %1, align 4, !tbaa !5
%7 = icmp eq i32 %6, 0
br label %8
8: ; preds = %5, %10
br i1 %7, label %10, label %9
9: ; preds = %8
tail call void @foo() #3
br label %10
10: ; preds = %9, %8
tail call void @bar25_() #3
%11 = load i32, ptr @c, align 4, !tbaa !5
%12 = or i32 %11, 1
store i32 %12, ptr @c, align 4, !tbaa !5
%13 = load i32, ptr @b, align 4, !tbaa !5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %8, !llvm.loop !9
15: ; preds = %10, %0
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
ret i32 0
}
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
declare void @foo() local_unnamed_addr #2
declare void @bar25_() local_unnamed_addr #2
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { 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 f36e909da03767c317eaa5ded9abbf3214299ff5)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
```
</p></details>
-----------------------------------------------------------------------
`clang-af2ed9f794c422923414d162dd1f48d986e2d6e3 -O3 case.c -S -emit-llvm -o case.suc20p.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 i32 0, align 4
@c = internal unnamed_addr global i32 0, align 4
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
%1 = load i32, ptr @b, align 4, !tbaa !5
%2 = add nsw i32 %1, -3
store i32 %2, ptr @b, align 4, !tbaa !5
%3 = icmp eq i32 %2, 0
br i1 %3, label %9, label %4
4: ; preds = %0, %4
tail call void @bar25_() #2
%5 = load i32, ptr @c, align 4, !tbaa !5
%6 = or i32 %5, 1
store i32 %6, ptr @c, align 4, !tbaa !5
%7 = load i32, ptr @b, align 4, !tbaa !5
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %4, !llvm.loop !9
9: ; preds = %4, %0
ret i32 0
}
declare void @bar25_() 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
```
</p></details>
-----------------------------------------------------------------------
Bisects to 849d01bf3d97d05074a00d78903d782b2ac804f8
Committed by: @caojoshua
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsGltv4yr619AX5Ag-fH3IQ5NOpZF2tasz-15hgx1mbMhi3Mv--hW-xHaS9rQz52hHeyaqEgzf_QYfLm9bVWkptyjaoejuhnfuYOz2y6PUX_mX4iCtlfYmN-Jli2Iy_BWI3CFy2zruVIGVdpgj2OPcfxWI7S6WEdxKjNgdRhD3oAhuy3liwng0SuCcW4geEKT-CUG2Xi2NubI0suohBIIUQYZRspvZUMR2GCV3A7gXqeFKz5DDPF4OcS951aOTEyc_Xxy4xYd5auS4gsl7vBwHmK3mS2OxB2c7nPuFNfuea-kBKk9wmB1UPmeAJ8OqwXGDNZMdgrgaLBxXXuE1zuFkjeXsQigP8GlSGR-C4IqEk4yHWcbT5-S9S3kxLjBK9p64l_nQCw300r4zBx8315hYyb-doZycu344jebBFMXj4zRZ1FxXQclimZFMcMISL4Gznf7mbRD8g6GY4IJrbRyWtWqU5k5id5C44HWNnfGewnnn8IlaXT82xlYBjTdkEy9obJbMgz_m87v6xEnBaCI5j4QUGc_zkgENIcvKMvKy4YK3clPg4AsOZKNcLz4OzDDfdgWQ46auZ9OxvZCOq7odgmbfdk3D7Qtinz41yjkp8OffENsjuJ9XENsf_c9a2OGvrifCO_x3I7pafh7jGpJBNgTJmPGms4V8KFUtNW-m4gITFAxQjttKOiy44zV_Md41A5wMGsRuZXCEhCB2y6D_8o90_ehHcdh_BWoalKlHopAGOvWDeMKJw-AL9WG75u-sOtYnGZ_T-CEOg05_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