widen-loop-comp.ll 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. ; RUN: opt < %s -indvars -S | FileCheck %s
  2. target triple = "aarch64--linux-gnu"
  3. ; Provide legal integer types.
  4. target datalayout = "n8:16:32:64"
  5. ; Check the loop exit i32 compare instruction and operand are widened to i64
  6. ; instead of truncating IV before its use in the i32 compare instruction.
  7. @idx = common global i32 0, align 4
  8. @e = common global i32 0, align 4
  9. @ptr = common global i32* null, align 8
  10. ; CHECK-LABEL: @test1
  11. ; CHECK: for.body.lr.ph:
  12. ; CHECK: sext i32
  13. ; CHECK: for.cond:
  14. ; CHECK: icmp slt i64
  15. ; CHECK: for.body:
  16. ; CHECK: phi i64
  17. define i32 @test1() {
  18. entry:
  19. store i32 -1, i32* @idx, align 4
  20. %0 = load i32, i32* @e, align 4
  21. %cmp4 = icmp slt i32 %0, 0
  22. br i1 %cmp4, label %for.end.loopexit, label %for.body.lr.ph
  23. for.body.lr.ph:
  24. %1 = load i32*, i32** @ptr, align 8
  25. %2 = load i32, i32* @e, align 4
  26. br label %for.body
  27. for.cond:
  28. %inc = add nsw i32 %i.05, 1
  29. %cmp = icmp slt i32 %i.05, %2
  30. br i1 %cmp, label %for.body, label %for.cond.for.end.loopexit_crit_edge
  31. for.body:
  32. %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.cond ]
  33. %idxprom = sext i32 %i.05 to i64
  34. %arrayidx = getelementptr inbounds i32, i32* %1, i64 %idxprom
  35. %3 = load i32, i32* %arrayidx, align 4
  36. %tobool = icmp eq i32 %3, 0
  37. br i1 %tobool, label %if.then, label %for.cond
  38. if.then:
  39. %i.05.lcssa = phi i32 [ %i.05, %for.body ]
  40. store i32 %i.05.lcssa, i32* @idx, align 4
  41. br label %for.end
  42. for.cond.for.end.loopexit_crit_edge:
  43. br label %for.end.loopexit
  44. for.end.loopexit:
  45. br label %for.end
  46. for.end:
  47. %4 = load i32, i32* @idx, align 4
  48. ret i32 %4
  49. }
  50. ; CHECK-LABEL: @test2
  51. ; CHECK: for.body4.us
  52. ; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  53. ; CHECK: %cmp2.us = icmp slt i64
  54. ; CHECK-NOT: %2 = trunc i64 %indvars.iv.next to i32
  55. ; CHECK-NOT: %cmp2.us = icmp slt i32
  56. define void @test2([8 x i8]* %a, i8* %b, i8 %limit) {
  57. entry:
  58. %conv = zext i8 %limit to i32
  59. br i1 undef, label %for.cond1.preheader, label %for.cond1.preheader.us
  60. for.cond1.preheader.us:
  61. %storemerge5.us = phi i32 [ 0, %entry ], [ %inc14.us, %for.inc13.us ]
  62. br i1 true, label %for.body4.lr.ph.us, label %for.inc13.us
  63. for.inc13.us:
  64. %inc14.us = add nsw i32 %storemerge5.us, 1
  65. %cmp.us = icmp slt i32 %inc14.us, 4
  66. br i1 %cmp.us, label %for.cond1.preheader.us, label %for.end
  67. for.body4.us:
  68. %storemerge14.us = phi i32 [ 0, %for.body4.lr.ph.us ], [ %inc.us, %for.body4.us ]
  69. %idxprom.us = sext i32 %storemerge14.us to i64
  70. %arrayidx6.us = getelementptr inbounds [8 x i8], [8 x i8]* %a, i64 %idxprom5.us, i64 %idxprom.us
  71. %0 = load i8, i8* %arrayidx6.us, align 1
  72. %idxprom7.us = zext i8 %0 to i64
  73. %arrayidx8.us = getelementptr inbounds i8, i8* %b, i64 %idxprom7.us
  74. %1 = load i8, i8* %arrayidx8.us, align 1
  75. store i8 %1, i8* %arrayidx6.us, align 1
  76. %inc.us = add nsw i32 %storemerge14.us, 1
  77. %cmp2.us = icmp slt i32 %inc.us, %conv
  78. br i1 %cmp2.us, label %for.body4.us, label %for.inc13.us
  79. for.body4.lr.ph.us:
  80. %idxprom5.us = sext i32 %storemerge5.us to i64
  81. br label %for.body4.us
  82. for.cond1.preheader:
  83. %storemerge5 = phi i32 [ 0, %entry ], [ %inc14, %for.inc13 ]
  84. br i1 false, label %for.inc13, label %for.inc13
  85. for.inc13:
  86. %inc14 = add nsw i32 %storemerge5, 1
  87. %cmp = icmp slt i32 %inc14, 4
  88. br i1 %cmp, label %for.cond1.preheader, label %for.end
  89. for.end:
  90. ret void
  91. }
  92. ; CHECK-LABEL: @test3
  93. ; CHECK: sext i32 %b
  94. ; CHECK: for.cond:
  95. ; CHECK: phi i64
  96. ; CHECK: icmp slt i64
  97. define i32 @test3(i32* %a, i32 %b) {
  98. entry:
  99. br label %for.cond
  100. for.cond:
  101. %sum.0 = phi i32 [ 0, %entry ], [ %add, %for.body ]
  102. %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
  103. %cmp = icmp slt i32 %i.0, %b
  104. br i1 %cmp, label %for.body, label %for.end
  105. for.body:
  106. %idxprom = sext i32 %i.0 to i64
  107. %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
  108. %0 = load i32, i32* %arrayidx, align 4
  109. %add = add nsw i32 %sum.0, %0
  110. %inc = add nsw i32 %i.0, 1
  111. br label %for.cond
  112. for.end:
  113. ret i32 %sum.0
  114. }
  115. declare i32 @fn1(i8 signext)
  116. ; PR21030
  117. ; CHECK-LABEL: @test4
  118. ; CHECK: for.body:
  119. ; CHECK: phi i32
  120. ; CHECK: icmp sgt i8
  121. define i32 @test4(i32 %a) {
  122. entry:
  123. br label %for.body
  124. for.body:
  125. %c.07 = phi i8 [ -3, %entry ], [ %dec, %for.body ]
  126. %conv6 = zext i8 %c.07 to i32
  127. %or = or i32 %a, %conv6
  128. %conv3 = trunc i32 %or to i8
  129. %call = call i32 @fn1(i8 signext %conv3)
  130. %dec = add i8 %c.07, -1
  131. %cmp = icmp sgt i8 %dec, -14
  132. br i1 %cmp, label %for.body, label %for.end
  133. for.end:
  134. ret i32 0
  135. }
  136. ; CHECK-LABEL: @test5
  137. ; CHECK: zext i32 %b
  138. ; CHECK: for.cond:
  139. ; CHECK: phi i64
  140. ; CHECK: icmp ule i64
  141. define i32 @test5(i32* %a, i32 %b) {
  142. entry:
  143. br label %for.cond
  144. for.cond:
  145. %sum.0 = phi i32 [ 0, %entry ], [ %add, %for.body ]
  146. %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
  147. %cmp = icmp ule i32 %i.0, %b
  148. br i1 %cmp, label %for.body, label %for.end
  149. for.body:
  150. %idxprom = zext i32 %i.0 to i64
  151. %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
  152. %0 = load i32, i32* %arrayidx, align 4
  153. %add = add nsw i32 %sum.0, %0
  154. %inc = add nsw i32 %i.0, 1
  155. br label %for.cond
  156. for.end:
  157. ret i32 %sum.0
  158. }