gepphigep.ll 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ; RUN: opt -instcombine -S < %s | FileCheck %s
  2. %struct1 = type { %struct2*, i32, i32, i32 }
  3. %struct2 = type { i32, i32 }
  4. %struct3 = type { i32, %struct4, %struct4 }
  5. %struct4 = type { %struct2, %struct2 }
  6. define i32 @test1(%struct1* %dm, i1 %tmp4, i64 %tmp9, i64 %tmp19) {
  7. bb:
  8. %tmp = getelementptr inbounds %struct1, %struct1* %dm, i64 0, i32 0
  9. %tmp1 = load %struct2*, %struct2** %tmp, align 8
  10. br i1 %tmp4, label %bb1, label %bb2
  11. bb1:
  12. %tmp10 = getelementptr inbounds %struct2, %struct2* %tmp1, i64 %tmp9
  13. %tmp11 = getelementptr inbounds %struct2, %struct2* %tmp10, i64 0, i32 0
  14. store i32 0, i32* %tmp11, align 4
  15. br label %bb3
  16. bb2:
  17. %tmp20 = getelementptr inbounds %struct2, %struct2* %tmp1, i64 %tmp19
  18. %tmp21 = getelementptr inbounds %struct2, %struct2* %tmp20, i64 0, i32 0
  19. store i32 0, i32* %tmp21, align 4
  20. br label %bb3
  21. bb3:
  22. %phi = phi %struct2* [ %tmp10, %bb1 ], [ %tmp20, %bb2 ]
  23. %tmp24 = getelementptr inbounds %struct2, %struct2* %phi, i64 0, i32 1
  24. %tmp25 = load i32, i32* %tmp24, align 4
  25. ret i32 %tmp25
  26. ; CHECK-LABEL: @test1(
  27. ; CHECK: getelementptr inbounds %struct2, %struct2* %tmp1, i64 %tmp9, i32 0
  28. ; CHECK: getelementptr inbounds %struct2, %struct2* %tmp1, i64 %tmp19, i32 0
  29. ; CHECK: %[[PHI:[0-9A-Za-z]+]] = phi i64 [ %tmp9, %bb1 ], [ %tmp19, %bb2 ]
  30. ; CHECK: getelementptr inbounds %struct2, %struct2* %tmp1, i64 %[[PHI]], i32 1
  31. }
  32. define i32 @test2(%struct1* %dm, i1 %tmp4, i64 %tmp9, i64 %tmp19) {
  33. bb:
  34. %tmp = getelementptr inbounds %struct1, %struct1* %dm, i64 0, i32 0
  35. %tmp1 = load %struct2*, %struct2** %tmp, align 8
  36. %tmp10 = getelementptr inbounds %struct2, %struct2* %tmp1, i64 %tmp9
  37. %tmp11 = getelementptr inbounds %struct2, %struct2* %tmp10, i64 0, i32 0
  38. store i32 0, i32* %tmp11, align 4
  39. %tmp20 = getelementptr inbounds %struct2, %struct2* %tmp1, i64 %tmp19
  40. %tmp21 = getelementptr inbounds %struct2, %struct2* %tmp20, i64 0, i32 0
  41. store i32 0, i32* %tmp21, align 4
  42. %tmp24 = getelementptr inbounds %struct2, %struct2* %tmp10, i64 0, i32 1
  43. %tmp25 = load i32, i32* %tmp24, align 4
  44. ret i32 %tmp25
  45. ; CHECK-LABEL: @test2(
  46. ; CHECK: getelementptr inbounds %struct2, %struct2* %tmp1, i64 %tmp9, i32 0
  47. ; CHECK: getelementptr inbounds %struct2, %struct2* %tmp1, i64 %tmp19, i32 0
  48. ; CHECK: getelementptr inbounds %struct2, %struct2* %tmp1, i64 %tmp9, i32 1
  49. }
  50. ; Check that instcombine doesn't insert GEPs before landingpad.
  51. define i32 @test3(%struct3* %dm, i1 %tmp4, i64 %tmp9, i64 %tmp19, i64 %tmp20, i64 %tmp21) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
  52. bb:
  53. %tmp = getelementptr inbounds %struct3, %struct3* %dm, i64 0
  54. br i1 %tmp4, label %bb1, label %bb2
  55. bb1:
  56. %tmp1 = getelementptr inbounds %struct3, %struct3* %tmp, i64 %tmp19, i32 1
  57. %tmp11 = getelementptr inbounds %struct4, %struct4* %tmp1, i64 0, i32 0, i32 0
  58. store i32 0, i32* %tmp11, align 4
  59. br label %bb3
  60. bb2:
  61. %tmp2 = getelementptr inbounds %struct3, %struct3* %tmp, i64 %tmp20, i32 1
  62. %tmp12 = getelementptr inbounds %struct4, %struct4* %tmp2, i64 0, i32 0, i32 1
  63. store i32 0, i32* %tmp12, align 4
  64. br label %bb3
  65. bb3:
  66. %phi = phi %struct4* [ %tmp1, %bb1 ], [ %tmp2, %bb2 ]
  67. %tmp22 = invoke i32 @foo1(i32 11) to label %bb4 unwind label %bb5
  68. bb4:
  69. ret i32 0
  70. bb5:
  71. %tmp27 = landingpad { i8*, i32 } catch i8* bitcast (i8** @_ZTIi to i8*)
  72. %tmp34 = getelementptr inbounds %struct4, %struct4* %phi, i64 %tmp21, i32 1
  73. %tmp35 = getelementptr inbounds %struct2, %struct2* %tmp34, i64 0, i32 1
  74. %tmp25 = load i32, i32* %tmp35, align 4
  75. ret i32 %tmp25
  76. ; CHECK-LABEL: @test3(
  77. ; CHECK: bb5:
  78. ; CHECK-NEXT: {{.*}}landingpad { i8*, i32 }
  79. }
  80. @_ZTIi = external constant i8*
  81. declare i32 @__gxx_personality_v0(...)
  82. declare i32 @foo1(i32)
  83. ; Check that instcombine doesn't fold GEPs into themselves through a loop
  84. ; back-edge.
  85. define i8* @test4(i32 %value, i8* %buffer) {
  86. entry:
  87. %incptr = getelementptr inbounds i8, i8* %buffer, i64 1
  88. %cmp = icmp ugt i32 %value, 127
  89. br i1 %cmp, label %loop.header, label %exit
  90. loop.header:
  91. br label %loop.body
  92. loop.body:
  93. %loopptr = phi i8* [ %incptr, %loop.header ], [ %incptr2, %loop.body ]
  94. %newval = phi i32 [ %value, %loop.header ], [ %shr, %loop.body ]
  95. %shr = lshr i32 %newval, 7
  96. %incptr2 = getelementptr inbounds i8, i8* %loopptr, i64 1
  97. %cmp2 = icmp ugt i32 %shr, 127
  98. br i1 %cmp2, label %loop.body, label %loop.exit
  99. loop.exit:
  100. %exitptr = phi i8* [ %incptr2, %loop.body ]
  101. br label %exit
  102. exit:
  103. %ptr2 = phi i8* [ %exitptr, %loop.exit ], [ %incptr, %entry ]
  104. %incptr3 = getelementptr inbounds i8, i8* %ptr2, i64 1
  105. ret i8* %incptr3
  106. ; CHECK-LABEL: @test4(
  107. ; CHECK: loop.body:
  108. ; CHECK: getelementptr{{.*}}i64 1
  109. ; CHECK: exit:
  110. }