<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54980>54980</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Dead Code Elimination Regression at -O1 (trunk vs. 14.0.0)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
thetheodor
</td>
</tr>
</table>
<pre>
`cat case.c`
```c
static int a, c;
static int *b = &a;
void bar126_(void);
void foo();
int main() {
char f = 0;
int g = *b;
for (; f <= 0; f = 1) {
int i = 0;
if (c)
break;
if (f)
foo();
if (a)
bar126_();
}
b = &c;
}
```
`clang-084ad1ebeee2af9f7a9b464a346a7ca51d6f83dc (trunk) -O1` can not eliminate `foo` but `clang-14.0.0 -O1` can.
Target: `x86_64-unknown-linux-gnu`
------------------------------------------------
`clang-084ad1ebeee2af9f7a9b464a346a7ca51d6f83dc (trunk) -O1 [-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"
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
br label %1
1: ; preds = %5, %0
%2 = phi i1 [ false, %0 ], [ true, %5 ]
%3 = phi i1 [ true, %0 ], [ false, %5 ]
br i1 %2, label %7, label %4
4: ; preds = %1
br i1 %3, label %5, label %6
5: ; preds = %4, %6
br label %1, !llvm.loop !5
6: ; preds = %4
call void (...) @foo() #2
br label %5
7: ; preds = %1
ret i32 0
}
declare void @foo(...) local_unnamed_addr #1
attributes #0 = { nounwind 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 = { "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 = { nounwind }
!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 084ad1ebeee2af9f7a9b464a346a7ca51d6f83dc)"}
!5 = distinct !{!5, !6, !7}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!"llvm.loop.unroll.disable"}
```
</p></details>
<details ><summary>Reduced assembly</summary><p>
```asm
main: # @main
.cfi_startproc
# %bb.0:
pushq %rbp
.cfi_def_cfa_offset 16
pushq %rbx
.cfi_def_cfa_offset 24
pushq %rax
.cfi_def_cfa_offset 32
.cfi_offset %rbx, -24
.cfi_offset %rbp, -16
movb $1, %bl
xorl %ebp, %ebp
.p2align 4, 0x90
.LBB0_1: # =>This Inner Loop Header: Depth=1
testb $1, %bpl
jne .LBB0_4
# %bb.2: # in Loop: Header=BB0_1 Depth=1
movb $1, %bpl
testb $1, %bl
movl $0, %ebx
jne .LBB0_1
# %bb.3: # in Loop: Header=BB0_1 Depth=1
xorl %ebx, %ebx
xorl %eax, %eax
callq foo@PLT
jmp .LBB0_1
.LBB0_4:
xorl %eax, %eax
addq $8, %rsp
.cfi_def_cfa_offset 24
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
retq
.Lfunc_end0:
.size main, .Lfunc_end0-main
```
</p></details>
------------------------------------------------
`clang-14.0.0 -O1 [-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"
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
ret i32 0
}
attributes #0 = { nounwind 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}
!llvm.ident = !{!2}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 1}
!2 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project 329fda39c507e8740978d10458451dcdb21563be)"}
```
</p></details>
<details ><summary>Reduced assembly</summary><p>
```asm
main: # @main
.cfi_startproc
# %bb.0:
xorl %eax, %eax
retq
.Lfunc_end0:
.size main, .Lfunc_end0-main
```
</p></details>
------------------------------------------------
### Bisection
Bisected to: a1f442b2787ef63ba84c8627987cfebe3ba4f7f6
Committed by: @nikic
------------------------------------------------
`clang-a1f442b2787ef63ba84c8627987cfebe3ba4f7f6 -O1 [-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"
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
br label %1
1: ; preds = %5, %0
%2 = phi i1 [ false, %0 ], [ true, %5 ]
%3 = phi i1 [ true, %0 ], [ false, %5 ]
br i1 %2, label %7, label %4
4: ; preds = %1
br i1 %3, label %5, label %6
5: ; preds = %4, %6
br label %1, !llvm.loop !3
6: ; preds = %4
call void (...) @foo() #2
br label %5
7: ; preds = %1
ret i32 0
}
declare dso_local void @foo(...) local_unnamed_addr #1
attributes #0 = { nounwind 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 = { "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 = { nounwind }
!llvm.module.flags = !{!0, !1}
!llvm.ident = !{!2}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 2}
!2 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project a1f442b2787ef63ba84c8627987cfebe3ba4f7f6)"}
!3 = distinct !{!3, !4, !5}
!4 = !{!"llvm.loop.mustprogress"}
!5 = !{!"llvm.loop.unroll.disable"}
```
</p></details>
<details ><summary>Reduced assembly</summary><p>
```asm
main: # @main
.cfi_startproc
# %bb.0:
pushq %rbp
.cfi_def_cfa_offset 16
pushq %rbx
.cfi_def_cfa_offset 24
pushq %rax
.cfi_def_cfa_offset 32
.cfi_offset %rbx, -24
.cfi_offset %rbp, -16
movb $1, %bl
xorl %ebp, %ebp
.p2align 4, 0x90
.LBB0_1: # =>This Inner Loop Header: Depth=1
testb $1, %bpl
jne .LBB0_4
# %bb.2: # in Loop: Header=BB0_1 Depth=1
movb $1, %bpl
testb $1, %bl
movl $0, %ebx
jne .LBB0_1
# %bb.3: # in Loop: Header=BB0_1 Depth=1
xorl %ebx, %ebx
xorl %eax, %eax
callq foo
jmp .LBB0_1
.LBB0_4:
xorl %eax, %eax
addq $8, %rsp
.cfi_def_cfa_offset 24
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
retq
.Lfunc_end0:
.size main, .Lfunc_end0-main
```
</p></details>
------------------------------------------------
Previous commit: a84a8c937ba0455694ed59776b150b80a386d21b
`clang-a84a8c937ba0455694ed59776b150b80a386d21b -O1 [-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"
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
ret i32 0
}
attributes #0 = { nounwind 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}
!llvm.ident = !{!2}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 2}
!2 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project a84a8c937ba0455694ed59776b150b80a386d21b)"}
```
</p></details>
<details ><summary>Reduced assembly</summary><p>
```asm
main: # @main
.cfi_startproc
# %bb.0:
xorl %eax, %eax
retq
.Lfunc_end0:
.size main, .Lfunc_end0-main
```
</p></details>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztG9uOozb0azIvFgiMuT3kYTKZVVfaqqvtvkcGTOIut4LJZPr1PTaGQJJJM7vTdtQyigBzLj4-PjdzNFGZPC8XnhVTgWLaMDOGwcJaL6x7fYWh-sXduBFU8BjxQiC6wA8oXjirM8gC30do4azhwaMDQnfdlzxBEa1t7G0WOJDDBQ4HJAVOyxJA49fdVfLOKS86IFr4GopQvKM1StWc1kCElDBbLcl9NAKkZY0kF2elqB56Qs3DPmHfceJn_OF9KvnEUtbhHUJRzei3C3jpCd75Qo-49JTnoLMp_sJf94-D0o-7MkCHjRyGcUaLrWEFhCY2ixhjmKZh6tMwIh6hDvGoH1PXTrw0cJJYiiTqtvgmVWP8YgMDsJgCFaVALOM5L6hgCN7KNQEsagUaJr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