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