<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56119>56119</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Dead Code Elimination Regression at -Oz (trunk vs. 14.0.4) 222879
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Quarub
</td>
</tr>
</table>
<pre>
`cat case.c #222879`
[case.txt](https://github.com/llvm/llvm-project/files/8935516/case.txt)
```c
struct a {
int b;
};
int c;
void foo();
static int d(struct a e) {
char f;
long g = -1L;
unsigned char h = e.b, i = g;
f = h % i;
if (7 == f)
foo();
return c;
}
int main() {
struct a j = {8}, k = {1};
d(j);
d(k);
}
```
`llvm-41455dd1dcbbdf2f5fb34cc1f248bfd8d947dc52 (trunk) -Oz` can not eliminate `foo` but `llvm-llvmorg-14.0.4 -Oz` can.
Target: `x86_64-unknown-linux-gnu`
------------------------------------------------
`llvm-41455dd1dcbbdf2f5fb34cc1f248bfd8d947dc52 (trunk) -Oz [-emit-llvm] -S -o /dev/stdout case.c`
<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"
@c = dso_local local_unnamed_addr global i32 0, align 4
; Function Attrs: minsize nounwind optsize uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
tail call fastcc void @d(i32 8) #2
tail call fastcc void @d(i32 1) #2
ret i32 0
}
; Function Attrs: minsize nounwind optsize uwtable
define internal fastcc void @d(i32 %0) unnamed_addr #0 {
%2 = freeze i32 %0
%3 = trunc i32 %2 to i8
%4 = icmp ne i8 %3, -1
%5 = and i32 %2, 255
%6 = icmp eq i32 %5, 7
%7 = and i1 %4, %6
br i1 %7, label %8, label %9
8: ; preds = %1
tail call void (...) @foo() #3
br label %9
9: ; preds = %8, %1
ret void
}
; Function Attrs: minsize optsize
declare void @foo(...) local_unnamed_addr #1
attributes #0 = { minsize nounwind optsize uwtable "frame-pointer"="none" "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 = { minsize optsize "frame-pointer"="none" "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 = { minsize optsize }
attributes #3 = { minsize nounwind optsize }
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git 41455dd1dcbbdf2f5fb34cc1f248bfd8d947dc52)"}
```
</p></details>
------------------------------------------------
`llvm-llvmorg-14.0.4 -Oz [-emit-llvm] -S -o /dev/stdout case.c`
<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"
@c = dso_local local_unnamed_addr global i32 0, align 4
; Function Attrs: minsize mustprogress nofree norecurse nosync nounwind optsize readnone uwtable willreturn
define dso_local i32 @main() local_unnamed_addr #0 {
ret i32 0
}
attributes #0 = { minsize mustprogress nofree norecurse nosync nounwind optsize readnone uwtable willreturn "frame-pointer"="none" "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}
!llvm.ident = !{!2}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 1}
!2 = !{!"clang version 14.0.4 (https://github.com/llvm/llvm-project.git 29f1039a7285a5c3a9c353d054140bf2556d4c4d)"}
```
</p></details>
------------------------------------------------
### Bisection
Bisected to: d428f09b2c9d49f6a328ef636c02305a8be4ab61
Committed by: @rotateright
------------------------------------------------
`llvm-d428f09b2c9d49f6a328ef636c02305a8be4ab61 -Oz [-emit-llvm] -S -o /dev/stdout case.c`
<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"
@c = dso_local local_unnamed_addr global i32 0, align 4
; Function Attrs: minsize nounwind optsize uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
tail call fastcc void @d(i32 8) #2
tail call fastcc void @d(i32 1) #2
ret i32 0
}
; Function Attrs: minsize nounwind optsize uwtable
define internal fastcc void @d(i32 %0) unnamed_addr #0 {
%2 = freeze i32 %0
%3 = trunc i32 %2 to i8
%4 = icmp ne i8 %3, -1
%5 = and i32 %2, 255
%6 = icmp eq i32 %5, 7
%7 = and i1 %4, %6
br i1 %7, label %8, label %9
8: ; preds = %1
tail call void (...) @foo() #3
br label %9
9: ; preds = %8, %1
ret void
}
; Function Attrs: minsize optsize
declare void @foo(...) local_unnamed_addr #1
attributes #0 = { minsize nounwind optsize uwtable "frame-pointer"="none" "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 = { minsize optsize "frame-pointer"="none" "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 = { minsize optsize }
attributes #3 = { minsize nounwind optsize }
!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project d428f09b2c9d49f6a328ef636c02305a8be4ab61)"}
```
</p></details>
------------------------------------------------
Previous commit: 8cb7a873ab8568acfbfd6c27a927d924cc994017
`llvm-8cb7a873ab8568acfbfd6c27a927d924cc994017 -Oz [-emit-llvm] -S -o /dev/stdout case.c`
<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"
@c = dso_local local_unnamed_addr global i32 0, align 4
; Function Attrs: minsize mustprogress nofree norecurse nosync nounwind optsize readnone willreturn uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
ret i32 0
}
attributes #0 = { minsize mustprogress nofree norecurse nosync nounwind optsize readnone willreturn uwtable "frame-pointer"="none" "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 7, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project 8cb7a873ab8568acfbfd6c27a927d924cc994017)"}
```
</p></details>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztGtlu2zjwa5wXQoZI3Q9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