Issue 64617
Summary Dead Code Elimination Regression at -O2 (trunk vs. llvmorg-16.0.6)
Labels new issue
Assignees
Reporter SvenjaScherrer
    ```c
static int a;
void foo(void);
int main() {
  long b[7][10][1];
  int c = 0;
  for (; c < 7; c++) {
 a = 0;
    for (; a < 10; a++)
      b[c][a][0] = 10;
    if (!b[3][7][0])
      foo();
  }
}
```

`clang-f36e909da037 (trunk) -O2` cannot eliminate the call to foo but `clang-llvmorg-16.0.6 -O2` can.

-----------------------------------------------------------------------

`clang-f36e909da03767c317eaa5ded9abbf3214299ff5 -O2 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
  %1 = alloca [7 x [10 x [1 x i64]]], align 16
  call void @llvm.lifetime.start.p0(i64 560, ptr nonnull %1) #3
  %2 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 3, i64 7
  br label %3

3:                                                ; preds = %0, %18
  %4 = phi i64 [ 0, %0 ], [ %19, %18 ]
  %5 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 %4, i64 0
  store i64 10, ptr %5, align 16, !tbaa !5
  %6 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 %4, i64 1
  store i64 10, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 %4, i64 2
  store i64 10, ptr %7, align 16, !tbaa !5
  %8 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 %4, i64 3
  store i64 10, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 %4, i64 4
  store i64 10, ptr %9, align 16, !tbaa !5
  %10 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 %4, i64 5
  store i64 10, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 %4, i64 6
  store i64 10, ptr %11, align 16, !tbaa !5
  %12 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 %4, i64 7
  store i64 10, ptr %12, align 8, !tbaa !5
  %13 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 %4, i64 8
  store i64 10, ptr %13, align 16, !tbaa !5
  %14 = getelementptr inbounds [7 x [10 x [1 x i64]]], ptr %1, i64 0, i64 %4, i64 9
  store i64 10, ptr %14, align 8, !tbaa !5
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %17, label %18

17: ; preds = %3
  tail call void @foo() #3
  br label %18

18:                                               ; preds = %3, %17
  %19 = add nuw nsw i64 %4, 1
  %20 = icmp eq i64 %19, 7
 br i1 %20, label %21, label %3, !llvm.loop !9

21: ; preds = %18
  call void @llvm.lifetime.end.p0(i64 560, 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

; 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 f36e909da03767c317eaa5ded9abbf3214299ff5)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long", !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 -O2 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @main() local_unnamed_addr #0 {
  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)"}
```


</p></details>

-----------------------------------------------------------------------

Bisects to 4c2299003fe1910f729180f3e5e434045e533974
Committed by: @valerydmit

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to