Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -5580,10 +5580,23 @@ if (!Op && N.getNode()) { // Check if frame index is available. SDValue LCandidate = peekThroughBitcasts(N); - if (LoadSDNode *LNode = dyn_cast(LCandidate.getNode())) + if (LoadSDNode *LNode = dyn_cast(LCandidate.getNode())) { if (FrameIndexSDNode *FINode = - dyn_cast(LNode->getBasePtr().getNode())) + dyn_cast(LNode->getBasePtr().getNode())) { Op = MachineOperand::CreateFI(FINode->getIndex()); + + // Adjust offset for big endian architectures + if (!MF.getDataLayout().isLittleEndian()) { + auto DlBits = Variable->getSizeInBits(); + auto FIBits = FINode->getValueSizeInBits(0); + if (DlBits.hasValue() && !FIBits.isScalable() && + DlBits.getValue() < FIBits.getFixedSize()) + Expr = DIExpression::prepend( + Expr, DIExpression::ApplyOffset, + (FIBits.getFixedSize() - DlBits.getValue()) / 8); + } + } + } } if (!Op) { Index: llvm/test/DebugInfo/ARM/big-endian-args.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/ARM/big-endian-args.ll @@ -0,0 +1,63 @@ +; RUN: llc -mtriple=armebv4t-unknown-unknown -start-after=codegenprepare -o - %s | FileCheck %s + +; Verify that the DBG_VALUE p4 and p5 points to an adjusted offset from the frame index due to being big-endian. +; +; Generated from the following C code +; +; void foo(int p0, int p1, int p2, int p3, short p4, char p5) { +; } +; +; compile with -mbig-endian -g -O2 -S -emit-llvm. + +; CHECK: @DEBUG_VALUE: foo:p4 <- [DW_OP_plus_uconst 2] [$sp+0] +; CHECK: @DEBUG_VALUE: foo:p5 <- [DW_OP_plus_uconst 4, DW_OP_plus_uconst 3] [$sp+0] + +target datalayout = "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" +target triple = "armebv4t-unknown-unknown" + +; Function Attrs: nofree norecurse nosync nounwind readnone willreturn mustprogress +define dso_local arm_aapcscc void @foo(i32 %p0, i32 %p1, i32 %p2, i32 %p3, i16 signext %p4, i8 zeroext %p5) local_unnamed_addr #0 !dbg !9 { +entry: + call void @llvm.dbg.value(metadata i32 %p0, metadata !17, metadata !DIExpression()), !dbg !23 + call void @llvm.dbg.value(metadata i32 %p1, metadata !18, metadata !DIExpression()), !dbg !23 + call void @llvm.dbg.value(metadata i32 %p2, metadata !19, metadata !DIExpression()), !dbg !23 + call void @llvm.dbg.value(metadata i32 %p3, metadata !20, metadata !DIExpression()), !dbg !23 + call void @llvm.dbg.value(metadata i16 %p4, metadata !21, metadata !DIExpression()), !dbg !23 + call void @llvm.dbg.value(metadata i8 %p5, metadata !22, metadata !DIExpression()), !dbg !23 + ret void, !dbg !24 +} + +; Function Attrs: nofree nosync nounwind readnone speculatable willreturn +declare void @llvm.dbg.value(metadata, metadata, metadata) #1 + +attributes #0 = { nofree norecurse nosync nounwind readnone willreturn mustprogress "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="arm7tdmi" "target-features"="+armv4t,+soft-float,+strict-align,-aes,-bf16,-crypto,-d32,-dotprod,-fp-armv8,-fp-armv8d16,-fp-armv8d16sp,-fp-armv8sp,-fp16,-fp16fml,-fp64,-fpregs,-fullfp16,-mve,-mve.fp,-neon,-sha2,-thumb-mode,-vfp2,-vfp2sp,-vfp3,-vfp3d16,-vfp3d16sp,-vfp3sp,-vfp4,-vfp4d16,-vfp4d16sp,-vfp4sp" "use-soft-float"="true" } +attributes #1 = { nofree nosync nounwind readnone speculatable willreturn } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5, !6, !7} +!llvm.ident = !{!8} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 13.0.0 (https://github.com/llvm/llvm-project 0c330afdfa42370fb50979efd1ee6bcbe9642b6d)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "big-endian-args.c", directory: "/") +!2 = !{} +!3 = !{i32 7, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!6 = !{i32 1, !"min_enum_size", i32 4} +!7 = !{i32 7, !"frame-pointer", i32 2} +!8 = !{!"clang version 13.0.0 (https://github.com/llvm/llvm-project 0c330afdfa42370fb50979efd1ee6bcbe9642b6d)"} +!9 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16) +!11 = !DISubroutineType(types: !12) +!12 = !{null, !13, !13, !13, !13, !14, !15} +!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!14 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed) +!15 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char) +!16 = !{!17, !18, !19, !20, !21, !22} +!17 = !DILocalVariable(name: "p0", arg: 1, scope: !9, file: !1, line: 1, type: !13) +!18 = !DILocalVariable(name: "p1", arg: 2, scope: !9, file: !1, line: 1, type: !13) +!19 = !DILocalVariable(name: "p2", arg: 3, scope: !9, file: !1, line: 1, type: !13) +!20 = !DILocalVariable(name: "p3", arg: 4, scope: !9, file: !1, line: 1, type: !13) +!21 = !DILocalVariable(name: "p4", arg: 5, scope: !9, file: !1, line: 1, type: !14) +!22 = !DILocalVariable(name: "p5", arg: 6, scope: !9, file: !1, line: 1, type: !15) +!23 = !DILocation(line: 0, scope: !9) +!24 = !DILocation(line: 2, column: 1, scope: !9)