align-addr.ll 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. target datalayout = "E-p:64:64:64-p1:32:32:32-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
  3. ; Instcombine should be able to prove vector alignment in the
  4. ; presence of a few mild address computation tricks.
  5. ; CHECK-LABEL: @test0(
  6. ; CHECK: align 16
  7. define void @test0(i8* %b, i64 %n, i64 %u, i64 %y) nounwind {
  8. entry:
  9. %c = ptrtoint i8* %b to i64
  10. %d = and i64 %c, -16
  11. %e = inttoptr i64 %d to double*
  12. %v = mul i64 %u, 2
  13. %z = and i64 %y, -2
  14. %t1421 = icmp eq i64 %n, 0
  15. br i1 %t1421, label %return, label %bb
  16. bb:
  17. %i = phi i64 [ %indvar.next, %bb ], [ 20, %entry ]
  18. %j = mul i64 %i, %v
  19. %h = add i64 %j, %z
  20. %t8 = getelementptr double, double* %e, i64 %h
  21. %p = bitcast double* %t8 to <2 x double>*
  22. store <2 x double><double 0.0, double 0.0>, <2 x double>* %p, align 8
  23. %indvar.next = add i64 %i, 1
  24. %exitcond = icmp eq i64 %indvar.next, %n
  25. br i1 %exitcond, label %return, label %bb
  26. return:
  27. ret void
  28. }
  29. ; When we see a unaligned load from an insufficiently aligned global or
  30. ; alloca, increase the alignment of the load, turning it into an aligned load.
  31. ; CHECK-LABEL: @test1(
  32. ; CHECK: tmp = load
  33. ; CHECK: GLOBAL{{.*}}align 16
  34. @GLOBAL = internal global [4 x i32] zeroinitializer
  35. define <16 x i8> @test1(<2 x i64> %x) {
  36. entry:
  37. %tmp = load <16 x i8>, <16 x i8>* bitcast ([4 x i32]* @GLOBAL to <16 x i8>*), align 1
  38. ret <16 x i8> %tmp
  39. }
  40. @GLOBAL_as1 = internal addrspace(1) global [4 x i32] zeroinitializer
  41. define <16 x i8> @test1_as1(<2 x i64> %x) {
  42. ; CHECK-LABEL: @test1_as1(
  43. ; CHECK: tmp = load
  44. ; CHECK: GLOBAL_as1{{.*}}align 16
  45. %tmp = load <16 x i8>, <16 x i8> addrspace(1)* bitcast ([4 x i32] addrspace(1)* @GLOBAL_as1 to <16 x i8> addrspace(1)*), align 1
  46. ret <16 x i8> %tmp
  47. }
  48. @GLOBAL_as1_gep = internal addrspace(1) global [8 x i32] zeroinitializer
  49. define <16 x i8> @test1_as1_gep(<2 x i64> %x) {
  50. ; CHECK-LABEL: @test1_as1_gep(
  51. ; CHECK: tmp = load
  52. ; CHECK: GLOBAL_as1_gep{{.*}}align 16
  53. %tmp = load <16 x i8>, <16 x i8> addrspace(1)* bitcast (i32 addrspace(1)* getelementptr ([8 x i32], [8 x i32] addrspace(1)* @GLOBAL_as1_gep, i16 0, i16 4) to <16 x i8> addrspace(1)*), align 1
  54. ret <16 x i8> %tmp
  55. }
  56. ; When a load or store lacks an explicit alignment, add one.
  57. ; CHECK-LABEL: @test2(
  58. ; CHECK: load double, double* %p, align 8
  59. ; CHECK: store double %n, double* %p, align 8
  60. define double @test2(double* %p, double %n) nounwind {
  61. %t = load double, double* %p
  62. store double %n, double* %p
  63. ret double %t
  64. }
  65. declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
  66. declare void @use(i8*)
  67. %struct.s = type { i32, i32, i32, i32 }
  68. define void @test3(%struct.s* sret %a4) {
  69. ; Check that the alignment is bumped up the alignment of the sret type.
  70. ; CHECK-LABEL: @test3(
  71. %a4.cast = bitcast %struct.s* %a4 to i8*
  72. call void @llvm.memset.p0i8.i64(i8* %a4.cast, i8 0, i64 16, i32 1, i1 false)
  73. ; CHECK: call void @llvm.memset.p0i8.i64(i8* %a4.cast, i8 0, i64 16, i32 4, i1 false)
  74. call void @use(i8* %a4.cast)
  75. ret void
  76. }