R600: Fix a rare bug where swizzle optimization returns wrong values
[oota-llvm.git] / test / CodeGen / R600 / swizzle-export.ll
1 ; RUN: llc < %s -march=r600 -mcpu=redwood | FileCheck --check-prefix=EG-CHECK %s
2
3 ;EG-CHECK: @main
4 ;EG-CHECK: EXPORT T{{[0-9]+}}.XYXX
5 ;EG-CHECK: EXPORT T{{[0-9]+}}.ZXXX
6 ;EG-CHECK: EXPORT T{{[0-9]+}}.XXWX
7 ;EG-CHECK: EXPORT T{{[0-9]+}}.XXXW
8
9 define void @main() #0 {
10 main_body:
11   %0 = call float @llvm.R600.load.input(i32 4)
12   %1 = call float @llvm.R600.load.input(i32 5)
13   %2 = call float @llvm.R600.load.input(i32 6)
14   %3 = call float @llvm.R600.load.input(i32 7)
15   %4 = load <4 x float> addrspace(8)* null
16   %5 = extractelement <4 x float> %4, i32 1
17   %6 = load <4 x float> addrspace(8)* null
18   %7 = extractelement <4 x float> %6, i32 2
19   %8 = load <4 x float> addrspace(8)* null
20   %9 = extractelement <4 x float> %8, i32 0
21   %10 = fmul float 0.000000e+00, %9
22   %11 = load <4 x float> addrspace(8)* null
23   %12 = extractelement <4 x float> %11, i32 0
24   %13 = fmul float %5, %12
25   %14 = load <4 x float> addrspace(8)* null
26   %15 = extractelement <4 x float> %14, i32 0
27   %16 = fmul float 0.000000e+00, %15
28   %17 = load <4 x float> addrspace(8)* null
29   %18 = extractelement <4 x float> %17, i32 0
30   %19 = fmul float 0.000000e+00, %18
31   %20 = load <4 x float> addrspace(8)* null
32   %21 = extractelement <4 x float> %20, i32 0
33   %22 = fmul float %7, %21
34   %23 = load <4 x float> addrspace(8)* null
35   %24 = extractelement <4 x float> %23, i32 0
36   %25 = fmul float 0.000000e+00, %24
37   %26 = load <4 x float> addrspace(8)* null
38   %27 = extractelement <4 x float> %26, i32 0
39   %28 = fmul float 0.000000e+00, %27
40   %29 = load <4 x float> addrspace(8)* null
41   %30 = extractelement <4 x float> %29, i32 0
42   %31 = fmul float 0.000000e+00, %30
43   %32 = load <4 x float> addrspace(8)* null
44   %33 = extractelement <4 x float> %32, i32 0
45   %34 = fmul float 0.000000e+00, %33
46   %35 = load <4 x float> addrspace(8)* null
47   %36 = extractelement <4 x float> %35, i32 0
48   %37 = fmul float 0.000000e+00, %36
49   %38 = load <4 x float> addrspace(8)* null
50   %39 = extractelement <4 x float> %38, i32 0
51   %40 = fmul float 1.000000e+00, %39
52   %41 = load <4 x float> addrspace(8)* null
53   %42 = extractelement <4 x float> %41, i32 0
54   %43 = fmul float 0.000000e+00, %42
55   %44 = load <4 x float> addrspace(8)* null
56   %45 = extractelement <4 x float> %44, i32 0
57   %46 = fmul float 0.000000e+00, %45
58   %47 = load <4 x float> addrspace(8)* null
59   %48 = extractelement <4 x float> %47, i32 0
60   %49 = fmul float 0.000000e+00, %48
61   %50 = load <4 x float> addrspace(8)* null
62   %51 = extractelement <4 x float> %50, i32 0
63   %52 = fmul float 0.000000e+00, %51
64   %53 = load <4 x float> addrspace(8)* null
65   %54 = extractelement <4 x float> %53, i32 0
66   %55 = fmul float 1.000000e+00, %54
67   %56 = insertelement <4 x float> undef, float %0, i32 0
68   %57 = insertelement <4 x float> %56, float %1, i32 1
69   %58 = insertelement <4 x float> %57, float %2, i32 2
70   %59 = insertelement <4 x float> %58, float %3, i32 3
71   call void @llvm.R600.store.swizzle(<4 x float> %59, i32 60, i32 1)
72   %60 = insertelement <4 x float> undef, float %10, i32 0
73   %61 = insertelement <4 x float> %60, float %13, i32 1
74   %62 = insertelement <4 x float> %61, float %16, i32 2
75   %63 = insertelement <4 x float> %62, float %19, i32 3
76   call void @llvm.R600.store.swizzle(<4 x float> %63, i32 0, i32 2)
77   %64 = insertelement <4 x float> undef, float %22, i32 0
78   %65 = insertelement <4 x float> %64, float %25, i32 1
79   %66 = insertelement <4 x float> %65, float %28, i32 2
80   %67 = insertelement <4 x float> %66, float %31, i32 3
81   call void @llvm.R600.store.swizzle(<4 x float> %67, i32 1, i32 2)
82   %68 = insertelement <4 x float> undef, float %34, i32 0
83   %69 = insertelement <4 x float> %68, float %37, i32 1
84   %70 = insertelement <4 x float> %69, float %40, i32 2
85   %71 = insertelement <4 x float> %70, float %43, i32 3
86   call void @llvm.R600.store.swizzle(<4 x float> %71, i32 2, i32 2)
87   %72 = insertelement <4 x float> undef, float %46, i32 0
88   %73 = insertelement <4 x float> %72, float %49, i32 1
89   %74 = insertelement <4 x float> %73, float %52, i32 2
90   %75 = insertelement <4 x float> %74, float %55, i32 3
91   call void @llvm.R600.store.swizzle(<4 x float> %75, i32 3, i32 2)
92   ret void
93 }
94
95 ; EG-CHECK: @main2
96 ; EG-CHECK: T{{[0-9]+}}.ZXY0
97
98 define void @main2() #0 {
99 main_body:
100   %0 = call float @llvm.R600.load.input(i32 4)
101   %1 = call float @llvm.R600.load.input(i32 5)
102   %2 = call float @llvm.R600.load.input(i32 6)
103   %3 = call float @llvm.R600.load.input(i32 7)
104   %4 = load <4 x float> addrspace(8)* getelementptr ([1024 x <4 x float>] addrspace(8)* null, i64 0, i32 1)
105   %5 = extractelement <4 x float> %4, i32 0
106   %6 = call float @llvm.cos.f32(float %5)
107   %7 = load <4 x float> addrspace(8)* null
108   %8 = extractelement <4 x float> %7, i32 0
109   %9 = load <4 x float> addrspace(8)* null
110   %10 = extractelement <4 x float> %9, i32 1
111   %11 = insertelement <4 x float> undef, float %0, i32 0
112   %12 = insertelement <4 x float> %11, float %1, i32 1
113   %13 = insertelement <4 x float> %12, float %2, i32 2
114   %14 = insertelement <4 x float> %13, float %3, i32 3
115   call void @llvm.R600.store.swizzle(<4 x float> %14, i32 60, i32 1)
116   %15 = insertelement <4 x float> undef, float %6, i32 0
117   %16 = insertelement <4 x float> %15, float %8, i32 1
118   %17 = insertelement <4 x float> %16, float %10, i32 2
119   %18 = insertelement <4 x float> %17, float 0.000000e+00, i32 3
120   call void @llvm.R600.store.swizzle(<4 x float> %18, i32 0, i32 2)
121   ret void
122 }
123
124 ; Function Attrs: readnone
125 declare float @llvm.R600.load.input(i32) #1
126
127 ; Function Attrs: nounwind readonly
128 declare float @llvm.cos.f32(float) #2
129
130 declare void @llvm.R600.store.swizzle(<4 x float>, i32, i32)
131
132 attributes #0 = { "ShaderType"="1" }
133 attributes #1 = { readnone }
134 attributes #2 = { nounwind readonly }