uglygep.ll 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ; RUN: opt < %s -loop-reduce -S | FileCheck %s
  2. ; LSR shouldn't consider %t8 to be an interesting user of %t6, and it
  3. ; should be able to form pretty GEPs.
  4. target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
  5. define void @Z4() nounwind {
  6. ; CHECK-LABEL: define void @Z4(
  7. bb:
  8. br label %bb3
  9. bb1: ; preds = %bb3
  10. br i1 undef, label %bb10, label %bb2
  11. bb2: ; preds = %bb1
  12. %t = add i64 %t4, 1 ; <i64> [#uses=1]
  13. br label %bb3
  14. bb3: ; preds = %bb2, %bb
  15. %t4 = phi i64 [ %t, %bb2 ], [ 0, %bb ] ; <i64> [#uses=3]
  16. br label %bb1
  17. ; CHECK: bb10:
  18. ; CHECK-NEXT: %t7 = icmp eq i64 %t4, 0
  19. ; Host %t2 computation outside the loop.
  20. ; CHECK-NEXT: [[SCEVGEP:%[^ ]+]] = getelementptr i8, i8* undef, i64 %t4
  21. ; CHECK-NEXT: br label %bb14
  22. bb10: ; preds = %bb9
  23. %t7 = icmp eq i64 %t4, 0 ; <i1> [#uses=1]
  24. %t3 = add i64 %t4, 16 ; <i64> [#uses=1]
  25. br label %bb14
  26. ; CHECK: bb14:
  27. ; CHECK-NEXT: store i8 undef, i8* [[SCEVGEP]]
  28. ; CHECK-NEXT: %t6 = load float*, float** undef
  29. ; Fold %t3's add within the address.
  30. ; CHECK-NEXT: [[SCEVGEP1:%[^ ]+]] = getelementptr float, float* %t6, i64 4
  31. ; CHECK-NEXT: [[SCEVGEP2:%[^ ]+]] = bitcast float* [[SCEVGEP1]] to i8*
  32. ; Use the induction variable (%t4) to access the right element
  33. ; CHECK-NEXT: [[ADDRESS:%[^ ]+]] = getelementptr i8, i8* [[SCEVGEP2]], i64 %t4
  34. ; CHECK-NEXT: store i8 undef, i8* [[ADDRESS]]
  35. ; CHECK-NEXT: br label %bb14
  36. bb14: ; preds = %bb14, %bb10
  37. %t2 = getelementptr inbounds i8, i8* undef, i64 %t4 ; <i8*> [#uses=1]
  38. store i8 undef, i8* %t2
  39. %t6 = load float*, float** undef
  40. %t8 = bitcast float* %t6 to i8* ; <i8*> [#uses=1]
  41. %t9 = getelementptr inbounds i8, i8* %t8, i64 %t3 ; <i8*> [#uses=1]
  42. store i8 undef, i8* %t9
  43. br label %bb14
  44. }
  45. define fastcc void @TransformLine() nounwind {
  46. ; CHECK-LABEL: @TransformLine(
  47. bb:
  48. br label %loop0
  49. ; CHECK: loop0:
  50. ; Induction variable is initialized to -2.
  51. ; CHECK-NEXT: [[PHIIV:%[^ ]+]] = phi i32 [ [[IVNEXT:%[^ ]+]], %loop0 ], [ -2, %bb ]
  52. ; CHECK-NEXT: [[IVNEXT]] = add nuw nsw i32 [[PHIIV]], 1
  53. ; CHECK-NEXT: br i1 false, label %loop0, label %bb0
  54. loop0: ; preds = %loop0, %bb
  55. %i0 = phi i32 [ %i0.next, %loop0 ], [ 0, %bb ] ; <i32> [#uses=2]
  56. %i0.next = add i32 %i0, 1 ; <i32> [#uses=1]
  57. br i1 false, label %loop0, label %bb0
  58. bb0: ; preds = %loop0
  59. br label %loop1
  60. ; CHECK: loop1:
  61. ; CHECK-NEXT: %i1 = phi i32 [ 0, %bb0 ], [ %i1.next, %bb5 ]
  62. ; IVNEXT covers the uses of %i0 and %t0.
  63. ; Therefore, %t0 has been removed.
  64. ; The critical edge has been split.
  65. ; CHECK-NEXT: br i1 false, label %bb2, label %[[LOOP1BB6:.+]]
  66. loop1: ; preds = %bb5, %bb0
  67. %i1 = phi i32 [ 0, %bb0 ], [ %i1.next, %bb5 ] ; <i32> [#uses=4]
  68. %t0 = add i32 %i0, %i1 ; <i32> [#uses=1]
  69. br i1 false, label %bb2, label %bb6
  70. ; CHECK: bb2:
  71. ; Critical edge split.
  72. ; CHECK-NEXT: br i1 true, label %[[BB2BB6:[^,]+]], label %bb5
  73. bb2: ; preds = %loop1
  74. br i1 true, label %bb6, label %bb5
  75. ; CHECK: bb5:
  76. ; CHECK-NEXT: %i1.next = add i32 %i1, 1
  77. ; CHECK-NEXT: br i1 true, label %[[BB5BB6:[^,]+]], label %loop1
  78. bb5: ; preds = %bb2
  79. %i1.next = add i32 %i1, 1 ; <i32> [#uses=1]
  80. br i1 true, label %bb6, label %loop1
  81. ; bb5 to bb6 split basic block.
  82. ; CHECK: [[BB5BB6]]:
  83. ; CHECK-NEXT: [[INITIALVAL:%[^ ]+]] = add i32 [[IVNEXT]], %i1.next
  84. ; CHECK-NEXT: br label %[[SPLITTOBB6:.+]]
  85. ; bb2 to bb6 split basic block.
  86. ; CHECK: [[BB2BB6]]:
  87. ; CHECK-NEXT: br label %[[SPLITTOBB6]]
  88. ; Split basic blocks to bb6.
  89. ; CHECK: [[SPLITTOBB6]]:
  90. ; CHECK-NEXT: [[INITP8:%[^ ]+]] = phi i32 [ [[INITIALVAL]], %[[BB5BB6]] ], [ undef, %[[BB2BB6]] ]
  91. ; CHECK-NEXT: [[INITP9:%[^ ]+]] = phi i32 [ undef, %[[BB5BB6]] ], [ %i1, %[[BB2BB6]] ]
  92. ; CHECK-NEXT: br label %bb6
  93. ; CHECK: [[LOOP1BB6]]:
  94. ; CHECK-NEXT: br label %bb6
  95. ; CHECK: bb6:
  96. ; CHECK-NEXT: %p8 = phi i32 [ undef, %[[LOOP1BB6]] ], [ [[INITP8]], %[[SPLITTOBB6]] ]
  97. ; CHECK-NEXT: %p9 = phi i32 [ %i1, %[[LOOP1BB6]] ], [ [[INITP9]], %[[SPLITTOBB6]] ]
  98. ; CHECK-NEXT: unreachable
  99. bb6: ; preds = %bb5, %bb2, %loop1
  100. %p8 = phi i32 [ %t0, %bb5 ], [ undef, %loop1 ], [ undef, %bb2 ] ; <i32> [#uses=0]
  101. %p9 = phi i32 [ undef, %bb5 ], [ %i1, %loop1 ], [ %i1, %bb2 ] ; <i32> [#uses=0]
  102. unreachable
  103. }