1; RUN: opt -S -loop-reduce < %s | FileCheck %s 2; RUN: opt --try-experimental-debuginfo-iterators -S -loop-reduce < %s | FileCheck %s 3 4; During Loop Strength Reduce, if the terminating condition for the loop is not 5; immediately adjacent to the terminating branch and it has more than one use, 6; a clone of the condition will be created just before the terminating branch 7; and will be used as the branch condition. 8; The purpose of this test is to check that the presence of a debug intrinsic 9; between the condition and branch does not trigger this behaviour, as this 10; would cause debug info to affect CodeGen. 11 12; CHECK-LABEL: i: 13; CHECK-NOT: icmp 14; CHECK: [[COND:%.*]] = icmp eq i8 15; CHECK-NEXT: #dbg_value(i1 [[COND]] 16; CHECK-NEXT: br i1 [[COND]] 17 18 19target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 20target triple = "x86_64-unknown-linux-gnu" 21 22@b = dso_local local_unnamed_addr global i8 0, align 1, !dbg !0 23@a = dso_local local_unnamed_addr global i32 0, align 4, !dbg !6 24@c = dso_local local_unnamed_addr global i8 0, align 1, !dbg !9 25define dso_local signext i16 @d() local_unnamed_addr !dbg !17 { 26entry: 27 %0 = load i32, ptr @a, align 4 28 %tobool2.not = icmp eq i32 %0, 0 29 %1 = load i8, ptr @b, align 1, !dbg !24 30 %cmp.not13 = icmp eq i8 %1, 7, !dbg !24 31 br i1 %cmp.not13, label %cleanup, label %if.end.preheader, !dbg !24 32 33if.end.preheader: ; preds = %entry 34 br label %if.end, !dbg !24 35 36if.end: ; preds = %if.end.preheader, %i 37 %2 = phi i8 [ %add, %i ], [ %1, %if.end.preheader ] 38 br i1 %tobool2.not, label %i, label %if.end4, !dbg !24 39 40if.end4: ; preds = %if.end 41 %conv5 = trunc i32 %0 to i16, !dbg !24 42 br label %cleanup, !dbg !24 43 44i: ; preds = %if.end 45 %add = add i8 %2, 1, !dbg !24 46 store i8 %add, ptr @b, align 1, !dbg !24 47 %cmp.not = icmp eq i8 %add, 7, !dbg !24 48 call void @llvm.dbg.value(metadata i1 %cmp.not, metadata !23, metadata !DIExpression(DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value)), !dbg !24 49 br i1 %cmp.not, label %cleanup.loopexit, label %if.end, !dbg !24 50 51cleanup.loopexit: ; preds = %i 52 br label %cleanup 53 54cleanup: ; preds = %cleanup.loopexit, %if.end4, %entry 55 %cmp.not12 = phi i1 [ %cmp.not13, %if.end4 ], [ %cmp.not13, %entry ], [ %cmp.not, %cleanup.loopexit ] 56 %retval.0 = phi i16 [ %conv5, %if.end4 ], [ undef, %entry ], [ undef, %cleanup.loopexit ] 57 %3 = load i8, ptr @c, align 1 58 %conv8 = sext i8 %3 to i16 59 %retval.1 = select i1 %cmp.not12, i16 %conv8, i16 %retval.0 60 ret i16 %retval.1, !dbg !24 61} 62 63declare void @llvm.dbg.value(metadata, metadata, metadata) 64 65!llvm.dbg.cu = !{!2} 66!llvm.module.flags = !{!12, !13, !14, !15} 67!llvm.ident = !{!16} 68 69!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 70!1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 2, type: !11, isLocal: false, isDefinition: true) 71!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None) 72!3 = !DIFile(filename: "lsr-cond-dbg.c", directory: "/") 73!4 = !{} 74!5 = !{!6, !0, !9} 75!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) 76!7 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true) 77!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 78!9 = !DIGlobalVariableExpression(var: !10, expr: !DIExpression()) 79!10 = distinct !DIGlobalVariable(name: "c", scope: !2, file: !3, line: 2, type: !11, isLocal: false, isDefinition: true) 80!11 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) 81!12 = !{i32 7, !"Dwarf Version", i32 4} 82!13 = !{i32 2, !"Debug Info Version", i32 3} 83!14 = !{i32 1, !"wchar_size", i32 4} 84!15 = !{i32 7, !"uwtable", i32 1} 85!16 = !{!"clang version 13.0.0"} 86!17 = distinct !DISubprogram(name: "d", scope: !3, file: !3, line: 3, type: !18, scopeLine: 3, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !21) 87!18 = !DISubroutineType(types: !19) 88!19 = !{!20} 89!20 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed) 90!21 = !{!23} 91!22 = distinct !DILexicalBlock(scope: !17, file: !3, line: 4, column: 3) 92!23 = !DILocalVariable(name: "g", scope: !22, file: !3, line: 7, type: !8) 93!24 = !DILocation(line: 5, column: 9, scope: !22) 94 95