| Issue |
64680
|
| Summary |
Dead Code Elimination Regression at -O3 (trunk vs. llvmorg-16.0.6)
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
SvenjaScherrer
|
```c
static int a, d;
static int *b[3];
static int **c = &b[2];
void foo(void);
void bar20_(void);
int main() {
for (; a < 3; ++a) {
int e = 8;
bar20_();
if (!e)
foo();
*c = &e;
*c = &d;
}
}
```
`clang-01dcad040641 (trunk) -O3` cannot eliminate the call to foo but `clang-llvmorg-16.0.6 -O3` can.
-----------------------------------------------------------------------
`clang-01dcad04064182155d5568a464dfea95ba567764 -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
@b = internal unnamed_addr global [3 x ptr] zeroinitializer, align 16
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
%1 = alloca i32, align 4
%2 = load i32, ptr @a, align 4, !tbaa !5
%3 = icmp slt i32 %2, 3
br i1 %3, label %4, label %12
4: ; preds = %0, %8
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
store i32 8, ptr %1, align 4, !tbaa !5
call void @bar20_() #3
%5 = load i32, ptr %1, align 4, !tbaa !5
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %4
call void @foo() #3
br label %8
8: ; preds = %7, %4
store ptr %1, ptr getelementptr inbounds ([3 x ptr], ptr @b, i64 0, i64 2), align 16, !tbaa !9
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
%9 = load i32, ptr @a, align 4, !tbaa !5
%10 = add nsw i32 %9, 1
store i32 %10, ptr @a, align 4, !tbaa !5
%11 = icmp slt i32 %9, 2
br i1 %11, label %4, label %12, !llvm.loop !11
12: ; preds = %8, %0
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 @bar20_() local_unnamed_addr #2
declare void @foo() 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 ([email protected]:llvm/llvm-project.git 01dcad04064182155d5568a464dfea95ba567764)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"
@a = internal unnamed_addr global i32 0, align 4
@d = internal global i32 0, align 4
@b = internal unnamed_addr global [3 x ptr] zeroinitializer, align 16
; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
%1 = load i32, ptr @a, align 4, !tbaa !5
%2 = icmp slt i32 %1, 3
br i1 %2, label %3, label %7
3: ; preds = %0, %3
tail call void @bar20_() #2
store ptr @d, ptr getelementptr inbounds ([3 x ptr], ptr @b, i64 0, i64 2), align 16, !tbaa !9
%4 = load i32, ptr @a, align 4, !tbaa !5
%5 = add nsw i32 %4, 1
store i32 %5, ptr @a, align 4, !tbaa !5
%6 = icmp slt i32 %4, 2
br i1 %6, label %3, label %7, !llvm.loop !11
7: ; preds = %3, %0
ret i32 0
}
declare void @bar20_() 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 ([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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
```
</p></details>
-----------------------------------------------------------------------
Bisects to d94e8479fcd7cd57fa9c6f3f3aa24d2ad3e11d89
Committed by: @fhahn
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs