simplify-libcalls.ll 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ; RUN: opt -S < %s -instcombine | FileCheck %s
  2. target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f80:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32"
  3. @G = constant [3 x i8] c"%s\00" ; <[3 x i8]*> [#uses=1]
  4. declare i32 @sprintf(i8*, i8*, ...)
  5. define void @foo(i8* %P, i32* %X) {
  6. call i32 (i8*, i8*, ...) @sprintf( i8* %P, i8* getelementptr ([3 x i8], [3 x i8]* @G, i32 0, i32 0), i32* %X ) ; <i32>:1 [#uses=0]
  7. ret void
  8. }
  9. ; PR1307
  10. @str = internal constant [5 x i8] c"foog\00"
  11. @str1 = internal constant [8 x i8] c"blahhh!\00"
  12. @str2 = internal constant [5 x i8] c"Ponk\00"
  13. define i8* @test1() {
  14. %tmp3 = tail call i8* @strchr( i8* getelementptr ([5 x i8], [5 x i8]* @str, i32 0, i32 2), i32 103 ) ; <i8*> [#uses=1]
  15. ret i8* %tmp3
  16. ; CHECK-LABEL: @test1(
  17. ; CHECK: ret i8* getelementptr inbounds ([5 x i8], [5 x i8]* @str, i32 0, i32 3)
  18. }
  19. declare i8* @strchr(i8*, i32)
  20. define i8* @test2() {
  21. %tmp3 = tail call i8* @strchr( i8* getelementptr ([8 x i8], [8 x i8]* @str1, i32 0, i32 2), i32 0 ) ; <i8*> [#uses=1]
  22. ret i8* %tmp3
  23. ; CHECK-LABEL: @test2(
  24. ; CHECK: ret i8* getelementptr inbounds ([8 x i8], [8 x i8]* @str1, i32 0, i32 7)
  25. }
  26. define i8* @test3() {
  27. entry:
  28. %tmp3 = tail call i8* @strchr( i8* getelementptr ([5 x i8], [5 x i8]* @str2, i32 0, i32 1), i32 80 ) ; <i8*> [#uses=1]
  29. ret i8* %tmp3
  30. ; CHECK-LABEL: @test3(
  31. ; CHECK: ret i8* null
  32. }
  33. @_2E_str = external constant [5 x i8] ; <[5 x i8]*> [#uses=1]
  34. declare i32 @memcmp(i8*, i8*, i32) nounwind readonly
  35. define i1 @PR2341(i8** %start_addr) {
  36. entry:
  37. %tmp4 = load i8*, i8** %start_addr, align 4 ; <i8*> [#uses=1]
  38. %tmp5 = call i32 @memcmp( i8* %tmp4, i8* getelementptr ([5 x i8], [5 x i8]* @_2E_str, i32 0, i32 0), i32 4 ) nounwind readonly ; <i32> [#uses=1]
  39. %tmp6 = icmp eq i32 %tmp5, 0 ; <i1> [#uses=1]
  40. ret i1 %tmp6
  41. ; CHECK-LABEL: @PR2341(
  42. ; CHECK: i32
  43. }
  44. define i32 @PR4284() nounwind {
  45. entry:
  46. %c0 = alloca i8, align 1 ; <i8*> [#uses=2]
  47. %c2 = alloca i8, align 1 ; <i8*> [#uses=2]
  48. store i8 64, i8* %c0
  49. store i8 -127, i8* %c2
  50. %call = call i32 @memcmp(i8* %c0, i8* %c2, i32 1) ; <i32> [#uses=1]
  51. ret i32 %call
  52. ; CHECK-LABEL: @PR4284(
  53. ; CHECK: ret i32 -65
  54. }
  55. %struct.__sFILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, i8*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64, %struct.pthread_mutex*, %struct.pthread*, i32, i32, %union.anon }
  56. %struct.__sbuf = type { i8*, i32, [4 x i8] }
  57. %struct.pthread = type opaque
  58. %struct.pthread_mutex = type opaque
  59. %union.anon = type { i64, [120 x i8] }
  60. @.str13 = external constant [2 x i8] ; <[2 x i8]*> [#uses=1]
  61. @.str14 = external constant [2 x i8] ; <[2 x i8]*> [#uses=1]
  62. define i32 @PR4641(i32 %argc, i8** %argv) nounwind {
  63. entry:
  64. call void @exit(i32 0) nounwind
  65. %cond392 = select i1 undef, i8* getelementptr ([2 x i8], [2 x i8]* @.str13, i32 0, i32 0), i8* getelementptr ([2 x i8], [2 x i8]* @.str14, i32 0, i32 0) ; <i8*> [#uses=1]
  66. %call393 = call %struct.__sFILE* @fopen(i8* undef, i8* %cond392) nounwind ; <%struct.__sFILE*> [#uses=0]
  67. unreachable
  68. }
  69. declare %struct.__sFILE* @fopen(i8*, i8*)
  70. declare void @exit(i32)
  71. define i32 @PR4645() {
  72. entry:
  73. br label %if.then
  74. lor.lhs.false: ; preds = %while.body
  75. br i1 undef, label %if.then, label %for.cond
  76. if.then: ; preds = %lor.lhs.false, %while.body
  77. call void @exit(i32 1)
  78. br label %for.cond
  79. for.cond: ; preds = %for.end, %if.then, %lor.lhs.false
  80. %j.0 = phi i32 [ %inc47, %for.end ], [ 0, %if.then ], [ 0, %lor.lhs.false ] ; <i32> [#uses=1]
  81. unreachable
  82. for.end: ; preds = %for.cond20
  83. %inc47 = add i32 %j.0, 1 ; <i32> [#uses=1]
  84. br label %for.cond
  85. }
  86. @h = constant [2 x i8] c"h\00" ; <[2 x i8]*> [#uses=1]
  87. @hel = constant [4 x i8] c"hel\00" ; <[4 x i8]*> [#uses=1]
  88. @hello_u = constant [8 x i8] c"hello_u\00" ; <[8 x i8]*> [#uses=1]
  89. define i32 @MemCpy() {
  90. %h_p = getelementptr [2 x i8], [2 x i8]* @h, i32 0, i32 0
  91. %hel_p = getelementptr [4 x i8], [4 x i8]* @hel, i32 0, i32 0
  92. %hello_u_p = getelementptr [8 x i8], [8 x i8]* @hello_u, i32 0, i32 0
  93. %target = alloca [1024 x i8]
  94. %target_p = getelementptr [1024 x i8], [1024 x i8]* %target, i32 0, i32 0
  95. call void @llvm.memcpy.p0i8.p0i8.i32(i8* %target_p, i8* %h_p, i32 2, i32 2, i1 false)
  96. call void @llvm.memcpy.p0i8.p0i8.i32(i8* %target_p, i8* %hel_p, i32 4, i32 4, i1 false)
  97. call void @llvm.memcpy.p0i8.p0i8.i32(i8* %target_p, i8* %hello_u_p, i32 8, i32 8, i1 false)
  98. ret i32 0
  99. ; CHECK-LABEL: @MemCpy(
  100. ; CHECK-NOT: llvm.memcpy
  101. ; CHECK: ret i32 0
  102. }
  103. declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
  104. declare i32 @strcmp(i8*, i8*) #0
  105. define void @test9(i8* %x) {
  106. ; CHECK-LABEL: @test9(
  107. ; CHECK-NOT: strcmp
  108. %y = call i32 @strcmp(i8* %x, i8* %x) #1
  109. ret void
  110. }
  111. attributes #0 = { nobuiltin }
  112. attributes #1 = { builtin }