preserve-scev.ll 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ; RUN: opt -S < %s -indvars | opt -analyze -iv-users | grep "%cmp = icmp slt i32" | grep "= {%\.ph,+,1}<%for.cond>"
  2. ; PR8079
  3. ; Provide legal integer types.
  4. target datalayout = "n8:16:32:64"
  5. ; LoopSimplify should invalidate indvars when splitting out the
  6. ; inner loop.
  7. @maxStat = external global i32
  8. define i32 @test() nounwind {
  9. entry:
  10. br label %for.cond
  11. for.cond: ; preds = %if.then5, %if.end, %entry
  12. %cuts.1 = phi i32 [ 0, %entry ], [ %inc, %if.then5 ], [ %cuts.1, %if.end ]
  13. %0 = phi i32 [ 0, %entry ], [ %add, %if.end ], [ %add, %if.then5 ]
  14. %add = add i32 %0, 1
  15. %cmp = icmp slt i32 %0, 1
  16. %tmp1 = load i32, i32* @maxStat, align 4
  17. br i1 %cmp, label %for.body, label %for.cond14.preheader
  18. for.cond14.preheader: ; preds = %for.cond
  19. %cmp1726 = icmp sgt i32 %tmp1, 0
  20. br i1 %cmp1726, label %for.body18, label %return
  21. for.body: ; preds = %for.cond
  22. %cmp2 = icmp sgt i32 %tmp1, 100
  23. br i1 %cmp2, label %return, label %if.end
  24. if.end: ; preds = %for.body
  25. %cmp4 = icmp sgt i32 %tmp1, -1
  26. br i1 %cmp4, label %if.then5, label %for.cond
  27. if.then5: ; preds = %if.end
  28. call void @foo() nounwind
  29. %inc = add i32 %cuts.1, 1
  30. br label %for.cond
  31. for.body18: ; preds = %for.body18, %for.cond14.preheader
  32. %i13.027 = phi i32 [ %1, %for.body18 ], [ 0, %for.cond14.preheader ]
  33. call void @foo() nounwind
  34. %1 = add nsw i32 %i13.027, 1
  35. %tmp16 = load i32, i32* @maxStat, align 4
  36. %cmp17 = icmp slt i32 %1, %tmp16
  37. br i1 %cmp17, label %for.body18, label %return
  38. return: ; preds = %for.body18, %for.body, %for.cond14.preheader
  39. ret i32 0
  40. }
  41. declare void @foo() nounwind
  42. ; Notify SCEV when removing an ExitingBlock.
  43. ; CHECK-LABEL: @mergeExit(
  44. ; CHECK: while.cond191:
  45. ; CHECK: br i1 %or.cond, label %while.body197
  46. ; CHECK-NOT: land.rhs:
  47. ; CHECK: ret
  48. define void @mergeExit(i32 %MapAttrCount) nounwind uwtable ssp {
  49. entry:
  50. br i1 undef, label %if.then124, label %if.end126
  51. if.then124: ; preds = %entry
  52. unreachable
  53. if.end126: ; preds = %entry
  54. br i1 undef, label %while.body.lr.ph, label %if.end591
  55. while.body.lr.ph: ; preds = %if.end126
  56. br i1 undef, label %if.end140, label %if.then137
  57. if.then137: ; preds = %while.body.lr.ph
  58. unreachable
  59. if.end140: ; preds = %while.body.lr.ph
  60. br i1 undef, label %while.cond191.outer, label %if.then148
  61. if.then148: ; preds = %if.end140
  62. unreachable
  63. while.cond191.outer: ; preds = %if.then205, %if.end140
  64. br label %while.cond191
  65. while.cond191: ; preds = %while.body197, %while.cond191.outer
  66. %CppIndex.0 = phi i32 [ %inc, %while.body197 ], [ undef, %while.cond191.outer ]
  67. br i1 undef, label %land.rhs, label %if.then216
  68. land.rhs: ; preds = %while.cond191
  69. %inc = add i32 %CppIndex.0, 1
  70. %cmp196 = icmp ult i32 %inc, %MapAttrCount
  71. br i1 %cmp196, label %while.body197, label %if.then216
  72. while.body197: ; preds = %land.rhs
  73. br i1 undef, label %if.then205, label %while.cond191
  74. if.then205: ; preds = %while.body197
  75. br label %while.cond191.outer
  76. if.then216: ; preds = %land.rhs, %while.cond191
  77. br i1 undef, label %if.else, label %if.then221
  78. if.then221: ; preds = %if.then216
  79. unreachable
  80. if.else: ; preds = %if.then216
  81. br i1 undef, label %if.then266, label %if.end340
  82. if.then266: ; preds = %if.else
  83. switch i32 undef, label %if.else329 [
  84. i32 17, label %if.then285
  85. i32 19, label %if.then285
  86. i32 18, label %if.then285
  87. i32 15, label %if.then285
  88. ]
  89. if.then285: ; preds = %if.then266, %if.then266, %if.then266, %if.then266
  90. br i1 undef, label %if.then317, label %if.else324
  91. if.then317: ; preds = %if.then285
  92. br label %if.end340
  93. if.else324: ; preds = %if.then285
  94. unreachable
  95. if.else329: ; preds = %if.then266
  96. unreachable
  97. if.end340: ; preds = %if.then317, %if.else
  98. unreachable
  99. if.end591: ; preds = %if.end126
  100. br i1 undef, label %cond.end, label %cond.false
  101. cond.false: ; preds = %if.end591
  102. unreachable
  103. cond.end: ; preds = %if.end591
  104. ret void
  105. }