1*d0e2808fSShan Huang; RUN: opt -passes=loop-load-elim -S < %s | FileCheck %s 2*d0e2808fSShan Huang 3*d0e2808fSShan Huang; LoopLoadElimination's propagateStoredValueToLoadUsers() replaces the 4*d0e2808fSShan Huang; `load` (`%a`) with a hoisted initial `load` and a `phi` that forwards 5*d0e2808fSShan Huang; the stored value. 6*d0e2808fSShan Huang; This test checks that the debug location is propagated to the new `phi` 7*d0e2808fSShan Huang; from the original `load` it replaces in block `%for.body` and the debug 8*d0e2808fSShan Huang; location drop of the hoisted `load` in block `%entry`. 9*d0e2808fSShan Huang; Moreover, this test also checks the debug location update of the new 10*d0e2808fSShan Huang; `bitcast` created when the `load` type is mismatched with the `store` type: 11*d0e2808fSShan Huang; store i32 ... 12*d0e2808fSShan Huang; %a = load float, ... 13*d0e2808fSShan Huang; Because the `bitcast` casts the old `load` value, it has the same debug 14*d0e2808fSShan Huang; location as the old `load` (ie., the same as the new `phi`). 15*d0e2808fSShan Huang 16*d0e2808fSShan Huang; If the store and the load use different types, but have the same 17*d0e2808fSShan Huang; size then we should still be able to forward the value. 18*d0e2808fSShan Huang; 19*d0e2808fSShan Huang; for (unsigned i = 0; i < 100; i++) { 20*d0e2808fSShan Huang; A[i+1] = B[i] + 2; 21*d0e2808fSShan Huang; C[i] = ((float*)A)[i] * 2; 22*d0e2808fSShan Huang; } 23*d0e2808fSShan Huang 24*d0e2808fSShan Huangdefine void @f(ptr noalias %A, ptr noalias %B, ptr noalias %C, i64 %N) !dbg !5 { 25*d0e2808fSShan Huang; CHECK-LABEL: define void @f( 26*d0e2808fSShan Huang; CHECK-NEXT: entry: 27*d0e2808fSShan Huang; CHECK-NEXT: [[LOAD_INITIAL:%.*]] = load float, ptr {{.*}}, align 4{{$}} 28*d0e2808fSShan Huang; CHECK: for.body: 29*d0e2808fSShan Huang; CHECK-NEXT: [[STORE_FORWARDED:%.*]] = phi float [ [[LOAD_INITIAL]], %entry ], [ [[STORE_FORWARD_CAST:%.*]], %for.body ], !dbg [[DBG9:![0-9]+]] 30*d0e2808fSShan Huang; CHECK: [[STORE_FORWARD_CAST]] = bitcast i32 {{.*}} to float, !dbg [[DBG9]] 31*d0e2808fSShan Huang; CHECK: [[DBG9]] = !DILocation(line: 11, 32*d0e2808fSShan Huang; 33*d0e2808fSShan Huangentry: 34*d0e2808fSShan Huang br label %for.body, !dbg !8 35*d0e2808fSShan Huang 36*d0e2808fSShan Huangfor.body: ; preds = %for.body, %entry 37*d0e2808fSShan Huang %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ], !dbg !9 38*d0e2808fSShan Huang %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !10 39*d0e2808fSShan Huang %Aidx_next = getelementptr inbounds i32, ptr %A, i64 %indvars.iv.next, !dbg !11 40*d0e2808fSShan Huang %Bidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv, !dbg !12 41*d0e2808fSShan Huang %Cidx = getelementptr inbounds i32, ptr %C, i64 %indvars.iv, !dbg !13 42*d0e2808fSShan Huang %Aidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv, !dbg !14 43*d0e2808fSShan Huang %b = load i32, ptr %Bidx, align 4, !dbg !15 44*d0e2808fSShan Huang %a_p1 = add i32 %b, 2, !dbg !16 45*d0e2808fSShan Huang store i32 %a_p1, ptr %Aidx_next, align 4, !dbg !17 46*d0e2808fSShan Huang %a = load float, ptr %Aidx, align 4, !dbg !18 47*d0e2808fSShan Huang %c = fmul float %a, 2.000000e+00, !dbg !19 48*d0e2808fSShan Huang %c.int = fptosi float %c to i32, !dbg !20 49*d0e2808fSShan Huang store i32 %c.int, ptr %Cidx, align 4, !dbg !21 50*d0e2808fSShan Huang %exitcond = icmp eq i64 %indvars.iv.next, %N, !dbg !22 51*d0e2808fSShan Huang br i1 %exitcond, label %for.end, label %for.body, !dbg !23 52*d0e2808fSShan Huang 53*d0e2808fSShan Huangfor.end: ; preds = %for.body 54*d0e2808fSShan Huang ret void, !dbg !24 55*d0e2808fSShan Huang} 56*d0e2808fSShan Huang 57*d0e2808fSShan Huang!llvm.dbg.cu = !{!0} 58*d0e2808fSShan Huang!llvm.debugify = !{!2, !3} 59*d0e2808fSShan Huang!llvm.module.flags = !{!4} 60*d0e2808fSShan Huang 61*d0e2808fSShan Huang!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug) 62*d0e2808fSShan Huang!1 = !DIFile(filename: "type-mismatch.ll", directory: "/") 63*d0e2808fSShan Huang!2 = !{i32 17} 64*d0e2808fSShan Huang!3 = !{i32 0} 65*d0e2808fSShan Huang!4 = !{i32 2, !"Debug Info Version", i32 3} 66*d0e2808fSShan Huang!5 = distinct !DISubprogram(name: "f", linkageName: "f", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0) 67*d0e2808fSShan Huang!6 = !DISubroutineType(types: !7) 68*d0e2808fSShan Huang!7 = !{} 69*d0e2808fSShan Huang!8 = !DILocation(line: 1, column: 1, scope: !5) 70*d0e2808fSShan Huang!9 = !DILocation(line: 2, column: 1, scope: !5) 71*d0e2808fSShan Huang!10 = !DILocation(line: 3, column: 1, scope: !5) 72*d0e2808fSShan Huang!11 = !DILocation(line: 4, column: 1, scope: !5) 73*d0e2808fSShan Huang!12 = !DILocation(line: 5, column: 1, scope: !5) 74*d0e2808fSShan Huang!13 = !DILocation(line: 6, column: 1, scope: !5) 75*d0e2808fSShan Huang!14 = !DILocation(line: 7, column: 1, scope: !5) 76*d0e2808fSShan Huang!15 = !DILocation(line: 8, column: 1, scope: !5) 77*d0e2808fSShan Huang!16 = !DILocation(line: 9, column: 1, scope: !5) 78*d0e2808fSShan Huang!17 = !DILocation(line: 10, column: 1, scope: !5) 79*d0e2808fSShan Huang!18 = !DILocation(line: 11, column: 1, scope: !5) 80*d0e2808fSShan Huang!19 = !DILocation(line: 12, column: 1, scope: !5) 81*d0e2808fSShan Huang!20 = !DILocation(line: 13, column: 1, scope: !5) 82*d0e2808fSShan Huang!21 = !DILocation(line: 14, column: 1, scope: !5) 83*d0e2808fSShan Huang!22 = !DILocation(line: 15, column: 1, scope: !5) 84*d0e2808fSShan Huang!23 = !DILocation(line: 16, column: 1, scope: !5) 85*d0e2808fSShan Huang!24 = !DILocation(line: 17, column: 1, scope: !5) 86