tail-dup-merge-loop-headers.ll 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. ; RUN: llc -O2 -o - %s | FileCheck %s
  2. target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
  3. target triple = "x86_64-unknown-linux-gnu"
  4. ; Function Attrs: nounwind uwtable
  5. ; CHECK-LABEL: tail_dup_merge_loops
  6. ; CHECK: # %entry
  7. ; CHECK-NOT: # %{{[a-zA-Z_]+}}
  8. ; CHECK: # %inner_loop_exit
  9. ; CHECK-NOT: # %{{[a-zA-Z_]+}}
  10. ; CHECK: # %inner_loop_latch
  11. ; CHECK-NOT: # %{{[a-zA-Z_]+}}
  12. ; CHECK: # %inner_loop_top
  13. ; CHECK-NOT: # %{{[a-zA-Z_]+}}
  14. ; CHECK: # %exit
  15. define void @tail_dup_merge_loops(i32 %a, i8* %b, i8* %c) local_unnamed_addr #0 {
  16. entry:
  17. %notlhs674.i = icmp eq i32 %a, 0
  18. br label %outer_loop_top
  19. outer_loop_top: ; preds = %inner_loop_exit, %entry
  20. %dst.0.ph.i = phi i8* [ %b, %entry ], [ %scevgep679.i, %inner_loop_exit ]
  21. br i1 %notlhs674.i, label %exit, label %inner_loop_preheader
  22. inner_loop_preheader: ; preds = %outer_loop_top
  23. br label %inner_loop_top
  24. inner_loop_top: ; preds = %inner_loop_latch, %inner_loop_preheader
  25. %dst.0.i = phi i8* [ %inc, %inner_loop_latch ], [ %dst.0.ph.i, %inner_loop_preheader ]
  26. %var = load i8, i8* %dst.0.i
  27. %tobool1.i = icmp slt i8 %var, 0
  28. br label %inner_loop_test
  29. inner_loop_test: ; preds = %inner_loop_top
  30. br i1 %tobool1.i, label %inner_loop_exit, label %inner_loop_latch
  31. inner_loop_exit: ; preds = %inner_loop_test
  32. %scevgep.i = getelementptr i8, i8* %dst.0.i, i64 1
  33. %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 0
  34. br label %outer_loop_top
  35. inner_loop_latch: ; preds = %inner_loop_test
  36. %cmp75.i = icmp ult i8* %dst.0.i, %c
  37. %inc = getelementptr i8, i8* %dst.0.i, i64 2
  38. br label %inner_loop_top
  39. exit: ; preds = %outer_loop_top
  40. ret void
  41. }
  42. @.str.6 = external unnamed_addr constant [23 x i8], align 1
  43. ; There is an erroneus check in LoopBase::addBasicBlockToLoop(), where it
  44. ; assumes that the header block for a loop is unique.
  45. ; For most of compilation this assumption is true, but during layout we allow
  46. ; this assumption to be violated. The following code will trigger the bug:
  47. ; The loops in question is eventually headed by the block shared_loop_header
  48. ;
  49. ; During layout The block labeled outer_loop_header gets tail-duplicated into
  50. ; outer_loop_latch, and into shared_preheader, and then removed. This leaves
  51. ; shared_loop_header as the header of both loops. The end result
  52. ; is that there are 2 valid loops, and that they share a header. If we re-ran
  53. ; the loop analysis, it would classify this as a single loop.
  54. ; So far this is fine as far as layout is concerned.
  55. ; After layout we tail merge blocks merge_other and merge_predecessor_split.
  56. ; We do this even though they share only a single instruction, because
  57. ; merge_predecessor_split falls through to their shared successor:
  58. ; outer_loop_latch.
  59. ; The rest of the blocks in the function are noise unfortunately. Bugpoint
  60. ; couldn't shrink the test any further.
  61. ; CHECK-LABEL: loop_shared_header
  62. ; CHECK: # %entry
  63. ; CHECK: # %shared_preheader
  64. ; CHECK: # %shared_loop_header
  65. ; CHECK: # %inner_loop_body
  66. ; CHECK: # %outer_loop_latch
  67. ; CHECK: # %merge_predecessor_split
  68. ; CHECK: # %outer_loop_latch
  69. ; CHECK: # %cleanup
  70. define i32 @loop_shared_header(i8* %exe, i32 %exesz, i32 %headsize, i32 %min, i32 %wwprva, i32 %e_lfanew, i8* readonly %wwp, i32 %wwpsz, i16 zeroext %sects) local_unnamed_addr #0 {
  71. entry:
  72. %0 = load i32, i32* undef, align 4
  73. %mul = shl nsw i32 %0, 2
  74. br i1 undef, label %if.end19, label %cleanup
  75. if.end19: ; preds = %entry
  76. %conv = zext i32 %mul to i64
  77. %call = tail call i8* @cli_calloc(i64 %conv, i64 1)
  78. %1 = icmp eq i32 %exesz, 0
  79. %notrhs = icmp eq i32 %0, 0
  80. %or.cond117.not = or i1 %1, %notrhs
  81. %or.cond202 = or i1 %or.cond117.not, undef
  82. %cmp35 = icmp ult i8* undef, %exe
  83. %or.cond203 = or i1 %or.cond202, %cmp35
  84. br i1 %or.cond203, label %cleanup, label %if.end50
  85. if.end50: ; preds = %if.end19
  86. tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %call, i8* undef, i64 %conv, i1 false)
  87. %cmp1.i.i = icmp ugt i32 %mul, 3
  88. br i1 %cmp1.i.i, label %shared_preheader, label %wunpsect.exit.thread.loopexit391
  89. shared_preheader: ; preds = %if.end50
  90. br label %outer_loop_header
  91. outer_loop_header: ; preds = %outer_loop_latch, %shared_preheader
  92. %bits.1.i = phi i8 [ 32, %shared_preheader ], [ %bits.43.i, %outer_loop_latch ]
  93. %dst.0.ph.i = phi i8* [ undef, %shared_preheader ], [ %scevgep679.i, %outer_loop_latch ]
  94. %2 = icmp eq i32 undef, 0
  95. br i1 %2, label %while.cond.us1412.i, label %shared_loop_header
  96. while.cond.us1412.i: ; preds = %outer_loop_header
  97. %.pre.i = add i8 %bits.1.i, -1
  98. %tobool2.us1420.i = icmp eq i8 %.pre.i, 0
  99. %or.cond.us1421.i = or i1 undef, %tobool2.us1420.i
  100. br i1 %or.cond.us1421.i, label %if.end41.us1436.i, label %cleanup
  101. if.end41.us1436.i: ; preds = %while.cond.us1412.i
  102. unreachable
  103. shared_loop_header: ; preds = %dup_early2, %dup_early1
  104. %dst.0.i = phi i8* [ undef, %inner_loop_body ], [ %dst.0.ph.i, %outer_loop_header ], [ undef, %dead_block ]
  105. %cmp3.i1172.i = icmp ult i8* undef, %call
  106. br i1 %cmp3.i1172.i, label %wunpsect.exit.thread.loopexit389, label %inner_loop_body
  107. inner_loop_body: ; preds = %shared_loop_header
  108. %3 = icmp slt i32 undef, 0
  109. br i1 %3, label %if.end96.i, label %shared_loop_header
  110. dead_block: ; preds = %inner_loop_body
  111. %cmp75.i = icmp ult i8* %dst.0.i, undef
  112. br label %shared_loop_header
  113. if.end96.i: ; preds = %inner_loop_body
  114. %cmp97.i = icmp ugt i32 undef, 2
  115. br i1 %cmp97.i, label %if.then99.i, label %if.end287.i
  116. if.then99.i: ; preds = %if.end96.i
  117. tail call void (i8*, ...) @cli_dbgmsg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 undef)
  118. br label %cleanup
  119. if.end287.i: ; preds = %if.end96.i
  120. %cmp291.i = icmp ne i32 undef, 1
  121. %conv294.i = select i1 %cmp291.i, i16 4, i16 3
  122. br i1 undef, label %if.end308.i, label %outer_loop_latch
  123. if.end308.i: ; preds = %if.end287.i
  124. br i1 undef, label %if.end335.i, label %merge_predecessor_split
  125. merge_predecessor_split: ; preds = %if.end308.i
  126. %4 = bitcast i8* undef to i32*
  127. br label %outer_loop_latch
  128. if.end335.i: ; preds = %if.end308.i
  129. br i1 undef, label %outer_loop_latch, label %merge_other
  130. merge_other: ; preds = %if.end335.i
  131. br label %outer_loop_latch
  132. outer_loop_latch: ; preds = %merge_other, %if.end335.i, %merge_predecessor_split, %if.end287.i
  133. %bits.43.i = phi i8 [ undef, %if.end287.i ], [ undef, %merge_other ], [ 32, %merge_predecessor_split ], [ 0, %if.end335.i ]
  134. %backsize.0.i = phi i16 [ %conv294.i, %if.end287.i ], [ 0, %merge_other ], [ 0, %merge_predecessor_split ], [ 0, %if.end335.i ]
  135. %5 = add i16 %backsize.0.i, -1
  136. %6 = zext i16 %5 to i64
  137. %scevgep.i = getelementptr i8, i8* %dst.0.ph.i, i64 1
  138. %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 %6
  139. br label %outer_loop_header
  140. wunpsect.exit.thread.loopexit389: ; preds = %shared_loop_header
  141. unreachable
  142. wunpsect.exit.thread.loopexit391: ; preds = %if.end50
  143. unreachable
  144. cleanup: ; preds = %if.then99.i, %while.cond.us1412.i, %if.end19, %entry
  145. %retval.0 = phi i32 [ 0, %if.then99.i ], [ 1, %entry ], [ 1, %if.end19 ], [ 1, %while.cond.us1412.i ]
  146. ret i32 %retval.0
  147. }
  148. ; Function Attrs: nounwind
  149. declare void @cli_dbgmsg(i8*, ...) local_unnamed_addr #0
  150. ; Function Attrs: nounwind
  151. declare i8* @cli_calloc(i64, i64) local_unnamed_addr #0
  152. ; Function Attrs: argmemonly nounwind
  153. declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #1
  154. attributes #0 = { nounwind }
  155. attributes #1 = { argmemonly nounwind }