devirtualize-3.ll 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ; RUN: opt -basicaa -inline -S -scalarrepl -gvn -instcombine < %s | FileCheck %s
  2. ; PR5009
  3. ; CHECK: define i32 @main()
  4. ; CHECK-NEXT: entry:
  5. ; CHECK-NEXT: call void @exit(i32 38)
  6. 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"
  7. target triple = "x86_64-apple-darwin10.0.0"
  8. %struct.cont_t = type { void (i8*, i32)*, i8* }
  9. %struct.foo_sf_t = type { %struct.cont_t*, i32 }
  10. define i32 @main() nounwind ssp {
  11. entry:
  12. %cont = alloca %struct.cont_t, align 8 ; <%struct.cont_t*> [#uses=4]
  13. %tmp = getelementptr inbounds %struct.cont_t, %struct.cont_t* %cont, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
  14. %tmp1 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %cont, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=2]
  15. store void (i8*, i32)* bitcast (void (%struct.cont_t*, i32)* @quit to void (i8*, i32)*), void (i8*, i32)** %tmp1
  16. %tmp2 = load void (i8*, i32)*, void (i8*, i32)** %tmp1 ; <void (i8*, i32)*> [#uses=1]
  17. store void (i8*, i32)* %tmp2, void (i8*, i32)** %tmp
  18. %tmp3 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %cont, i32 0, i32 1 ; <i8**> [#uses=1]
  19. store i8* null, i8** %tmp3
  20. call void @foo(%struct.cont_t* %cont)
  21. ret i32 0
  22. }
  23. define internal void @quit(%struct.cont_t* %cont, i32 %rcode) nounwind ssp {
  24. entry:
  25. call void @exit(i32 %rcode) noreturn
  26. unreachable
  27. }
  28. define internal void @foo(%struct.cont_t* %c) nounwind ssp {
  29. entry:
  30. %sf = alloca %struct.foo_sf_t, align 8 ; <%struct.foo_sf_t*> [#uses=3]
  31. %next = alloca %struct.cont_t, align 8 ; <%struct.cont_t*> [#uses=3]
  32. %tmp = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
  33. store %struct.cont_t* %c, %struct.cont_t** %tmp
  34. %tmp2 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 1 ; <i32*> [#uses=1]
  35. store i32 2, i32* %tmp2
  36. %tmp4 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %next, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
  37. store void (i8*, i32)* bitcast (void (%struct.foo_sf_t*, i32)* @foo2 to void (i8*, i32)*), void (i8*, i32)** %tmp4
  38. %tmp5 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %next, i32 0, i32 1 ; <i8**> [#uses=1]
  39. %conv = bitcast %struct.foo_sf_t* %sf to i8* ; <i8*> [#uses=1]
  40. store i8* %conv, i8** %tmp5
  41. call void @bar(%struct.cont_t* %next, i32 14)
  42. ret void
  43. }
  44. define internal void @foo2(%struct.foo_sf_t* %sf, i32 %y) nounwind ssp {
  45. entry:
  46. %tmp1 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
  47. %tmp2 = load %struct.cont_t*, %struct.cont_t** %tmp1 ; <%struct.cont_t*> [#uses=1]
  48. %tmp3 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %tmp2, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
  49. %tmp4 = load void (i8*, i32)*, void (i8*, i32)** %tmp3 ; <void (i8*, i32)*> [#uses=1]
  50. %tmp6 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 0 ; <%struct.cont_t**> [#uses=1]
  51. %tmp7 = load %struct.cont_t*, %struct.cont_t** %tmp6 ; <%struct.cont_t*> [#uses=1]
  52. %conv = bitcast %struct.cont_t* %tmp7 to i8* ; <i8*> [#uses=1]
  53. %tmp9 = getelementptr inbounds %struct.foo_sf_t, %struct.foo_sf_t* %sf, i32 0, i32 1 ; <i32*> [#uses=1]
  54. %tmp10 = load i32, i32* %tmp9 ; <i32> [#uses=1]
  55. %mul = mul i32 %tmp10, %y ; <i32> [#uses=1]
  56. call void %tmp4(i8* %conv, i32 %mul)
  57. ret void
  58. }
  59. define internal void @bar(%struct.cont_t* %c, i32 %y) nounwind ssp {
  60. entry:
  61. %tmp1 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %c, i32 0, i32 0 ; <void (i8*, i32)**> [#uses=1]
  62. %tmp2 = load void (i8*, i32)*, void (i8*, i32)** %tmp1 ; <void (i8*, i32)*> [#uses=1]
  63. %tmp4 = getelementptr inbounds %struct.cont_t, %struct.cont_t* %c, i32 0, i32 1 ; <i8**> [#uses=1]
  64. %tmp5 = load i8*, i8** %tmp4 ; <i8*> [#uses=1]
  65. %add = add nsw i32 %y, 5 ; <i32> [#uses=1]
  66. call void %tmp2(i8* %tmp5, i32 %add)
  67. ret void
  68. }
  69. declare void @exit(i32) noreturn