| Issue |
64642
|
| Summary |
Dead Code Elimination Regression at -O3 (trunk vs. llvmorg-16.0.6)
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
SvenjaScherrer
|
```c
static int a, b;
static int *f = &b;
void foo(void);
static void c();
static void d();
static void e() {
if (b)
foo();
c();
}
static void c(unsigned g) {
g = -17;
for (; g >= 5; g = g + 9)
d();
}
static void d() {
--a;
*f &= 0 == a;
}
int main() { e(); }
```
`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.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
@a = 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 = icmp eq i32 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %0
tail call void @foo() #2
%4 = load i32, ptr @b, align 4, !tbaa !5
br label %5
5: ; preds = %0, %3
%6 = phi i32 [ %4, %3 ], [ 0, %0 ]
%7 = load i32, ptr @a, align 4, !tbaa !5
%8 = icmp eq i32 %7, 1
%9 = zext i1 %8 to i32
%10 = and i32 %6, %9
%11 = add i32 %7, -2
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
%14 = and i32 %10, %13
store i32 %11, ptr @a, align 4, !tbaa !5
store i32 %14, ptr @b, align 4, !tbaa !5
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 f36e909da03767c317eaa5ded9abbf3214299ff5)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
```
</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"
@a = 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 @a, align 4, !tbaa !5
%2 = add i32 %1, -2
store i32 %2, ptr @a, align 4, !tbaa !5
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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
```
</p></details>
-----------------------------------------------------------------------
Bisects to b9808e5660f5fe9e7414c0c0b93acd899235471c
Committed by: @nikic
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs