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