inline_cleanup.ll 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. ; Test that the inliner doesn't leave around dead allocas, and that it folds
  2. ; uncond branches away after it is done specializing.
  3. ; RUN: opt < %s -inline -S | FileCheck %s
  4. @A = weak global i32 0 ; <i32*> [#uses=1]
  5. @B = weak global i32 0 ; <i32*> [#uses=1]
  6. @C = weak global i32 0 ; <i32*> [#uses=1]
  7. define internal fastcc void @foo(i32 %X) {
  8. entry:
  9. %ALL = alloca i32, align 4 ; <i32*> [#uses=1]
  10. %tmp1 = and i32 %X, 1 ; <i32> [#uses=1]
  11. %tmp1.upgrd.1 = icmp eq i32 %tmp1, 0 ; <i1> [#uses=1]
  12. br i1 %tmp1.upgrd.1, label %cond_next, label %cond_true
  13. cond_true: ; preds = %entry
  14. store i32 1, i32* @A
  15. br label %cond_next
  16. cond_next: ; preds = %cond_true, %entry
  17. %tmp4 = and i32 %X, 2 ; <i32> [#uses=1]
  18. %tmp4.upgrd.2 = icmp eq i32 %tmp4, 0 ; <i1> [#uses=1]
  19. br i1 %tmp4.upgrd.2, label %cond_next7, label %cond_true5
  20. cond_true5: ; preds = %cond_next
  21. store i32 1, i32* @B
  22. br label %cond_next7
  23. cond_next7: ; preds = %cond_true5, %cond_next
  24. %tmp10 = and i32 %X, 4 ; <i32> [#uses=1]
  25. %tmp10.upgrd.3 = icmp eq i32 %tmp10, 0 ; <i1> [#uses=1]
  26. br i1 %tmp10.upgrd.3, label %cond_next13, label %cond_true11
  27. cond_true11: ; preds = %cond_next7
  28. store i32 1, i32* @C
  29. br label %cond_next13
  30. cond_next13: ; preds = %cond_true11, %cond_next7
  31. %tmp16 = and i32 %X, 8 ; <i32> [#uses=1]
  32. %tmp16.upgrd.4 = icmp eq i32 %tmp16, 0 ; <i1> [#uses=1]
  33. br i1 %tmp16.upgrd.4, label %UnifiedReturnBlock, label %cond_true17
  34. cond_true17: ; preds = %cond_next13
  35. call void @ext( i32* %ALL )
  36. ret void
  37. UnifiedReturnBlock: ; preds = %cond_next13
  38. ret void
  39. }
  40. declare void @ext(i32*)
  41. define void @test() {
  42. ; CHECK-LABEL: @test(
  43. ; CHECK-NOT: ret
  44. ;
  45. ; FIXME: This should be a CHECK-NOT, but currently we have a bug that causes us
  46. ; to not nuke unused allocas.
  47. ; CHECK: alloca
  48. ; CHECK-NOT: ret
  49. ;
  50. ; No branches should survive the inliner's cleanup.
  51. ; CHECK-NOT: br
  52. ; CHECK: ret void
  53. entry:
  54. tail call fastcc void @foo( i32 1 )
  55. tail call fastcc void @foo( i32 2 )
  56. tail call fastcc void @foo( i32 3 )
  57. tail call fastcc void @foo( i32 8 )
  58. ret void
  59. }
  60. declare void @f(i32 %x)
  61. define void @inner2(i32 %x, i32 %y, i32 %z, i1 %b) {
  62. entry:
  63. %cmp1 = icmp ne i32 %x, 0
  64. br i1 %cmp1, label %then1, label %end1
  65. then1:
  66. call void @f(i32 %x)
  67. br label %end1
  68. end1:
  69. %x2 = and i32 %x, %z
  70. %cmp2 = icmp sgt i32 %x2, 1
  71. br i1 %cmp2, label %then2, label %end2
  72. then2:
  73. call void @f(i32 %x2)
  74. br label %end2
  75. end2:
  76. %y2 = or i32 %y, %z
  77. %cmp3 = icmp sgt i32 %y2, 0
  78. br i1 %cmp3, label %then3, label %end3
  79. then3:
  80. call void @f(i32 %y2)
  81. br label %end3
  82. end3:
  83. br i1 %b, label %end3.1, label %end3.2
  84. end3.1:
  85. %x3.1 = or i32 %x, 10
  86. br label %end3.3
  87. end3.2:
  88. %x3.2 = or i32 %x, 10
  89. br label %end3.3
  90. end3.3:
  91. %x3.3 = phi i32 [ %x3.1, %end3.1 ], [ %x3.2, %end3.2 ]
  92. %cmp4 = icmp slt i32 %x3.3, 1
  93. br i1 %cmp4, label %then4, label %end4
  94. then4:
  95. call void @f(i32 %x3.3)
  96. br label %end4
  97. end4:
  98. ret void
  99. }
  100. define void @outer2(i32 %z, i1 %b) {
  101. ; Ensure that after inlining, none of the blocks with a call to @f actually
  102. ; make it through inlining.
  103. ; CHECK-LABEL: define void @outer2(
  104. ; CHECK-NOT: call
  105. ; CHECK: ret void
  106. entry:
  107. call void @inner2(i32 0, i32 -1, i32 %z, i1 %b)
  108. ret void
  109. }
  110. define void @PR12470_inner(i16 signext %p1) nounwind uwtable {
  111. entry:
  112. br i1 undef, label %cond.true, label %cond.false
  113. cond.true:
  114. br label %cond.end
  115. cond.false:
  116. %conv = sext i16 %p1 to i32
  117. br label %cond.end
  118. cond.end:
  119. %cond = phi i32 [ undef, %cond.true ], [ 0, %cond.false ]
  120. %tobool = icmp eq i32 %cond, 0
  121. br i1 %tobool, label %if.end5, label %if.then
  122. if.then:
  123. ret void
  124. if.end5:
  125. ret void
  126. }
  127. define void @PR12470_outer() {
  128. ; This previously crashed during inliner cleanup and folding inner return
  129. ; instructions. Check that we don't crash and we produce a function with a single
  130. ; return instruction due to merging the returns of the inlined function.
  131. ; CHECK-LABEL: define void @PR12470_outer(
  132. ; CHECK-NOT: call
  133. ; CHECK: ret void
  134. ; CHECK-NOT: ret void
  135. ; CHECK: }
  136. entry:
  137. call void @PR12470_inner(i16 signext 1)
  138. ret void
  139. }
  140. define void @crasher_inner() nounwind uwtable {
  141. entry:
  142. br i1 false, label %for.end28, label %for.body6
  143. for.body6:
  144. br i1 undef, label %for.body6, label %for.cond12.for.inc26_crit_edge
  145. for.cond12.for.inc26_crit_edge:
  146. br label %for.body6.1
  147. for.end28:
  148. ret void
  149. for.body6.1:
  150. br i1 undef, label %for.body6.1, label %for.cond12.for.inc26_crit_edge.1
  151. for.cond12.for.inc26_crit_edge.1:
  152. br label %for.body6.2
  153. for.body6.2:
  154. br i1 undef, label %for.body6.2, label %for.cond12.for.inc26_crit_edge.2
  155. for.cond12.for.inc26_crit_edge.2:
  156. br label %for.end28
  157. }
  158. define void @crasher_outer() {
  159. ; CHECK-LABEL: @crasher_outer(
  160. ; CHECK-NOT: call
  161. ; CHECK: ret void
  162. ; CHECK-NOT: ret
  163. ; CHECK: }
  164. entry:
  165. tail call void @crasher_inner()
  166. ret void
  167. }