memset-aggregate.ll 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ; PR1226
  2. ; RUN: opt < %s -scalarrepl -S | grep "ret i32 16843009"
  3. ; RUN: opt < %s -scalarrepl -S | not grep alloca
  4. ; RUN: opt < %s -scalarrepl -instcombine -S | grep "ret i16 514"
  5. target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"
  6. target triple = "i686-apple-darwin8"
  7. %struct.bar = type { %struct.foo, i64, double }
  8. %struct.foo = type { i32, i32 }
  9. define i32 @test1(%struct.foo* %P) {
  10. entry:
  11. %L = alloca %struct.foo, align 8 ; <%struct.foo*> [#uses=2]
  12. %L2 = bitcast %struct.foo* %L to i8* ; <i8*> [#uses=1]
  13. %tmp13 = bitcast %struct.foo* %P to i8* ; <i8*> [#uses=1]
  14. call void @llvm.memcpy.p0i8.p0i8.i32(i8* %L2, i8* %tmp13, i32 8, i32 4, i1 false)
  15. %tmp4 = getelementptr %struct.foo, %struct.foo* %L, i32 0, i32 0 ; <i32*> [#uses=1]
  16. %tmp5 = load i32, i32* %tmp4 ; <i32> [#uses=1]
  17. ret i32 %tmp5
  18. }
  19. define i32 @test2() {
  20. entry:
  21. %L = alloca [4 x %struct.foo], align 16 ; <[4 x %struct.foo]*> [#uses=2]
  22. %L12 = bitcast [4 x %struct.foo]* %L to i8* ; <i8*> [#uses=1]
  23. call void @llvm.memset.p0i8.i32(i8* %L12, i8 0, i32 32, i32 16, i1 false)
  24. %tmp4 = getelementptr [4 x %struct.foo], [4 x %struct.foo]* %L, i32 0, i32 0, i32 0 ; <i32*> [#uses=1]
  25. %tmp5 = load i32, i32* %tmp4 ; <i32> [#uses=1]
  26. ret i32 %tmp5
  27. }
  28. define i32 @test3() {
  29. entry:
  30. %B = alloca %struct.bar, align 16 ; <%struct.bar*> [#uses=4]
  31. %B1 = bitcast %struct.bar* %B to i8* ; <i8*> [#uses=1]
  32. call void @llvm.memset.p0i8.i32(i8* %B1, i8 1, i32 24, i32 16, i1 false)
  33. %tmp3 = getelementptr %struct.bar, %struct.bar* %B, i32 0, i32 0, i32 0 ; <i32*> [#uses=1]
  34. store i32 1, i32* %tmp3
  35. %tmp4 = getelementptr %struct.bar, %struct.bar* %B, i32 0, i32 2 ; <double*> [#uses=1]
  36. store double 1.000000e+01, double* %tmp4
  37. %tmp6 = getelementptr %struct.bar, %struct.bar* %B, i32 0, i32 0, i32 1 ; <i32*> [#uses=1]
  38. %tmp7 = load i32, i32* %tmp6 ; <i32> [#uses=1]
  39. ret i32 %tmp7
  40. }
  41. %struct.f = type { i32, i32, i32, i32, i32, i32 }
  42. define i16 @test4() nounwind {
  43. entry:
  44. %A = alloca %struct.f, align 8 ; <%struct.f*> [#uses=3]
  45. %0 = getelementptr %struct.f, %struct.f* %A, i32 0, i32 0 ; <i32*> [#uses=1]
  46. store i32 1, i32* %0, align 8
  47. %1 = getelementptr %struct.f, %struct.f* %A, i32 0, i32 1 ; <i32*> [#uses=1]
  48. %2 = bitcast i32* %1 to i8* ; <i8*> [#uses=1]
  49. call void @llvm.memset.p0i8.i32(i8* %2, i8 2, i32 12, i32 4, i1 false)
  50. %3 = getelementptr %struct.f, %struct.f* %A, i32 0, i32 2 ; <i32*> [#uses=1]
  51. %4 = load i32, i32* %3, align 8 ; <i32> [#uses=1]
  52. %retval12 = trunc i32 %4 to i16 ; <i16> [#uses=1]
  53. ret i16 %retval12
  54. }
  55. declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
  56. declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i32, i1) nounwind