diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -18280,8 +18280,8 @@ if (StoreSDNode *ST1 = dyn_cast(Chain)) { if (ST->isUnindexed() && ST->isSimple() && ST1->isUnindexed() && ST1->isSimple()) { - if (ST1->getBasePtr() == Ptr && ST1->getValue() == Value && - ST->getMemoryVT() == ST1->getMemoryVT() && + if (OptLevel != CodeGenOpt::None && ST1->getBasePtr() == Ptr && + ST1->getValue() == Value && ST->getMemoryVT() == ST1->getMemoryVT() && ST->getAddressSpace() == ST1->getAddressSpace()) { // If this is a store followed by a store with the same value to the // same location, then the store is dead/noop. diff --git a/llvm/test/CodeGen/RISCV/dbg-combine.ll b/llvm/test/CodeGen/RISCV/dbg-combine.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/dbg-combine.ll @@ -0,0 +1,69 @@ +; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s | FileCheck %s + +; Make sure that the sequence of debug locations for function foo is correctly +; generated. More specifically, .loc entries for lines 6 and 7 must appear in +; the correct sequence. + +; $ clang -emit-llvm -S -g dbg-combine.c +; 1 int main () +; 2 { +; 3 int size; +; 4 +; 5 size = (int) sizeof (long long); +; 6 size = (int) sizeof (void*); +; 7 size = (int) sizeof (void (*)(void)); +; 8 +; 9 return 0; +; 10 } + +; CHECK: .loc 1 6 +; CHECK: .loc 1 7 + +; ModuleID = 'dbg-combine.c' +source_filename = "dbg-combine.c" +target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128" +target triple = "riscv64-unknown-unknown-elf" + +; Function Attrs: noinline nounwind optnone +define dso_local signext i32 @main() #0 !dbg !11 { +entry: + %retval = alloca i32, align 4 + %size = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + call void @llvm.dbg.declare(metadata i32* %size, metadata !14, metadata !DIExpression()), !dbg !15 + store i32 8, i32* %size, align 4, !dbg !16 + store i32 8, i32* %size, align 4, !dbg !17 + store i32 8, i32* %size, align 4, !dbg !18 + ret i32 0, !dbg !19 +} + +; Function Attrs: nofree nosync nounwind readnone speculatable willreturn +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +attributes #0 = { noinline nounwind optnone "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+a,+c,+m,+relax,-save-restore" } +attributes #1 = { nofree nosync nounwind readnone speculatable willreturn } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!4, !5, !6, !7, !8, !9} +!llvm.ident = !{!10} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git ecfd2d2403ae336195de7cdb06e1fe02a2bf1bc9)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "dbg-combine.c", directory: "/home/xgupta/riscv/riscv-llvm/_build/bin") +!2 = !{!3} +!3 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!4 = !{i32 7, !"Dwarf Version", i32 4} +!5 = !{i32 2, !"Debug Info Version", i32 3} +!6 = !{i32 1, !"wchar_size", i32 4} +!7 = !{i32 1, !"target-abi", !"lp64"} +!8 = !{i32 7, !"frame-pointer", i32 2} +!9 = !{i32 1, !"SmallDataLimit", i32 8} +!10 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git ecfd2d2403ae336195de7cdb06e1fe02a2bf1bc9)"} +!11 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !12, scopeLine: 2, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !13) +!12 = !DISubroutineType(types: !2) +!13 = !{} +!14 = !DILocalVariable(name: "size", scope: !11, file: !1, line: 3, type: !3) +!15 = !DILocation(line: 3, column: 7, scope: !11) +!16 = !DILocation(line: 5, column: 8, scope: !11) +!17 = !DILocation(line: 6, column: 8, scope: !11) +!18 = !DILocation(line: 7, column: 8, scope: !11) +!19 = !DILocation(line: 9, column: 3, scope: !11)