load-pre-nonlocal.ll 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ; RUN: opt -S -o - -basicaa -domtree -gvn %s | FileCheck %s
  2. target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
  3. %struct.S1 = type { i32, i32 }
  4. @a2 = common global i32* null, align 8
  5. @a = common global i32* null, align 8
  6. @s1 = common global %struct.S1 zeroinitializer, align 8
  7. ; Check that GVN doesn't determine %2 is partially redundant.
  8. ; CHECK-LABEL: define i32 @volatile_load
  9. ; CHECK: for.body:
  10. ; CHECK: %2 = load i32, i32*
  11. ; CHECK: %3 = load volatile i32, i32*
  12. ; CHECK: for.cond.for.end_crit_edge:
  13. define i32 @volatile_load(i32 %n) {
  14. entry:
  15. %cmp6 = icmp sgt i32 %n, 0
  16. br i1 %cmp6, label %for.body.lr.ph, label %for.end
  17. for.body.lr.ph:
  18. %0 = load i32*, i32** @a2, align 8, !tbaa !1
  19. %1 = load i32*, i32** @a, align 8, !tbaa !1
  20. br label %for.body
  21. for.body:
  22. %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.body ]
  23. %s.09 = phi i32 [ 0, %for.body.lr.ph ], [ %add, %for.body ]
  24. %p.08 = phi i32* [ %0, %for.body.lr.ph ], [ %incdec.ptr, %for.body ]
  25. %2 = load i32, i32* %p.08, align 4, !tbaa !5
  26. %arrayidx = getelementptr inbounds i32, i32* %1, i64 %indvars.iv
  27. store i32 %2, i32* %arrayidx, align 4, !tbaa !5
  28. %3 = load volatile i32, i32* %p.08, align 4, !tbaa !5
  29. %add = add nsw i32 %3, %s.09
  30. %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  31. %incdec.ptr = getelementptr inbounds i32, i32* %p.08, i64 1
  32. %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  33. %exitcond = icmp ne i32 %lftr.wideiv, %n
  34. br i1 %exitcond, label %for.body, label %for.cond.for.end_crit_edge
  35. for.cond.for.end_crit_edge:
  36. %add.lcssa = phi i32 [ %add, %for.body ]
  37. br label %for.end
  38. for.end:
  39. %s.0.lcssa = phi i32 [ %add.lcssa, %for.cond.for.end_crit_edge ], [ 0, %entry ]
  40. ret i32 %s.0.lcssa
  41. }
  42. ; %1 is partially redundant if %0 can be widened to a 64-bit load.
  43. ; CHECK-LABEL: define i32 @overaligned_load
  44. ; CHECK: if.then:
  45. ; CHECK: %0 = load i64
  46. ; CHECK: [[LSHR:%[0-9]+]] = lshr i64 %0, 32, !dbg [[LSHR_LOC:![0-9]+]]
  47. ; CHECK: trunc i64 [[LSHR]] to i32
  48. ; CHECK: if.end:
  49. ; CHECK-NOT: %1 = load i32, i32*
  50. ; CHECK: [[LSHR_LOC]] = !DILocation(line: 101, column: 1, scope: !{{.*}})
  51. define i32 @overaligned_load(i32 %a, i32* nocapture %b) {
  52. entry:
  53. %cmp = icmp sgt i32 %a, 0, !dbg !14
  54. br i1 %cmp, label %if.then, label %if.else, !dbg !14
  55. if.then:
  56. %0 = load i32, i32* getelementptr inbounds (%struct.S1, %struct.S1* @s1, i64 0, i32 0), align 8, !tbaa !5, !dbg !15
  57. br label %if.end, !dbg !15
  58. if.else:
  59. %arrayidx = getelementptr inbounds i32, i32* %b, i64 2, !dbg !16
  60. store i32 10, i32* %arrayidx, align 4, !tbaa !5, !dbg !16
  61. br label %if.end, !dbg !16
  62. if.end:
  63. %i.0 = phi i32 [ %0, %if.then ], [ 0, %if.else ]
  64. %p.0 = phi i32* [ getelementptr inbounds (%struct.S1, %struct.S1* @s1, i64 0, i32 0), %if.then ], [ %b, %if.else ]
  65. %add.ptr = getelementptr inbounds i32, i32* %p.0, i64 1, !dbg !17
  66. %1 = load i32, i32* %add.ptr, align 4, !tbaa !5, !dbg !17
  67. %add1 = add nsw i32 %1, %i.0, !dbg !17
  68. ret i32 %add1, !dbg !17
  69. }
  70. !1 = !{!2, !2, i64 0}
  71. !2 = !{!"any pointer", !3, i64 0}
  72. !3 = !{!"omnipotent char", !4, i64 0}
  73. !4 = !{!"Simple C/C++ TBAA"}
  74. !5 = !{!6, !6, i64 0}
  75. !6 = !{!"int", !3, i64 0}
  76. !llvm.module.flags = !{!7, !8, !9}
  77. !7 = !{i32 2, !"Dwarf Version", i32 4}
  78. !8 = !{i32 2, !"Debug Info Version", i32 3}
  79. !9 = !{i32 1, !"PIC Level", i32 2}
  80. !10 = !{}
  81. !11 = !DISubroutineType(types: !10)
  82. !12 = !DIFile(filename: "test.cpp", directory: "/tmp")
  83. !13 = !DISubprogram(name: "test", scope: !12, file: !12, line: 99, type: !11, isLocal: false, isDefinition: true, scopeLine: 100, flags: DIFlagPrototyped, isOptimized: false, function: i32 (i32, i32*)* @overaligned_load, variables: !10)
  84. !14 = !DILocation(line: 100, column: 1, scope: !13)
  85. !15 = !DILocation(line: 101, column: 1, scope: !13)
  86. !16 = !DILocation(line: 102, column: 1, scope: !13)
  87. !17 = !DILocation(line: 103, column: 1, scope: !13)