xref: /llvm-project/clang/test/CodeGen/fp-matrix-pragma.c (revision c9ab1d890586bd8a6a194e6a37968538b80f81bd)
1 // RUN: %clang -emit-llvm -S -fenable-matrix -mllvm -disable-llvm-optzns %s -o - | FileCheck %s
2 // UNSUPPORTED: target={{.*}}-zos{{.*}}
3 
4 typedef float fx2x2_t __attribute__((matrix_type(2, 2)));
5 typedef int ix2x2_t __attribute__((matrix_type(2, 2)));
6 
fp_matrix_contract(fx2x2_t a,fx2x2_t b,float c,float d)7 fx2x2_t fp_matrix_contract(fx2x2_t a, fx2x2_t b, float c, float d) {
8 // CHECK: call contract <4 x float> @llvm.matrix.multiply.v4f32.v4f32.v4f32
9 // CHECK: fdiv contract <4 x float>
10 // CHECK: fmul contract <4 x float>
11 #pragma clang fp contract(fast)
12   return (a * b / c) * d;
13 }
14 
fp_matrix_reassoc(fx2x2_t a,fx2x2_t b,fx2x2_t c)15 fx2x2_t fp_matrix_reassoc(fx2x2_t a, fx2x2_t b, fx2x2_t c) {
16 // CHECK: fadd reassoc <4 x float>
17 // CHECK: fsub reassoc <4 x float>
18 #pragma clang fp reassociate(on)
19   return a + b - c;
20 }
21 
fp_matrix_ops(fx2x2_t a,fx2x2_t b,fx2x2_t c)22 fx2x2_t fp_matrix_ops(fx2x2_t a, fx2x2_t b, fx2x2_t c) {
23 // CHECK: call reassoc contract <4 x float> @llvm.matrix.multiply.v4f32.v4f32.v4f32
24 // CHECK: fadd reassoc contract <4 x float>
25 #pragma clang fp contract(fast) reassociate(on)
26   return a * b + c;
27 }
28 
fp_matrix_compound_ops(fx2x2_t a,fx2x2_t b,fx2x2_t c,fx2x2_t d,float e,float f)29 fx2x2_t fp_matrix_compound_ops(fx2x2_t a, fx2x2_t b, fx2x2_t c, fx2x2_t d,
30     float e, float f) {
31 // CHECK: call reassoc contract <4 x float> @llvm.matrix.multiply.v4f32.v4f32.v4f32
32 // CHECK: fadd reassoc contract <4 x float>
33 // CHECK: fsub reassoc contract <4 x float>
34 // CHECK: fmul reassoc contract <4 x float>
35 // CHECK: fdiv reassoc contract <4 x float>
36 #pragma clang fp contract(fast) reassociate(on)
37   a *= b;
38   a += c;
39   a -= d;
40   a *= e;
41   a /= f;
42 
43   return a;
44 }
45 
int_matrix_ops(ix2x2_t a,ix2x2_t b,ix2x2_t c)46 ix2x2_t int_matrix_ops(ix2x2_t a, ix2x2_t b, ix2x2_t c) {
47 // CHECK: call <4 x i32> @llvm.matrix.multiply.v4i32.v4i32.v4i32
48 // CHECK: add <4 x i32>
49 #pragma clang fp contract(fast) reassociate(on)
50   return a * b + c;
51 }
52