memset_chk-1.ll 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. ; Test lib call simplification of __memset_chk calls with various values
  2. ; for dstlen and len.
  3. ;
  4. ; RUN: opt < %s -instcombine -S | FileCheck %s
  5. ; rdar://7719085
  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. %struct.T = type { [100 x i32], [100 x i32], [1024 x i8] }
  8. @t = common global %struct.T zeroinitializer
  9. ; Check cases where dstlen >= len.
  10. define i8* @test_simplify1() {
  11. ; CHECK-LABEL: @test_simplify1(
  12. %dst = bitcast %struct.T* @t to i8*
  13. ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.T* @t to i8*), i8 0, i64 1824, i32 4, i1 false)
  14. ; CHECK-NEXT: ret i8* bitcast (%struct.T* @t to i8*)
  15. %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 1824)
  16. ret i8* %ret
  17. }
  18. define i8* @test_simplify2() {
  19. ; CHECK-LABEL: @test_simplify2(
  20. %dst = bitcast %struct.T* @t to i8*
  21. ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.T* @t to i8*), i8 0, i64 1824, i32 4, i1 false)
  22. ; CHECK-NEXT: ret i8* bitcast (%struct.T* @t to i8*)
  23. %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 3648)
  24. ret i8* %ret
  25. }
  26. define i8* @test_simplify3() {
  27. ; CHECK-LABEL: @test_simplify3(
  28. %dst = bitcast %struct.T* @t to i8*
  29. ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.T* @t to i8*), i8 0, i64 1824, i32 4, i1 false)
  30. ; CHECK-NEXT: ret i8* bitcast (%struct.T* @t to i8*)
  31. %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 -1)
  32. ret i8* %ret
  33. }
  34. ; Check cases where dstlen < len.
  35. define i8* @test_no_simplify1() {
  36. ; CHECK-LABEL: @test_no_simplify1(
  37. %dst = bitcast %struct.T* @t to i8*
  38. ; CHECK-NEXT: %ret = call i8* @__memset_chk(i8* bitcast (%struct.T* @t to i8*), i32 0, i64 1824, i64 400)
  39. ; CHECK-NEXT: ret i8* %ret
  40. %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 400)
  41. ret i8* %ret
  42. }
  43. define i8* @test_no_simplify2() {
  44. ; CHECK-LABEL: @test_no_simplify2(
  45. %dst = bitcast %struct.T* @t to i8*
  46. ; CHECK-NEXT: %ret = call i8* @__memset_chk(i8* bitcast (%struct.T* @t to i8*), i32 0, i64 1824, i64 0)
  47. ; CHECK-NEXT: ret i8* %ret
  48. %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 0)
  49. ret i8* %ret
  50. }
  51. declare i8* @__memset_chk(i8*, i32, i64, i64)