1; RUN: opt -S -loop-reduce %s -o - | FileCheck %s 2; REQUIRES: x86-registered-target 3 4;; Ensure that we retain debuginfo for the induction variable and dependant 5;; variables when loop strength reduction is applied to the loop. 6;; This IR produced from: 7;; 8;; clang -S -emit-llvm -Xclang -disable-llvm-passes -g lsr-basic.cpp -o 9;; Then executing opt -O2 up to the the loopFullUnroll pass. 10;; void mul_pow_of_2_to_shift(unsigned size, unsigned *data) { 11;; unsigned i = 0; 12;; #pragma clang loop vectorize(disable) 13;; while (i < size) { 14;; unsigned comp = i * 8; 15;; data[i] = comp; 16;; i++; // DexLabel('mul_pow_of_2_induction_increment') 17;; } 18;; } 19; CHECK: call void @llvm.dbg.value(metadata i64 %lsr.iv, metadata ![[i:[0-9]+]], metadata !DIExpression(DW_OP_consts, 8, DW_OP_div, DW_OP_stack_value)) 20; CHECK: call void @llvm.dbg.value(metadata i64 %lsr.iv, metadata ![[comp:[0-9]+]], metadata !DIExpression(DW_OP_consts, 8, DW_OP_div, DW_OP_consts, 8, DW_OP_mul, DW_OP_stack_value)) 21; CHECK: call void @llvm.dbg.value(metadata i64 %lsr.iv, metadata ![[i]], metadata !DIExpression(DW_OP_consts, 8, DW_OP_div, DW_OP_consts, 1, DW_OP_plus, DW_OP_stack_value)) 22; CHECK: ![[i]] = !DILocalVariable(name: "i" 23; CHECK: ![[comp]] = !DILocalVariable(name: "comp" 24 25target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 26target triple = "x86_64-unknown-linux-gnu" 27 28define dso_local void @_Z21mul_pow_of_2_to_shiftjPj(i32 %size, i32* nocapture %data) local_unnamed_addr !dbg !7 { 29entry: 30 call void @llvm.dbg.value(metadata i32 %size, metadata !12, metadata !DIExpression()), !dbg !13 31 call void @llvm.dbg.value(metadata i32* %data, metadata !14, metadata !DIExpression()), !dbg !13 32 call void @llvm.dbg.value(metadata i32 0, metadata !15, metadata !DIExpression()), !dbg !13 33 %cmp4.not = icmp eq i32 %size, 0, !dbg !13 34 br i1 %cmp4.not, label %while.end, label %while.body.preheader, !dbg !13 35 36while.body.preheader: ; preds = %entry 37 %wide.trip.count = zext i32 %size to i64, !dbg !13 38 br label %while.body, !dbg !13 39 40while.body: ; preds = %while.body, %while.body.preheader 41 %indvars.iv = phi i64 [ 0, %while.body.preheader ], [ %indvars.iv.next, %while.body ] 42 call void @llvm.dbg.value(metadata i64 %indvars.iv, metadata !15, metadata !DIExpression()), !dbg !13 43 %0 = trunc i64 %indvars.iv to i32, !dbg !16 44 %mul = shl i32 %0, 3, !dbg !16 45 call void @llvm.dbg.value(metadata i32 %mul, metadata !18, metadata !DIExpression()), !dbg !16 46 %arrayidx = getelementptr inbounds i32, i32* %data, i64 %indvars.iv, !dbg !16 47 store i32 %mul, i32* %arrayidx, align 4, !dbg !16 48 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !16 49 call void @llvm.dbg.value(metadata i64 %indvars.iv.next, metadata !15, metadata !DIExpression()), !dbg !13 50 %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count, !dbg !13 51 br i1 %exitcond, label %while.body, label %while.end.loopexit, !dbg !13, !llvm.loop !19 52 53while.end.loopexit: ; preds = %while.body 54 br label %while.end, !dbg !13 55 56while.end: ; preds = %while.end.loopexit, %entry 57 ret void, !dbg !13 58} 59 60; Function Attrs: nofree nosync nounwind readnone speculatable willreturn 61declare void @llvm.dbg.value(metadata, metadata, metadata) #0 62 63attributes #0 = { nofree nosync nounwind readnone speculatable willreturn } 64 65!llvm.dbg.cu = !{!0} 66!llvm.module.flags = !{!3, !4, !5} 67!llvm.ident = !{!6} 68 69!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) 70!1 = !DIFile(filename: "lsr-basic.cpp", directory: "/tmp") 71!2 = !{} 72!3 = !{i32 7, !"Dwarf Version", i32 4} 73!4 = !{i32 2, !"Debug Info Version", i32 3} 74!5 = !{i32 1, !"wchar_size", i32 4} 75!6 = !{!"clang version 13.0.0"} 76!7 = distinct !DISubprogram(name: "mul_pow_of_2_to_shift", linkageName: "_Z21mul_pow_of_2_to_shiftjPj", scope: !1, file: !1, line: 18, type: !8, scopeLine: 18, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2) 77!8 = !DISubroutineType(types: !9) 78!9 = !{null, !10, !11} 79!10 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) 80!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64) 81!12 = !DILocalVariable(name: "size", arg: 1, scope: !7, file: !1, line: 18, type: !10) 82!13 = !DILocation(line: 0, scope: !7) 83!14 = !DILocalVariable(name: "data", arg: 2, scope: !7, file: !1, line: 18, type: !11) 84!15 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 19, type: !10) 85!16 = !DILocation(line: 22, column: 27, scope: !17) 86!17 = distinct !DILexicalBlock(scope: !7, file: !1, line: 21, column: 22) 87!18 = !DILocalVariable(name: "comp", scope: !17, file: !1, line: 22, type: !10) 88!19 = distinct !{!19, !20, !21, !22, !23} 89!20 = !DILocation(line: 21, column: 5, scope: !7) 90!21 = !DILocation(line: 25, column: 5, scope: !7) 91!22 = !{!"llvm.loop.mustprogress"} 92!23 = !{!"llvm.loop.vectorize.width", i32 1} 93