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,234 @@ +; 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 34, 35, 39, 40 must appear +; in the correct sequence. + +; $ clang -emit-llvm -S -g dbg-combine.c +; 1 typedef char padding[16]; +; 2 +; 3 struct { +; 4 padding p1; +; 5 long long v; +; 6 padding p2; +; 7 } padding_long; +; 8 +; 9 static void +; 10 fill (void *buf, long sizeof_buf) +; 11 { +; 12 char *p = buf; +; 13 int i; +; 14 for (i = 0; i < sizeof_buf; i++) +; 15 p[i] = "The quick brown dingo jumped over the layzy dog."[i]; +; 16 } +; 17 +; 18 void +; 19 fill_structs (void) +; 20 { +; 21 +; 22 fill (&padding_long.p1, sizeof (padding)); +; 23 fill (&padding_long.v, sizeof (padding_long.v)); +; 24 fill (&padding_long.p2, sizeof (padding)); +; 25 } +; 26 +; 27 int main () +; 28 { +; 29 int size, value; +; 30 +; 31 fill_structs (); +; 32 +; 33 size = (int) sizeof (long long); +; 34 size = (int) sizeof (void*); +; 35 size = (int) sizeof (void (*)(void)); +; 36 +; 37 /* Signed char? */ +; 38 value = '\377'; +; 39 value = (int) (char) -1; +; 40 value = (int) (signed char) -1; +; 41 +; 42 return 0; +; 43 } + +; CHECK: .loc 1 34 +; CHECK: .loc 1 35 +; CHECK: .loc 1 39 +; CHECK: .loc 1 40 + +; 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" + +%struct.anon = type { [16 x i8], i64, [16 x i8] } + +@padding_long = dso_local global %struct.anon zeroinitializer, align 8, !dbg !0 +@.str = private unnamed_addr constant [49 x i8] c"The quick brown dingo jumped over the layzy dog.\00", align 1 + +; Function Attrs: noinline nounwind optnone +define dso_local void @fill_structs() #0 !dbg !26 { +entry: + call void @fill(i8* getelementptr inbounds (%struct.anon, %struct.anon* @padding_long, i32 0, i32 0, i32 0), i64 16), !dbg !30 + call void @fill(i8* bitcast (i64* getelementptr inbounds (%struct.anon, %struct.anon* @padding_long, i32 0, i32 1) to i8*), i64 8), !dbg !31 + call void @fill(i8* getelementptr inbounds (%struct.anon, %struct.anon* @padding_long, i32 0, i32 2, i32 0), i64 16), !dbg !32 + ret void, !dbg !33 +} + +; Function Attrs: noinline nounwind optnone +define internal void @fill(i8* %buf, i64 %sizeof_buf) #0 !dbg !34 { +entry: + %buf.addr = alloca i8*, align 8 + %sizeof_buf.addr = alloca i64, align 8 + %p = alloca i8*, align 8 + %i = alloca i32, align 4 + store i8* %buf, i8** %buf.addr, align 8 + call void @llvm.dbg.declare(metadata i8** %buf.addr, metadata !39, metadata !DIExpression()), !dbg !40 + store i64 %sizeof_buf, i64* %sizeof_buf.addr, align 8 + call void @llvm.dbg.declare(metadata i64* %sizeof_buf.addr, metadata !41, metadata !DIExpression()), !dbg !42 + call void @llvm.dbg.declare(metadata i8** %p, metadata !43, metadata !DIExpression()), !dbg !45 + %0 = load i8*, i8** %buf.addr, align 8, !dbg !46 + store i8* %0, i8** %p, align 8, !dbg !45 + call void @llvm.dbg.declare(metadata i32* %i, metadata !47, metadata !DIExpression()), !dbg !48 + store i32 0, i32* %i, align 4, !dbg !49 + br label %for.cond, !dbg !51 + +for.cond: ; preds = %for.inc, %entry + %1 = load i32, i32* %i, align 4, !dbg !52 + %conv = sext i32 %1 to i64, !dbg !52 + %2 = load i64, i64* %sizeof_buf.addr, align 8, !dbg !54 + %cmp = icmp slt i64 %conv, %2, !dbg !55 + br i1 %cmp, label %for.body, label %for.end, !dbg !56 + +for.body: ; preds = %for.cond + %3 = load i32, i32* %i, align 4, !dbg !57 + %idxprom = sext i32 %3 to i64, !dbg !58 + %arrayidx = getelementptr inbounds [49 x i8], [49 x i8]* @.str, i64 0, i64 %idxprom, !dbg !58 + %4 = load i8, i8* %arrayidx, align 1, !dbg !58 + %5 = load i8*, i8** %p, align 8, !dbg !59 + %6 = load i32, i32* %i, align 4, !dbg !60 + %idxprom2 = sext i32 %6 to i64, !dbg !59 + %arrayidx3 = getelementptr inbounds i8, i8* %5, i64 %idxprom2, !dbg !59 + store i8 %4, i8* %arrayidx3, align 1, !dbg !61 + br label %for.inc, !dbg !59 + +for.inc: ; preds = %for.body + %7 = load i32, i32* %i, align 4, !dbg !62 + %inc = add nsw i32 %7, 1, !dbg !62 + store i32 %inc, i32* %i, align 4, !dbg !62 + br label %for.cond, !dbg !63, !llvm.loop !64 + +for.end: ; preds = %for.cond + ret void, !dbg !67 +} + +; Function Attrs: noinline nounwind optnone +define dso_local signext i32 @main() #0 !dbg !68 { +entry: + %retval = alloca i32, align 4 + %size = alloca i32, align 4 + %value = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + call void @llvm.dbg.declare(metadata i32* %size, metadata !71, metadata !DIExpression()), !dbg !72 + call void @llvm.dbg.declare(metadata i32* %value, metadata !73, metadata !DIExpression()), !dbg !74 + call void @fill_structs(), !dbg !75 + store i32 8, i32* %size, align 4, !dbg !76 + store i32 8, i32* %size, align 4, !dbg !77 + store i32 8, i32* %size, align 4, !dbg !78 + store i32 255, i32* %value, align 4, !dbg !79 + store i32 255, i32* %value, align 4, !dbg !80 + store i32 -1, i32* %value, align 4, !dbg !81 + ret i32 0, !dbg !82 +} + +; 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 = !{!2} +!llvm.module.flags = !{!19, !20, !21, !22, !23, !24} +!llvm.ident = !{!25} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "padding_long", scope: !2, file: !3, line: 7, type: !9, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 04b5c00952c39e00806bc154df348f5171919788)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !4, globals: !8, splitDebugInlining: false, nameTableKind: None) +!3 = !DIFile(filename: "dbg-combine.c", directory: "/home/xgupta/riscv/riscv-llvm/_build1") +!4 = !{!5, !6, !7} +!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!6 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_unsigned_char) +!7 = !DIBasicType(name: "signed char", size: 8, encoding: DW_ATE_signed_char) +!8 = !{!0} +!9 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !3, line: 3, size: 320, elements: !10) +!10 = !{!11, !16, !18} +!11 = !DIDerivedType(tag: DW_TAG_member, name: "p1", scope: !9, file: !3, line: 4, baseType: !12, size: 128) +!12 = !DIDerivedType(tag: DW_TAG_typedef, name: "padding", file: !3, line: 1, baseType: !13) +!13 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 128, elements: !14) +!14 = !{!15} +!15 = !DISubrange(count: 16) +!16 = !DIDerivedType(tag: DW_TAG_member, name: "v", scope: !9, file: !3, line: 5, baseType: !17, size: 64, offset: 128) +!17 = !DIBasicType(name: "long long", size: 64, encoding: DW_ATE_signed) +!18 = !DIDerivedType(tag: DW_TAG_member, name: "p2", scope: !9, file: !3, line: 6, baseType: !12, size: 128, offset: 192) +!19 = !{i32 7, !"Dwarf Version", i32 4} +!20 = !{i32 2, !"Debug Info Version", i32 3} +!21 = !{i32 1, !"wchar_size", i32 4} +!22 = !{i32 1, !"target-abi", !"lp64"} +!23 = !{i32 7, !"frame-pointer", i32 2} +!24 = !{i32 1, !"SmallDataLimit", i32 8} +!25 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 04b5c00952c39e00806bc154df348f5171919788)"} +!26 = distinct !DISubprogram(name: "fill_structs", scope: !3, file: !3, line: 19, type: !27, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !29) +!27 = !DISubroutineType(types: !28) +!28 = !{null} +!29 = !{} +!30 = !DILocation(line: 22, column: 3, scope: !26) +!31 = !DILocation(line: 23, column: 3, scope: !26) +!32 = !DILocation(line: 24, column: 3, scope: !26) +!33 = !DILocation(line: 25, column: 1, scope: !26) +!34 = distinct !DISubprogram(name: "fill", scope: !3, file: !3, line: 10, type: !35, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !2, retainedNodes: !29) +!35 = !DISubroutineType(types: !36) +!36 = !{null, !37, !38} +!37 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64) +!38 = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed) +!39 = !DILocalVariable(name: "buf", arg: 1, scope: !34, file: !3, line: 10, type: !37) +!40 = !DILocation(line: 10, column: 13, scope: !34) +!41 = !DILocalVariable(name: "sizeof_buf", arg: 2, scope: !34, file: !3, line: 10, type: !38) +!42 = !DILocation(line: 10, column: 23, scope: !34) +!43 = !DILocalVariable(name: "p", scope: !34, file: !3, line: 12, type: !44) +!44 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64) +!45 = !DILocation(line: 12, column: 9, scope: !34) +!46 = !DILocation(line: 12, column: 13, scope: !34) +!47 = !DILocalVariable(name: "i", scope: !34, file: !3, line: 13, type: !5) +!48 = !DILocation(line: 13, column: 7, scope: !34) +!49 = !DILocation(line: 14, column: 10, scope: !50) +!50 = distinct !DILexicalBlock(scope: !34, file: !3, line: 14, column: 3) +!51 = !DILocation(line: 14, column: 8, scope: !50) +!52 = !DILocation(line: 14, column: 15, scope: !53) +!53 = distinct !DILexicalBlock(scope: !50, file: !3, line: 14, column: 3) +!54 = !DILocation(line: 14, column: 19, scope: !53) +!55 = !DILocation(line: 14, column: 17, scope: !53) +!56 = !DILocation(line: 14, column: 3, scope: !50) +!57 = !DILocation(line: 15, column: 63, scope: !53) +!58 = !DILocation(line: 15, column: 12, scope: !53) +!59 = !DILocation(line: 15, column: 5, scope: !53) +!60 = !DILocation(line: 15, column: 7, scope: !53) +!61 = !DILocation(line: 15, column: 10, scope: !53) +!62 = !DILocation(line: 14, column: 32, scope: !53) +!63 = !DILocation(line: 14, column: 3, scope: !53) +!64 = distinct !{!64, !56, !65, !66} +!65 = !DILocation(line: 15, column: 64, scope: !50) +!66 = !{!"llvm.loop.mustprogress"} +!67 = !DILocation(line: 16, column: 1, scope: !34) +!68 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 27, type: !69, scopeLine: 28, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !29) +!69 = !DISubroutineType(types: !70) +!70 = !{!5} +!71 = !DILocalVariable(name: "size", scope: !68, file: !3, line: 29, type: !5) +!72 = !DILocation(line: 29, column: 7, scope: !68) +!73 = !DILocalVariable(name: "value", scope: !68, file: !3, line: 29, type: !5) +!74 = !DILocation(line: 29, column: 13, scope: !68) +!75 = !DILocation(line: 31, column: 3, scope: !68) +!76 = !DILocation(line: 33, column: 8, scope: !68) +!77 = !DILocation(line: 34, column: 8, scope: !68) +!78 = !DILocation(line: 35, column: 8, scope: !68) +!79 = !DILocation(line: 38, column: 9, scope: !68) +!80 = !DILocation(line: 39, column: 9, scope: !68) +!81 = !DILocation(line: 40, column: 9, scope: !68) +!82 = !DILocation(line: 42, column: 3, scope: !68)