After https://github.com/llvm/llvm-project/pull/153643, there may be a BranchOnCond with constant condition in the entry block. Simplify those in removeBranchOnConst. This removes a number of redundant conditional branch from entry blocks. In some cases, it may also make the original scalar loop unreachable, because we know it will never execute. In that case, we need to remove the loop from LoopInfo, because all unreachable blocks may dominate each other, making LoopInfo invalid. In those cases, we can also completely remove the loop, for which I'll share a follow-up patch. Depends on https://github.com/llvm/llvm-project/pull/153643. PR: https://github.com/llvm/llvm-project/pull/154510
73 lines
3.4 KiB
LLVM
73 lines
3.4 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
|
|
; RUN: opt -S < %s -passes=loop-vectorize -force-vector-width=2 | FileCheck %s
|
|
;; Tests that when we simplify the loop-exit branch condition, we preserve the
|
|
;; !dbg attachment for all loop-exit branches.
|
|
|
|
define i32 @foo(ptr %p) {
|
|
; CHECK-LABEL: define i32 @foo(
|
|
; CHECK-SAME: ptr [[P:%.*]]) {
|
|
; CHECK-NEXT: [[ENTRY:.*:]]
|
|
; CHECK-NEXT: br label %[[VECTOR_PH:.*]]
|
|
; CHECK: [[VECTOR_PH]]:
|
|
; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
|
|
; CHECK: [[VECTOR_BODY]]:
|
|
; CHECK-NEXT: store i8 0, ptr [[P]], align 1, !dbg [[DBG3:![0-9]+]]
|
|
; CHECK-NEXT: br label %[[MIDDLE_BLOCK:.*]]
|
|
; CHECK: [[MIDDLE_BLOCK]]:
|
|
; CHECK-NEXT: br label %[[EXIT:.*]], !dbg [[DBG3]]
|
|
; CHECK: [[SCALAR_PH:.*]]:
|
|
; CHECK-NEXT: br label %[[LOOP:.*]]
|
|
; CHECK: [[LOOP]]:
|
|
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], %[[LOOP]] ], [ 0, %[[SCALAR_PH]] ], !dbg [[DBG7:![0-9]+]]
|
|
; CHECK-NEXT: [[CONV:%.*]] = trunc i64 0 to i8, !dbg [[DBG8:![0-9]+]]
|
|
; CHECK-NEXT: store i8 [[CONV]], ptr [[P]], align 1, !dbg [[DBG3]]
|
|
; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1, !dbg [[DBG9:![0-9]+]]
|
|
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 1, !dbg [[DBG10:![0-9]+]]
|
|
; CHECK-NEXT: br i1 [[EXITCOND]], label %[[EXIT]], label %[[LOOP]], !dbg [[DBG11:![0-9]+]]
|
|
; CHECK: [[EXIT]]:
|
|
; CHECK-NEXT: ret i32 0
|
|
;
|
|
entry:
|
|
br label %loop
|
|
|
|
loop: ; preds = %loop, %entry
|
|
%iv = phi i64 [ %iv.next, %loop ], [ 0, %entry ], !dbg !3
|
|
%conv = trunc i64 0 to i8, !dbg !4
|
|
store i8 %conv, ptr %p, align 1, !dbg !5
|
|
%iv.next = add i64 %iv, 1, !dbg !6
|
|
%exitcond = icmp eq i64 %iv, 1, !dbg !7
|
|
br i1 %exitcond, label %exit, label %loop, !dbg !8
|
|
|
|
exit: ; preds = %loop
|
|
ret i32 0
|
|
}
|
|
|
|
!llvm.dbg.cu = !{!0}
|
|
!llvm.module.flags = !{!2}
|
|
|
|
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git")
|
|
!1 = !DIFile(filename: "test.cpp", directory: "/")
|
|
!2 = !{i32 2, !"Debug Info Version", i32 3}
|
|
!3 = !DILocation(line: 4, scope: !9)
|
|
!4 = !DILocation(line: 5, scope: !9)
|
|
!5 = !DILocation(line: 6, scope: !9)
|
|
!6 = !DILocation(line: 7, scope: !9)
|
|
!7 = !DILocation(line: 8, scope: !9)
|
|
!8 = !DILocation(line: 9, scope: !9)
|
|
!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 11, type: !10, unit: !0, retainedNodes: !11)
|
|
!10 = distinct !DISubroutineType(types: !11)
|
|
!11 = !{}
|
|
;.
|
|
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
|
|
; CHECK: [[META1]] = !DIFile(filename: "{{.*}}test.cpp", directory: {{.*}})
|
|
; CHECK: [[DBG3]] = !DILocation(line: 6, scope: [[META4:![0-9]+]])
|
|
; CHECK: [[META4]] = distinct !DISubprogram(name: "foo", scope: [[META1]], file: [[META1]], line: 11, type: [[META5:![0-9]+]], spFlags: DISPFlagDefinition, unit: [[META0]], retainedNodes: [[META6:![0-9]+]])
|
|
; CHECK: [[META5]] = distinct !DISubroutineType(types: [[META6]])
|
|
; CHECK: [[META6]] = !{}
|
|
; CHECK: [[DBG7]] = !DILocation(line: 4, scope: [[META4]])
|
|
; CHECK: [[DBG8]] = !DILocation(line: 5, scope: [[META4]])
|
|
; CHECK: [[DBG9]] = !DILocation(line: 7, scope: [[META4]])
|
|
; CHECK: [[DBG10]] = !DILocation(line: 8, scope: [[META4]])
|
|
; CHECK: [[DBG11]] = !DILocation(line: 9, scope: [[META4]])
|
|
;.
|