Index: lib/CodeGen/SelectionDAG/LegalizeTypes.cpp =================================================================== --- lib/CodeGen/SelectionDAG/LegalizeTypes.cpp +++ lib/CodeGen/SelectionDAG/LegalizeTypes.cpp @@ -864,8 +864,13 @@ AnalyzeNewValue(Hi); // Transfer debug values. - transferDbgValues(DAG, Op, Lo, 0); - transferDbgValues(DAG, Op, Hi, Lo.getValueSizeInBits()); + if (DAG.getDataLayout().isBigEndian()) { + transferDbgValues(DAG, Op, Hi, 0); + transferDbgValues(DAG, Op, Lo, Hi.getValueSizeInBits()); + } else { + transferDbgValues(DAG, Op, Lo, 0); + transferDbgValues(DAG, Op, Hi, Lo.getValueSizeInBits()); + } // Remember that this is the result of the node. std::pair &Entry = ExpandedIntegers[Op]; Index: test/CodeGen/PowerPC/debuginfo-split-int.ll =================================================================== --- /dev/null +++ test/CodeGen/PowerPC/debuginfo-split-int.ll @@ -0,0 +1,86 @@ +; RUN: llc < %s -stop-after=isel -o - | FileCheck %s + +source_filename = "foo.c" +target datalayout = "E-m:e-p:32:32-i64:64-n32" +target triple = "ppc32" + +; Verify that, when handling split-up integers, the +; transferring of debug info takes the endianness +; into consideration. +; +; The fragment expression at offset 0 should correspond +; to the high part of the value on big-endian targets. + +; This basis of this ll file was created by running: +; clang --target=powerpc -O1 -S -g -emit-llvm foo.c +; +; with foo.c being the program: +; unsigned long long global; +; +; __attribute__((noinline)) +; unsigned long long foo() +; { +; return global; +; } +; +; void bar() +; { +; volatile unsigned long long result = foo(); +; } +; +; This file is a slight tweak of that output, with irrelevant +; lifetime intrinsics, metadata, and debug info being removed. + +@global = common local_unnamed_addr global i64 0, align 8 + +define i64 @foo() local_unnamed_addr #0 !dbg !6 { +entry: + %0 = load i64, i64* @global, align 8 + ret i64 %0 +} +; CHECK: [[DL:![0-9]+]] = !DILocalVariable(name: "result" +; +; High 32 bits in R3, low 32 bits in R4 +; CHECK: BL @foo +; CHECK: %0 = COPY %r3 +; CHECK: DBG_VALUE debug-use %0, debug-use _, [[DL]], !DIExpression(DW_OP_LLVM_fragment, 0, 32) +; CHECK: %1 = COPY %r4 +; CHECK: DBG_VALUE debug-use %1, debug-use _, [[DL]], !DIExpression(DW_OP_LLVM_fragment, 32, 32) +define void @bar() local_unnamed_addr #1 !dbg !10 { +entry: + %result = alloca i64, align 8 + %call = tail call i64 @foo(), !dbg !16 + tail call void @llvm.dbg.value(metadata i64 %call, metadata !14, metadata !DIExpression()), !dbg !17 + store volatile i64 %call, i64* %result, align 8 + ret void +} + +; Function Attrs: nounwind readnone speculatable +declare void @llvm.dbg.value(metadata, metadata, metadata) #2 + +attributes #0 = { noinline } +attributes #1 = { nounwind } +attributes #2 = { nounwind readnone speculatable } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} +!llvm.ident = !{!5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !2) +!1 = !DIFile(filename: "foo.c", directory: "/") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{!"clang version 6.0.0"} +!6 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 4, type: !7, isLocal: false, isDefinition: true, scopeLine: 5, isOptimized: true, unit: !0, variables: !2) +!7 = !DISubroutineType(types: !8) +!8 = !{!9} +!9 = !DIBasicType(name: "long long unsigned int", size: 64, encoding: DW_ATE_unsigned) +!10 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 9, type: !11, isLocal: false, isDefinition: true, scopeLine: 10, isOptimized: true, unit: !0, variables: !13) +!11 = !DISubroutineType(types: !12) +!12 = !{null} +!13 = !{!14} +!14 = !DILocalVariable(name: "result", scope: !10, file: !1, line: 11, type: !15) +!15 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !9) +!16 = !DILocation(line: 11, column: 40, scope: !10) +!17 = !DILocation(line: 11, column: 31, scope: !10)