[BasicAA] Revert "Revert r218714 - Make better use of zext and sign information."
[oota-llvm.git] / test / Analysis / BasicAA / zext.ll
1 ; RUN: opt < %s -basicaa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
2 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-S128"
3 target triple = "x86_64-unknown-linux-gnu"
4
5 ; CHECK-LABEL: test_with_zext
6 ; CHECK:  NoAlias: i8* %a, i8* %b
7
8 define void @test_with_zext() {
9   %1 = tail call i8* @malloc(i64 120)
10   %a = getelementptr inbounds i8* %1, i64 8
11   %2 = getelementptr inbounds i8* %1, i64 16
12   %3 = zext i32 3 to i64
13   %b = getelementptr inbounds i8* %2, i64 %3
14   ret void
15 }
16
17 ; CHECK-LABEL: test_with_lshr
18 ; CHECK:  NoAlias: i8* %a, i8* %b
19
20 define void @test_with_lshr(i64 %i) {
21   %1 = tail call i8* @malloc(i64 120)
22   %a = getelementptr inbounds i8* %1, i64 8
23   %2 = getelementptr inbounds i8* %1, i64 16
24   %3 = lshr i64 %i, 2
25   %b = getelementptr inbounds i8* %2, i64 %3
26   ret void
27 }
28
29 ; CHECK-LABEL: test_with_a_loop
30 ; CHECK:  NoAlias: i8* %a, i8* %b
31
32 define void @test_with_a_loop() {
33   %1 = tail call i8* @malloc(i64 120)
34   %a = getelementptr inbounds i8* %1, i64 8
35   %2 = getelementptr inbounds i8* %1, i64 16
36   br label %for.loop
37
38 for.loop:
39   %i = phi i32 [ 0, %0 ], [ %i.next, %for.loop ]
40   %3 = zext i32 %i to i64
41   %b = getelementptr inbounds i8* %2, i64 %3
42   %i.next = add nuw nsw i32 %i, 1
43   %4 = icmp eq i32 %i.next, 10
44   br i1 %4, label %for.loop.exit, label %for.loop
45
46 for.loop.exit:
47   ret void
48 }
49
50 ; CHECK-LABEL: test_sign_extension
51 ; CHECK:  PartialAlias: i64* %b.i64, i8* %a
52
53 define void @test_sign_extension(i32 %p) {
54   %1 = tail call i8* @malloc(i64 120)
55   %p.64 = zext i32 %p to i64
56   %a = getelementptr inbounds i8* %1, i64 %p.64
57   %p.minus1 = add i32 %p, -1
58   %p.minus1.64 = zext i32 %p.minus1 to i64
59   %b.i8 = getelementptr inbounds i8* %1, i64 %p.minus1.64
60   %b.i64 = bitcast i8* %b.i8 to i64*
61   ret void
62 }
63
64 ; CHECK-LABEL: test_fe_tools
65 ; CHECK:  PartialAlias: i32* %a, i32* %b
66
67 define void @test_fe_tools([8 x i32]* %values) {
68   br label %reorder
69
70 for.loop:
71   %i = phi i32 [ 0, %reorder ], [ %i.next, %for.loop ]
72   %idxprom = zext i32 %i to i64
73   %b = getelementptr inbounds [8 x i32]* %values, i64 0, i64 %idxprom
74   %i.next = add nuw nsw i32 %i, 1
75   %1 = icmp eq i32 %i.next, 10
76   br i1 %1, label %for.loop.exit, label %for.loop
77
78 reorder:
79   %a = getelementptr inbounds [8 x i32]* %values, i64 0, i64 1
80   br label %for.loop
81
82 for.loop.exit:
83   ret void
84 }
85
86 ; Function Attrs: nounwind
87 declare noalias i8* @malloc(i64)