undef-resolve.ll 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. ; RUN: opt -sccp -S < %s | FileCheck %s
  2. ; PR6940
  3. define double @test1() {
  4. %t = sitofp i32 undef to double
  5. ret double %t
  6. ; CHECK-LABEL: @test1(
  7. ; CHECK: ret double 0.0
  8. }
  9. ; rdar://7832370
  10. ; Check that lots of stuff doesn't get turned into undef.
  11. define i32 @test2() nounwind readnone ssp {
  12. ; CHECK-LABEL: @test2(
  13. init:
  14. br label %control.outer.outer
  15. control.outer.loopexit.us-lcssa: ; preds = %control
  16. br label %control.outer.loopexit
  17. control.outer.loopexit: ; preds = %control.outer.loopexit.us-lcssa.us, %control.outer.loopexit.us-lcssa
  18. br label %control.outer.outer.backedge
  19. control.outer.outer: ; preds = %control.outer.outer.backedge, %init
  20. %switchCond.0.ph.ph = phi i32 [ 2, %init ], [ 3, %control.outer.outer.backedge ] ; <i32> [#uses=2]
  21. %i.0.ph.ph = phi i32 [ undef, %init ], [ %i.0.ph.ph.be, %control.outer.outer.backedge ] ; <i32> [#uses=1]
  22. %tmp4 = icmp eq i32 %i.0.ph.ph, 0 ; <i1> [#uses=1]
  23. br i1 %tmp4, label %control.outer.outer.split.us, label %control.outer.outer.control.outer.outer.split_crit_edge
  24. control.outer.outer.control.outer.outer.split_crit_edge: ; preds = %control.outer.outer
  25. br label %control.outer
  26. control.outer.outer.split.us: ; preds = %control.outer.outer
  27. br label %control.outer.us
  28. control.outer.us: ; preds = %bb3.us, %control.outer.outer.split.us
  29. %A.0.ph.us = phi i32 [ %switchCond.0.us, %bb3.us ], [ 4, %control.outer.outer.split.us ] ; <i32> [#uses=2]
  30. %switchCond.0.ph.us = phi i32 [ %A.0.ph.us, %bb3.us ], [ %switchCond.0.ph.ph, %control.outer.outer.split.us ] ; <i32> [#uses=1]
  31. br label %control.us
  32. bb3.us: ; preds = %control.us
  33. br label %control.outer.us
  34. bb0.us: ; preds = %control.us
  35. br label %control.us
  36. ; CHECK: control.us: ; preds = %bb0.us, %control.outer.us
  37. ; CHECK-NEXT: %switchCond.0.us = phi i32
  38. ; CHECK-NEXT: switch i32 %switchCond.0.us
  39. control.us: ; preds = %bb0.us, %control.outer.us
  40. %switchCond.0.us = phi i32 [ %A.0.ph.us, %bb0.us ], [ %switchCond.0.ph.us, %control.outer.us ] ; <i32> [#uses=2]
  41. switch i32 %switchCond.0.us, label %control.outer.loopexit.us-lcssa.us [
  42. i32 0, label %bb0.us
  43. i32 1, label %bb1.us-lcssa.us
  44. i32 3, label %bb3.us
  45. i32 4, label %bb4.us-lcssa.us
  46. ]
  47. control.outer.loopexit.us-lcssa.us: ; preds = %control.us
  48. br label %control.outer.loopexit
  49. bb1.us-lcssa.us: ; preds = %control.us
  50. br label %bb1
  51. bb4.us-lcssa.us: ; preds = %control.us
  52. br label %bb4
  53. control.outer: ; preds = %bb3, %control.outer.outer.control.outer.outer.split_crit_edge
  54. %A.0.ph = phi i32 [ %nextId17, %bb3 ], [ 4, %control.outer.outer.control.outer.outer.split_crit_edge ] ; <i32> [#uses=1]
  55. %switchCond.0.ph = phi i32 [ 0, %bb3 ], [ %switchCond.0.ph.ph, %control.outer.outer.control.outer.outer.split_crit_edge ] ; <i32> [#uses=1]
  56. br label %control
  57. control: ; preds = %bb0, %control.outer
  58. %switchCond.0 = phi i32 [ %A.0.ph, %bb0 ], [ %switchCond.0.ph, %control.outer ] ; <i32> [#uses=2]
  59. switch i32 %switchCond.0, label %control.outer.loopexit.us-lcssa [
  60. i32 0, label %bb0
  61. i32 1, label %bb1.us-lcssa
  62. i32 3, label %bb3
  63. i32 4, label %bb4.us-lcssa
  64. ]
  65. bb4.us-lcssa: ; preds = %control
  66. br label %bb4
  67. bb4: ; preds = %bb4.us-lcssa, %bb4.us-lcssa.us
  68. br label %control.outer.outer.backedge
  69. control.outer.outer.backedge: ; preds = %bb4, %control.outer.loopexit
  70. %i.0.ph.ph.be = phi i32 [ 1, %bb4 ], [ 0, %control.outer.loopexit ] ; <i32> [#uses=1]
  71. br label %control.outer.outer
  72. bb3: ; preds = %control
  73. %nextId17 = add i32 %switchCond.0, -2 ; <i32> [#uses=1]
  74. br label %control.outer
  75. bb0: ; preds = %control
  76. br label %control
  77. bb1.us-lcssa: ; preds = %control
  78. br label %bb1
  79. bb1: ; preds = %bb1.us-lcssa, %bb1.us-lcssa.us
  80. ret i32 0
  81. }
  82. ; Make sure SCCP honors the xor "idiom"
  83. ; rdar://9956541
  84. define i32 @test3() {
  85. %t = xor i32 undef, undef
  86. ret i32 %t
  87. ; CHECK-LABEL: @test3(
  88. ; CHECK: ret i32 0
  89. }
  90. ; Be conservative with FP ops
  91. define double @test4(double %x) {
  92. %t = fadd double %x, undef
  93. ret double %t
  94. ; CHECK-LABEL: @test4(
  95. ; CHECK: fadd double %x, undef
  96. }
  97. ; Make sure casts produce a possible value
  98. define i32 @test5() {
  99. %t = sext i8 undef to i32
  100. ret i32 %t
  101. ; CHECK-LABEL: @test5(
  102. ; CHECK: ret i32 0
  103. }
  104. ; Make sure ashr produces a possible value
  105. define i32 @test6() {
  106. %t = ashr i32 undef, 31
  107. ret i32 %t
  108. ; CHECK-LABEL: @test6(
  109. ; CHECK: ret i32 -1
  110. }
  111. ; Make sure lshr produces a possible value
  112. define i32 @test7() {
  113. %t = lshr i32 undef, 31
  114. ret i32 %t
  115. ; CHECK-LABEL: @test7(
  116. ; CHECK: ret i32 0
  117. }
  118. ; icmp eq with undef simplifies to undef
  119. define i1 @test8() {
  120. %t = icmp eq i32 undef, -1
  121. ret i1 %t
  122. ; CHECK-LABEL: @test8(
  123. ; CHECK: ret i1 undef
  124. }
  125. ; Make sure we don't conclude that relational comparisons simplify to undef
  126. define i1 @test9() {
  127. %t = icmp ugt i32 undef, -1
  128. ret i1 %t
  129. ; CHECK-LABEL: @test9(
  130. ; CHECK: icmp ugt
  131. }
  132. ; Make sure we handle extractvalue
  133. define i64 @test10() {
  134. entry:
  135. %e = extractvalue { i64, i64 } undef, 1
  136. ret i64 %e
  137. ; CHECK-LABEL: @test10(
  138. ; CHECK: ret i64 undef
  139. }