blob: ecef8138f0b21ce5bb0032735e1f25a2e5c4458a [file] [log] [blame]
Sanjay Patelb653de12014-09-10 17:58:16 +00001; RUN: opt -S -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 < %s | FileCheck %s
Arnold Schwaighofere97c71b2013-07-11 15:21:55 +00002target datalayout = "e-p:32:32:32-S128-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f16:16:16-f32:32:32-f64:32:64-f128:128:128-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
3
4
5; We can vectorize this code because if the address computation would wrap then
6; a load from 0 would take place which is undefined behaviour in address space 0
7; according to LLVM IR semantics.
8
9; PR16592
10
Matt Arsenaulte64c7c72013-10-02 20:29:00 +000011; CHECK-LABEL: @safe(
Arnold Schwaighofere97c71b2013-07-11 15:21:55 +000012; CHECK: <4 x float>
13
14define void @safe(float* %A, float* %B, float %K) {
15entry:
16 br label %"<bb 3>"
17
18"<bb 3>":
19 %i_15 = phi i32 [ 0, %entry ], [ %i_19, %"<bb 3>" ]
David Blaikie79e6c742015-02-27 19:29:02 +000020 %pp3 = getelementptr float, float* %A, i32 %i_15
David Blaikiea79ac142015-02-27 21:17:42 +000021 %D.1396_10 = load float, float* %pp3, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000022 %pp24 = getelementptr float, float* %B, i32 %i_15
David Blaikiea79ac142015-02-27 21:17:42 +000023 %D.1398_15 = load float, float* %pp24, align 4
Arnold Schwaighofere97c71b2013-07-11 15:21:55 +000024 %D.1399_17 = fadd float %D.1398_15, %K
25 %D.1400_18 = fmul float %D.1396_10, %D.1399_17
26 store float %D.1400_18, float* %pp3, align 4
27 %i_19 = add nsw i32 %i_15, 1
28 %exitcond = icmp ne i32 %i_19, 64
29 br i1 %exitcond, label %"<bb 3>", label %return
30
31return:
32 ret void
33}
34
35; In a non-default address space we don't have this rule.
36
Matt Arsenaulte64c7c72013-10-02 20:29:00 +000037; CHECK-LABEL: @notsafe(
Arnold Schwaighofere97c71b2013-07-11 15:21:55 +000038; CHECK-NOT: <4 x float>
39
40define void @notsafe(float addrspace(5) * %A, float* %B, float %K) {
41entry:
42 br label %"<bb 3>"
43
44"<bb 3>":
45 %i_15 = phi i32 [ 0, %entry ], [ %i_19, %"<bb 3>" ]
David Blaikie79e6c742015-02-27 19:29:02 +000046 %pp3 = getelementptr float, float addrspace(5) * %A, i32 %i_15
David Blaikiea79ac142015-02-27 21:17:42 +000047 %D.1396_10 = load float, float addrspace(5) * %pp3, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000048 %pp24 = getelementptr float, float* %B, i32 %i_15
David Blaikiea79ac142015-02-27 21:17:42 +000049 %D.1398_15 = load float, float* %pp24, align 4
Arnold Schwaighofere97c71b2013-07-11 15:21:55 +000050 %D.1399_17 = fadd float %D.1398_15, %K
51 %D.1400_18 = fmul float %D.1396_10, %D.1399_17
52 store float %D.1400_18, float addrspace(5) * %pp3, align 4
53 %i_19 = add nsw i32 %i_15, 1
54 %exitcond = icmp ne i32 %i_19, 64
55 br i1 %exitcond, label %"<bb 3>", label %return
56
57return:
58 ret void
59}
60
61