phi-speculation.ll 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. target datalayout =
  2. "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-S128"
  3. ; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
  4. ; ptr_phi and ptr2_phi do not alias.
  5. ; CHECK: test_noalias_1
  6. ; CHECK: NoAlias: i32* %ptr2_phi, i32* %ptr_phi
  7. define i32 @test_noalias_1(i32* %ptr2, i32 %count, i32* %coeff) {
  8. entry:
  9. %ptr = getelementptr inbounds i32, i32* %ptr2, i64 1
  10. br label %while.body
  11. while.body:
  12. %num = phi i32 [ %count, %entry ], [ %dec, %while.body ]
  13. %ptr_phi = phi i32* [ %ptr, %entry ], [ %ptr_inc, %while.body ]
  14. %ptr2_phi = phi i32* [ %ptr2, %entry ], [ %ptr2_inc, %while.body ]
  15. %result.09 = phi i32 [ 0 , %entry ], [ %add, %while.body ]
  16. %dec = add nsw i32 %num, -1
  17. %0 = load i32, i32* %ptr_phi, align 4
  18. store i32 %0, i32* %ptr2_phi, align 4
  19. %1 = load i32, i32* %coeff, align 4
  20. %2 = load i32, i32* %ptr_phi, align 4
  21. %mul = mul nsw i32 %1, %2
  22. %add = add nsw i32 %mul, %result.09
  23. %tobool = icmp eq i32 %dec, 0
  24. %ptr_inc = getelementptr inbounds i32, i32* %ptr_phi, i64 1
  25. %ptr2_inc = getelementptr inbounds i32, i32* %ptr2_phi, i64 1
  26. br i1 %tobool, label %the_exit, label %while.body
  27. the_exit:
  28. ret i32 %add
  29. }
  30. ; CHECK: test_noalias_2
  31. ; CHECK: NoAlias: i32* %ptr_outer_phi, i32* %ptr_outer_phi2
  32. ; CHECK: NoAlias: i32* %ptr2_phi, i32* %ptr_phi
  33. define i32 @test_noalias_2(i32* %ptr2, i32 %count, i32* %coeff) {
  34. entry:
  35. %ptr = getelementptr inbounds i32, i32* %ptr2, i64 1
  36. br label %outer.while.header
  37. outer.while.header:
  38. %ptr_outer_phi = phi i32* [%ptr_inc_outer, %outer.while.backedge], [ %ptr, %entry]
  39. %ptr_outer_phi2 = phi i32* [%ptr2_inc_outer, %outer.while.backedge], [ %ptr2, %entry]
  40. %num.outer = phi i32 [ %count, %entry ], [ %dec.outer, %outer.while.backedge ]
  41. br label %while.body
  42. while.body:
  43. %num = phi i32 [ %count, %outer.while.header ], [ %dec, %while.body ]
  44. %ptr_phi = phi i32* [ %ptr_outer_phi, %outer.while.header ], [ %ptr_inc, %while.body ]
  45. %ptr2_phi = phi i32* [ %ptr_outer_phi2, %outer.while.header ], [ %ptr2_inc, %while.body ]
  46. %result.09 = phi i32 [ 0 , %outer.while.header ], [ %add, %while.body ]
  47. %dec = add nsw i32 %num, -1
  48. %0 = load i32, i32* %ptr_phi, align 4
  49. store i32 %0, i32* %ptr2_phi, align 4
  50. %1 = load i32, i32* %coeff, align 4
  51. %2 = load i32, i32* %ptr_phi, align 4
  52. %mul = mul nsw i32 %1, %2
  53. %add = add nsw i32 %mul, %result.09
  54. %tobool = icmp eq i32 %dec, 0
  55. %ptr_inc = getelementptr inbounds i32, i32* %ptr_phi, i64 1
  56. %ptr2_inc = getelementptr inbounds i32, i32* %ptr2_phi, i64 1
  57. br i1 %tobool, label %outer.while.backedge, label %while.body
  58. outer.while.backedge:
  59. %ptr_inc_outer = getelementptr inbounds i32, i32* %ptr_phi, i64 1
  60. %ptr2_inc_outer = getelementptr inbounds i32, i32* %ptr2_phi, i64 1
  61. %dec.outer = add nsw i32 %num.outer, -1
  62. %br.cond = icmp eq i32 %dec.outer, 0
  63. br i1 %br.cond, label %the_exit, label %outer.while.header
  64. the_exit:
  65. ret i32 %add
  66. }
  67. ; CHECK: test_noalias_3
  68. ; CHECK: MayAlias: i8* %ptr2_phi, i8* %ptr_phi
  69. define i32 @test_noalias_3(i8* noalias %x, i8* noalias %y, i8* noalias %z,
  70. i32 %count) {
  71. entry:
  72. br label %while.body
  73. while.body:
  74. %num = phi i32 [ %count, %entry ], [ %dec, %while.body ]
  75. %ptr_phi = phi i8* [ %x, %entry ], [ %z, %while.body ]
  76. %ptr2_phi = phi i8* [ %y, %entry ], [ %ptr_phi, %while.body ]
  77. %dec = add nsw i32 %num, -1
  78. %tobool = icmp eq i32 %dec, 0
  79. br i1 %tobool, label %the_exit, label %while.body
  80. the_exit:
  81. ret i32 1
  82. }