1; RUN: opt < %s -licm -pass-remarks-missed=licm -o /dev/null 2>&1 | FileCheck %s 2; RUN: opt -aa-pipeline=basic-aa -passes='require<aa>,require<targetir>,require<scalar-evolution>,require<opt-remark-emit>,loop(licm)' %s -o /dev/null -pass-remarks-missed=licm 2>&1 | FileCheck %s 3target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128" 4 5; Without the noalias on %p, we can't optmize this and the remark should tell 6; us about it. 7 8define void @test(i32* %array, i32* %p) { 9Entry: 10 br label %Loop 11 12Loop: 13 %j = phi i32 [ 0, %Entry ], [ %Next, %Loop ] 14 %addr = getelementptr i32, i32* %array, i32 %j 15 %a = load i32, i32* %addr 16; CHECK: remark: /tmp/kk.c:2:20: failed to move load with loop-invariant address because the loop may invalidate its value 17 %b = load i32, i32* %p, !dbg !8 18 %a2 = add i32 %a, %b 19 store i32 %a2, i32* %addr 20 %Next = add i32 %j, 1 21 %cond = icmp eq i32 %Next, 0 22 br i1 %cond, label %Out, label %Loop 23 24Out: 25 ret void 26} 27 28; This illustrates why we need to check loop-invariance before issuing this 29; remark. 30 31define i32 @invalidated_load_with_non_loop_invariant_address(i32* %array, i32* %array2) { 32Entry: 33 br label %Loop 34 35Loop: 36 %j = phi i32 [ 0, %Entry ], [ %Next, %Loop ] 37 38; CHECK-NOT: /tmp/kk.c:3:20: {{.*}} loop-invariant 39 %addr = getelementptr i32, i32* %array, i32 %j 40 %a = load i32, i32* %addr, !dbg !9 41 42 %addr2 = getelementptr i32, i32* %array2, i32 %j 43 store i32 %j, i32* %addr2 44 45 %Next = add i32 %j, 1 46 %cond = icmp eq i32 %Next, 0 47 br i1 %cond, label %Out, label %Loop 48 49Out: 50 %a2 = phi i32 [ %a, %Loop ] 51 ret i32 %a2 52} 53 54!llvm.dbg.cu = !{!0} 55!llvm.module.flags = !{!3, !4} 56!llvm.ident = !{!5} 57 58!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, enums: !2) 59!1 = !DIFile(filename: "/tmp/kk.c", directory: "/tmp") 60!2 = !{} 61!3 = !{i32 2, !"Debug Info Version", i32 3} 62!4 = !{i32 1, !"PIC Level", i32 2} 63!5 = !{!"clang version 3.9.0 "} 64!6 = distinct !DISubprogram(name: "success", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2) 65!7 = !DISubroutineType(types: !2) 66!8 = !DILocation(line: 2, column: 20, scope: !6) 67!9 = !DILocation(line: 3, column: 20, scope: !6) 68