xref: /llvm-project/llvm/test/CodeGen/X86/dbg-changes-codegen.ll (revision 2f448bf509432c1a19ec46ab8cbc7353c03c6280)
1; RUN: llc < %s -mtriple=x86_64-linux | FileCheck %s
2
3; The Peephole optimizer should fold the load into the cmp even with debug info.
4; CHECK-LABEL: _ZN3Foo3batEv
5; CHECK-NOT: movq pfoo
6; CHECK: cmpq {{%[a-z]+}}, pfoo(%rip)
7;
8; CHECK-LABEL: _Z3bazv
9; CHECK-NOT: movq wibble2
10; CHECK: cmpq {{%[a-z]+}}, wibble2(%rip)
11
12; Regenerate test with this command:
13;   clang -emit-llvm -S -O2 -g
14; from this source:
15;   struct Foo {
16;     bool bat();
17;     bool operator==(Foo &arg) { return (this == &arg); }
18;   };
19;   Foo *pfoo;
20;   bool Foo::bat() { return (*this == *pfoo); }
21;
22;   struct Wibble ptr wibble1, *wibble2;
23;   struct Flibble {
24;     void bar(Wibble *c) {
25;       if (c < wibble2)
26;         wibble2 = 0;
27;       c->x = 0;
28;     }
29;   } flibble;
30;   void baz() { flibble.bar(wibble1); }
31
32%struct.Foo = type { i8 }
33%struct.Wibble = type { i32 }
34%struct.Flibble = type { i8 }
35
36@pfoo = dso_local global ptr null, align 8
37@wibble1 = dso_local global ptr null, align 8
38@wibble2 = dso_local global ptr null, align 8
39@flibble = dso_local global %struct.Flibble zeroinitializer, align 1
40
41; Function Attrs: nounwind readonly uwtable
42define zeroext i1 @_ZN3Foo3batEv(ptr %this) #0 align 2 {
43entry:
44  %0 = load ptr, ptr @pfoo, align 8
45  tail call void @llvm.dbg.value(metadata ptr %0, i64 0, metadata !62, metadata !DIExpression()), !dbg !DILocation(scope: !1)
46  %cmp.i = icmp eq ptr %0, %this
47  ret i1 %cmp.i
48}
49
50; Function Attrs: nounwind uwtable
51define dso_local void @_Z3bazv() #1 {
52entry:
53  %0 = load ptr, ptr @wibble1, align 8
54  tail call void @llvm.dbg.value(metadata ptr undef, i64 0, metadata !65, metadata !DIExpression()), !dbg !DILocation(scope: !1)
55  %1 = load ptr, ptr @wibble2, align 8
56  %cmp.i = icmp ugt ptr %1, %0
57  br i1 %cmp.i, label %if.then.i, label %_ZN7Flibble3barEP6Wibble.exit
58
59if.then.i:                                        ; preds = %entry
60  store ptr null, ptr @wibble2, align 8
61  br label %_ZN7Flibble3barEP6Wibble.exit
62
63_ZN7Flibble3barEP6Wibble.exit:                    ; preds = %entry, %if.then.i
64  store i32 0, ptr %0, align 4
65  ret void
66}
67
68; Function Attrs: nounwind readnone
69declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
70
71attributes #0 = { nounwind readonly uwtable "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
72attributes #1 = { nounwind uwtable "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
73attributes #2 = { nounwind readnone }
74
75!1 = distinct !DISubprogram()
76
77!17 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: null)
78!45 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: null)
79!62 = !DILocalVariable(name: "arg", line: 4, arg: 2, scope: !1, type: !17)
80!64 = !{ptr undef}
81!65 = !DILocalVariable(name: "this", line: 13, arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !1, type: !45)
82