summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2015-07-23 22:56:53 +0000
committerSanjay Patel <spatel@rotateright.com>2015-07-23 22:56:53 +0000
commitf2fa58e744d5e209f2b398dbc7963813dab876c7 (patch)
tree48123bdad24f6ac17d59ebb94bda4780f45e7a9c /llvm
parent9b141ed48e2d0ae97631c39141de20191871304e (diff)
downloadbcm5719-llvm-f2fa58e744d5e209f2b398dbc7963813dab876c7.tar.gz
bcm5719-llvm-f2fa58e744d5e209f2b398dbc7963813dab876c7.zip
fix crash in machine trace metrics due to processing dbg_value instructions (PR24199)
The test in PR24199 ( https://llvm.org/bugs/show_bug.cgi?id=24199 ) crashes because machine trace metrics was not ignoring dbg_value instructions when calculating data dependencies. The machine-combiner pass asks machine trace metrics to calculate an instruction trace, does some reassociations, and calls MachineInstr::eraseFromParentAndMarkDBGValuesForRemoval() along with MachineTraceMetrics::invalidate(). The dbg_value instructions have their operands invalidated, but the instructions are not expected to be deleted. On a subsequent loop iteration of the machine-combiner pass, machine trace metrics would be called again and die while accessing the invalid debug instructions. Differential Revision: http://reviews.llvm.org/D11423 llvm-svn: 243057
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/CodeGen/MachineTraceMetrics.cpp4
-rw-r--r--llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll62
2 files changed, 66 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineTraceMetrics.cpp b/llvm/lib/CodeGen/MachineTraceMetrics.cpp
index 9404c687d41..d9a6b68462e 100644
--- a/llvm/lib/CodeGen/MachineTraceMetrics.cpp
+++ b/llvm/lib/CodeGen/MachineTraceMetrics.cpp
@@ -624,6 +624,10 @@ struct DataDep {
static bool getDataDeps(const MachineInstr *UseMI,
SmallVectorImpl<DataDep> &Deps,
const MachineRegisterInfo *MRI) {
+ // Debug values should not be included in any calculations.
+ if (UseMI->isDebugValue())
+ return false;
+
bool HasPhysRegs = false;
for (MachineInstr::const_mop_iterator I = UseMI->operands_begin(),
E = UseMI->operands_end(); I != E; ++I) {
diff --git a/llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll b/llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll
new file mode 100644
index 00000000000..1d0ee79f04a
--- /dev/null
+++ b/llvm/test/CodeGen/X86/machine-trace-metrics-crash.ll
@@ -0,0 +1,62 @@
+; RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mattr=sse -enable-unsafe-fp-math < %s | FileCheck %s
+
+; The debug info in this test case was causing a crash because machine trace metrics
+; did not correctly ignore debug instructions. The check lines ensure that the
+; machine-combiner pass has run, reassociated the add operands, and therefore
+; used machine trace metrics.
+
+define void @PR24199() {
+; CHECK-LABEL: PR24199:
+; CHECK: addss %xmm1, %xmm0
+; CHECK: addss %xmm2, %xmm0
+
+entry:
+ %i = alloca %struct.A, align 8
+ %tobool = icmp ne i32 undef, 0
+ br i1 undef, label %if.end, label %if.then
+
+if.then:
+ br label %if.end
+
+if.end:
+ %h = phi float [ 0.0, %if.then ], [ 4.0, %entry ]
+ call void @foo(%struct.A* nonnull undef)
+ tail call void @llvm.dbg.value(metadata %struct.A* undef, i64 0, metadata !5, metadata !4), !dbg !6
+ tail call void @llvm.dbg.value(metadata float %h, i64 0, metadata !5, metadata !4), !dbg !6
+ %n0 = load float, float* undef, align 4
+ %mul = fmul fast float %n0, %h
+ %add = fadd fast float %mul, 1.0
+ tail call void @llvm.dbg.value(metadata %struct.A* undef, i64 0, metadata !5, metadata !4), !dbg !6
+ tail call void @llvm.dbg.value(metadata float %add, i64 0, metadata !5, metadata !4), !dbg !6
+ %add.i = fadd fast float %add, %n0
+ store float %add.i, float* undef, align 4
+ %n1 = bitcast %struct.A* %i to i8*
+ call void @llvm.lifetime.start(i64 16, i8* %n1)
+ %n2 = load <2 x float>, <2 x float>* undef, align 8
+ %conv = uitofp i1 %tobool to float
+ %bitcast = extractelement <2 x float> %n2, i32 0
+ %factor = fmul fast float %bitcast, 2.0
+ %add3 = fadd fast float %factor, %conv
+ call void @bar(float %add3)
+ ret void
+}
+
+%struct.A = type { float, float }
+
+declare void @bar(float)
+declare void @foo(%struct.A*)
+declare void @llvm.lifetime.start(i64, i8* nocapture)
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: 1)
+!1 = !DIFile(filename: "24199.cpp", directory: "/bin")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = !DISubprogram(linkageName: "foo", file: !1, line: 18, isLocal: false, isDefinition: true, scopeLine: 18, function: void (%struct.A*)* @foo)
+!4 = !DIExpression()
+!5 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 1, scope: !3, flags: DIFlagArtificial | DIFlagObjectPointer)
+!6 = !DILocation(line: 0, scope: !3)
+
+
OpenPOWER on IntegriCloud