206 lines · plain
1; RUN: opt < %s -passes=gvn -o /dev/null -pass-remarks-output=%t -S2; RUN: cat %t | FileCheck %s3 4 5; ModuleID = 'bugpoint-reduced-simplified.bc'6source_filename = "gvn-test.c"7target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"8target triple = "x86_64-unknown-linux-gnu"9 10; CHECK: --- !Missed11; CHECK-NEXT: Pass: gvn12; CHECK-NEXT: Name: LoadClobbered13; CHECK-NEXT: Function: nonDominating114; CHECK-NEXT: Args:15; CHECK-NEXT: - String: 'load of type '16; CHECK-NEXT: - Type: i3217; CHECK-NEXT: - String: ' not eliminated'18; CHECK-NEXT: - String: ' in favor of '19; CHECK-NEXT: - OtherAccess: store20; CHECK-NEXT: - String: ' because it is clobbered by '21; CHECK-NEXT: - ClobberedBy: call22; CHECK-NEXT: ...23 24; Confirm that the partial redundancy being clobbered by the call to25; clobberingFunc() between store and load is identified.26 27define dso_local void @nonDominating1(ptr %a, i1 %cond, i32 %b) local_unnamed_addr #0 {28entry:29 br i1 %cond, label %if.then, label %if.end30 31if.then: ; preds = %entry32 store i32 %b, ptr %a, align 433 br label %if.end34 35if.end: ; preds = %if.then, %entry36 tail call void @clobberingFunc() #137 %0 = load i32, ptr %a, align 438 %mul2 = shl nsw i32 %0, 139 store i32 %mul2, ptr %a, align 440 ret void41}42 43declare dso_local void @clobberingFunc() local_unnamed_addr #044 45; CHECK: --- !Missed46; CHECK-NEXT: Pass: gvn47; CHECK-NEXT: Name: LoadClobbered48; CHECK-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 3, Column: 3 }49; CHECK-NEXT: Function: nonDominating250; CHECK-NEXT: Args:51; CHECK-NEXT: - String: 'load of type '52; CHECK-NEXT: - Type: i3253; CHECK-NEXT: - String: ' not eliminated'54; CHECK-NEXT: - String: ' in favor of '55; CHECK-NEXT: - OtherAccess: load56; CHECK-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 1, Column: 1 }57; CHECK-NEXT: - String: ' because it is clobbered by '58; CHECK-NEXT: - ClobberedBy: call59; CHECK-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 2, Column: 2 }60; CHECK-NEXT: ...61; CHECK: --- !Missed62; CHECK-NEXT: Pass: gvn63; CHECK-NEXT: Name: LoadClobbered64; CHECK-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 5, Column: 5 }65; CHECK-NEXT: Function: nonDominating266; CHECK-NEXT: Args:67; CHECK-NEXT: - String: 'load of type '68; CHECK-NEXT: - Type: i3269; CHECK-NEXT: - String: ' not eliminated'70; CHECK-NEXT: - String: ' in favor of '71; CHECK-NEXT: - OtherAccess: load72; CHECK-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 3, Column: 3 }73; CHECK-NEXT: - String: ' because it is clobbered by '74; CHECK-NEXT: - ClobberedBy: call75; CHECK-NEXT: DebugLoc: { File: '/tmp/s.c', Line: 4, Column: 4 }76; CHECK-NEXT: ...77 78; More complex version of nonDominating1(), this time with loads. The values79; already loaded into %0 and %1 cannot replace %2 due to clobbering calls.80; %1 is not clobbered by the first call however, and %0 is irrelevant for the81; second one since %1 is more recently available.82 83define dso_local void @nonDominating2(ptr %a, i1 %cond) local_unnamed_addr #0 {84entry:85 br i1 %cond, label %if.then, label %if.end586 87if.then: ; preds = %entry88 %0 = load i32, ptr %a, align 4, !dbg !1489 %mul = mul nsw i32 %0, 1090 tail call void @clobberingFunc() #1, !dbg !1591 %1 = load i32, ptr %a, align 4, !dbg !1692 %mul3 = mul nsw i32 %1, 593 tail call void @clobberingFunc() #1, !dbg !1794 br label %if.end595 96if.end5: ; preds = %if.then, %entry97 %2 = load i32, ptr %a, align 4, !dbg !1898 %mul9 = shl nsw i32 %2, 199 store i32 %mul9, ptr %a, align 4100 ret void101}102 103; CHECK: --- !Missed104; CHECK-NEXT: Pass: gvn105; CHECK-NEXT: Name: LoadClobbered106; CHECK-NEXT: Function: nonDominating3107; CHECK-NEXT: Args:108; CHECK-NEXT: - String: 'load of type '109; CHECK-NEXT: - Type: i32110; CHECK-NEXT: - String: ' not eliminated'111; CHECK-NEXT: - String: ' because it is clobbered by '112; CHECK-NEXT: - ClobberedBy: call113; CHECK-NEXT: ...114 115; The two stores are both partially available at %0 (were it not for the116; clobbering call), however neither is strictly more recent than the other, so117; no attempt is made to identify what value could have potentially been reused118; otherwise. Just report that the load cannot be eliminated.119 120define dso_local void @nonDominating3(ptr %a, i32 %b, i32 %c, i1 %cond) local_unnamed_addr #0 {121entry:122 br i1 %cond, label %if.end5.sink.split, label %if.else123 124if.else: ; preds = %entry125 store i32 %b, ptr %a, align 4126 br label %if.end5127 128if.end5.sink.split: ; preds = %entry129 store i32 %c, ptr %a, align 4130 br label %if.end5131 132if.end5: ; preds = %if.end5.sink.split, %if.else133 tail call void @clobberingFunc() #1134 %0 = load i32, ptr %a, align 4135 %mul7 = shl nsw i32 %0, 1136 ret void137}138 139; CHECK: --- !Missed140; CHECK-NEXT: Pass: gvn141; CHECK-NEXT: Name: LoadClobbered142; CHECK-NEXT: Function: nonDominating4143; CHECK-NEXT: Args:144; CHECK-NEXT: - String: 'load of type '145; CHECK-NEXT: - Type: i32146; CHECK-NEXT: - String: ' not eliminated'147; CHECK-NEXT: - String: ' in favor of '148; CHECK-NEXT: - OtherAccess: store149; CHECK-NEXT: - String: ' because it is clobbered by '150; CHECK-NEXT: - ClobberedBy: call151; CHECK-NEXT: ...152 153; Make sure isPotentiallyReachable() is not called for an instruction154; outside the current function, as it will cause a crash.155 156define dso_local void @nonDominating4(i1 %cond, i32 %b) local_unnamed_addr #0 {157entry:158 br i1 %cond, label %if.then, label %if.end159 160if.then: ; preds = %entry161 store i32 %b, ptr @g, align 4162 br label %if.end163 164if.end: ; preds = %if.then, %entry165 tail call void @clobberingFunc() #1166 %0 = load i32, ptr @g, align 4167 %mul2 = shl nsw i32 %0, 1168 store i32 %mul2, ptr @g, align 4169 ret void170}171 172@g = external global i32173 174define dso_local void @globalUser(i32 %b) local_unnamed_addr #0 {175entry:176 store i32 %b, ptr @g, align 4177 ret void178}179 180attributes #0 = { "use-soft-float"="false" }181attributes #1 = { nounwind }182 183!llvm.ident = !{!0}184!llvm.dbg.cu = !{!1}185!llvm.module.flags = !{!4, !5, !6}186 187!0 = !{!"clang version 10.0.0 (git@github.com:llvm/llvm-project.git a2f6ae9abffcba260c22bb235879f0576bf3b783)"}188 189!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang version 4.0.0 (trunk 282540) (llvm/trunk 282542)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !3)190!2 = !DIFile(filename: "/tmp/s.c", directory: "/tmp")191!3 = !{}192!4 = !{i32 2, !"Dwarf Version", i32 4}193!5 = !{i32 2, !"Debug Info Version", i32 3}194!6 = !{i32 1, !"PIC Level", i32 2}195!8 = distinct !DISubprogram(name: "nonDominating2", scope: !2, file: !2, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !1, retainedNodes: !3)196!9 = !DISubroutineType(types: !10)197!10 = !{null, !11, !12, !12, !13}198!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)199!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)200!13 = !DIBasicType(name: "_Bool", size: 8, encoding: DW_ATE_boolean)201!14 = !DILocation(line: 1, column: 1, scope: !8)202!15 = !DILocation(line: 2, column: 2, scope: !8)203!16 = !DILocation(line: 3, column: 3, scope: !8)204!17 = !DILocation(line: 4, column: 4, scope: !8)205!18 = !DILocation(line: 5, column: 5, scope: !8)206