231 lines · c
1// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -fclangir -emit-cir -o %t.cir -Wall -Werror -Wsign-conversion2// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s3// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -fclangir -emit-llvm -o %t.ll -Wall -Werror -Wsign-conversion4// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s5 6// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -fclangir -emit-cir -o %t.cir -Wall -Werror -Wsign-conversion7// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s8// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -fclangir -emit-llvm -o %t.ll -Wall -Werror -Wsign-conversion9// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s10 11// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefixes=OGCG12// RUN: %clang_cc1 -x c -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +avx512f -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefixes=OGCG13// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512f -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefixes=OGCG14// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -fms-extensions -fms-compatibility -ffreestanding %s -triple=x86_64-windows-msvc -target-feature +avx512f -emit-llvm -o - -Wall -Werror -Wsign-conversion | FileCheck %s --check-prefixes=OGCG15 16#include <immintrin.h>17 18__m512 test_mm512_undefined(void) {19 // CIR-LABEL: _mm512_undefined20 // CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<8 x !cir.double>21 // CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<8 x !cir.double> -> !cir.vector<16 x !cir.float>22 // CIR: cir.return %{{.*}} : !cir.vector<16 x !cir.float>23 24 // LLVM-LABEL: test_mm512_undefined25 // LLVM: store <16 x float> zeroinitializer, ptr %[[A:.*]], align 6426 // LLVM: %{{.*}} = load <16 x float>, ptr %[[A]], align 6427 // LLVM: ret <16 x float> %{{.*}}28 29 // OGCG-LABEL: test_mm512_undefined30 // OGCG: ret <16 x float> zeroinitializer31 return _mm512_undefined();32}33 34__m512 test_mm512_undefined_ps(void) {35 // CIR-LABEL: _mm512_undefined_ps36 // CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<8 x !cir.double>37 // CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<8 x !cir.double> -> !cir.vector<16 x !cir.float>38 // CIR: cir.return %{{.*}} : !cir.vector<16 x !cir.float>39 40 // LLVM-LABEL: test_mm512_undefined_ps41 // LLVM: store <16 x float> zeroinitializer, ptr %[[A:.*]], align 6442 // LLVM: %{{.*}} = load <16 x float>, ptr %[[A]], align 6443 // LLVM: ret <16 x float> %{{.*}}44 45 // OGCG-LABEL: test_mm512_undefined_ps46 // OGCG: ret <16 x float> zeroinitializer47 return _mm512_undefined_ps();48}49 50__m512d test_mm512_undefined_pd(void) {51 // CIR-LABEL: _mm512_undefined_pd52 // CIR: %{{.*}} = cir.const #cir.zero : !cir.vector<8 x !cir.double>53 // CIR: cir.return %{{.*}} : !cir.vector<8 x !cir.double>54 55 // LLVM-LABEL: test_mm512_undefined_pd56 // LLVM: store <8 x double> zeroinitializer, ptr %[[A:.*]], align 6457 // LLVM: %{{.*}} = load <8 x double>, ptr %[[A]], align 6458 // LLVM: ret <8 x double> %{{.*}}59 60 // OGCG-LABEL: test_mm512_undefined_pd61 // OGCG: ret <8 x double> zeroinitializer62 return _mm512_undefined_pd();63}64 65__m512i test_mm512_undefined_epi32(void) {66 // CIR-LABEL: _mm512_undefined_epi3267 // CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<8 x !cir.double>68 // CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<8 x !cir.double> -> !cir.vector<8 x !s64i>69 // CIR: cir.return %{{.*}} : !cir.vector<8 x !s64i>70 71 // LLVM-LABEL: test_mm512_undefined_epi3272 // LLVM: store <8 x i64> zeroinitializer, ptr %[[A:.*]], align 6473 // LLVM: %{{.*}} = load <8 x i64>, ptr %[[A]], align 6474 // LLVM: ret <8 x i64> %{{.*}}75 76 // OGCG-LABEL: test_mm512_undefined_epi3277 // OGCG: ret <8 x i64> zeroinitializer78 return _mm512_undefined_epi32();79}80 81__mmask16 test_mm512_kand(__mmask16 A, __mmask16 B) {82 // CIR-LABEL: _mm512_kand83 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>84 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>85 // CIR: cir.binop(and, {{.*}}, {{.*}}) : !cir.vector<16 x !cir.int<u, 1>>86 // CIR: cir.cast bitcast {{.*}} : !cir.vector<16 x !cir.int<u, 1>> -> !u16i87 88 // LLVM-LABEL: _mm512_kand89 // LLVM: [[L:%.*]] = bitcast i16 %{{.*}} to <16 x i1>90 // LLVM: [[R:%.*]] = bitcast i16 %{{.*}} to <16 x i1>91 // LLVM: [[RES:%.*]] = and <16 x i1> [[L]], [[R]]92 // LLVM: bitcast <16 x i1> [[RES]] to i1693 94 // OGCG-LABEL: _mm512_kand95 // OGCG: bitcast i16 %{{.*}} to <16 x i1>96 // OGCG: bitcast i16 %{{.*}} to <16 x i1>97 // OGCG: and <16 x i1>98 // OGCG: bitcast <16 x i1> {{.*}} to i1699 return _mm512_kand(A, B);100}101 102__mmask16 test_mm512_kandn(__mmask16 A, __mmask16 B) {103 // CIR-LABEL: _mm512_kandn104 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>105 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>106 // CIR: cir.unary(not, {{.*}}) : !cir.vector<16 x !cir.int<u, 1>>107 // CIR: cir.binop(and, {{.*}}, {{.*}}) : !cir.vector<16 x !cir.int<u, 1>>108 // CIR: cir.cast bitcast {{.*}} : !cir.vector<16 x !cir.int<u, 1>> -> !u16i109 110 // LLVM-LABEL: _mm512_kandn111 // LLVM: [[L:%.*]] = bitcast i16 %{{.*}} to <16 x i1>112 // LLVM: [[R:%.*]] = bitcast i16 %{{.*}} to <16 x i1>113 // LLVM: xor <16 x i1> [[L]], splat (i1 true)114 // LLVM: and <16 x i1>115 // LLVM: bitcast <16 x i1> {{.*}} to i16116 117 // OGCG-LABEL: _mm512_kandn118 // OGCG: bitcast i16 %{{.*}} to <16 x i1>119 // OGCG: bitcast i16 %{{.*}} to <16 x i1>120 // OGCG: xor <16 x i1>121 // OGCG: and <16 x i1>122 // OGCG: bitcast <16 x i1> {{.*}} to i16123 return _mm512_kandn(A, B);124}125 126__mmask16 test_mm512_kor(__mmask16 A, __mmask16 B) {127 // CIR-LABEL: _mm512_kor128 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>129 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>130 // CIR: cir.binop(or, {{.*}}, {{.*}}) : !cir.vector<16 x !cir.int<u, 1>>131 // CIR: cir.cast bitcast {{.*}} : !cir.vector<16 x !cir.int<u, 1>> -> !u16i132 133 // LLVM-LABEL: _mm512_kor134 // LLVM: [[L:%.*]] = bitcast i16 %{{.*}} to <16 x i1>135 // LLVM: [[R:%.*]] = bitcast i16 %{{.*}} to <16 x i1>136 // LLVM: or <16 x i1> [[L]], [[R]]137 // LLVM: bitcast <16 x i1> {{.*}} to i16138 139 // OGCG-LABEL: _mm512_kor140 // OGCG: bitcast i16 %{{.*}} to <16 x i1>141 // OGCG: bitcast i16 %{{.*}} to <16 x i1>142 // OGCG: or <16 x i1>143 // OGCG: bitcast <16 x i1> {{.*}} to i16144 return _mm512_kor(A, B);145}146 147__mmask16 test_mm512_kxnor(__mmask16 A, __mmask16 B) {148 // CIR-LABEL: _mm512_kxnor149 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>150 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>151 // CIR: cir.unary(not, {{.*}}) : !cir.vector<16 x !cir.int<u, 1>>152 // CIR: cir.binop(xor, {{.*}}, {{.*}}) : !cir.vector<16 x !cir.int<u, 1>>153 // CIR: cir.cast bitcast {{.*}} : !cir.vector<16 x !cir.int<u, 1>> -> !u16i154 155 // LLVM-LABEL: _mm512_kxnor156 // LLVM: [[L:%.*]] = bitcast i16 %{{.*}} to <16 x i1>157 // LLVM: [[R:%.*]] = bitcast i16 %{{.*}} to <16 x i1>158 // LLVM: [[NOT:%.*]] = xor <16 x i1> [[L]], splat (i1 true)159 // LLVM: [[RES:%.*]] = xor <16 x i1> [[NOT]], [[R]]160 // LLVM: bitcast <16 x i1> [[RES]] to i16161 162 // OGCG-LABEL: _mm512_kxnor163 // OGCG: bitcast i16 %{{.*}} to <16 x i1>164 // OGCG: bitcast i16 %{{.*}} to <16 x i1>165 // OGCG: xor <16 x i1>166 // OGCG: xor <16 x i1>167 // OGCG: bitcast <16 x i1> {{.*}} to i16168 return _mm512_kxnor(A, B);169}170 171__mmask16 test_mm512_kxor(__mmask16 A, __mmask16 B) {172 // CIR-LABEL: _mm512_kxor173 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>174 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>175 // CIR: cir.binop(xor, {{.*}}, {{.*}}) : !cir.vector<16 x !cir.int<u, 1>>176 // CIR: cir.cast bitcast {{.*}} : !cir.vector<16 x !cir.int<u, 1>> -> !u16i177 178 // LLVM-LABEL: _mm512_kxor179 // LLVM: [[L:%.*]] = bitcast i16 %{{.*}} to <16 x i1>180 // LLVM: [[R:%.*]] = bitcast i16 %{{.*}} to <16 x i1>181 // LLVM: xor <16 x i1> [[L]], [[R]]182 // LLVM: bitcast <16 x i1> {{.*}} to i16183 184 // OGCG-LABEL: _mm512_kxor185 // OGCG: bitcast i16 %{{.*}} to <16 x i1>186 // OGCG: bitcast i16 %{{.*}} to <16 x i1>187 // OGCG: xor <16 x i1>188 // OGCG: bitcast <16 x i1> {{.*}} to i16189 return _mm512_kxor(A, B);190}191 192__mmask16 test_mm512_knot(__mmask16 A) {193 // CIR-LABEL: _mm512_knot194 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>195 // CIR: cir.unary(not, {{.*}}) : !cir.vector<16 x !cir.int<u, 1>>196 // CIR: cir.cast bitcast {{.*}} : !cir.vector<16 x !cir.int<u, 1>> -> !u16i197 198 // LLVM-LABEL: _mm512_knot199 // LLVM: bitcast i16 %{{.*}} to <16 x i1>200 // LLVM: xor <16 x i1>201 // LLVM: bitcast <16 x i1> {{.*}} to i16202 203 // OGCG-LABEL: _mm512_knot204 // OGCG: bitcast i16 %{{.*}} to <16 x i1>205 // OGCG: xor <16 x i1>206 // OGCG: bitcast <16 x i1> {{.*}} to i16207 return _mm512_knot(A);208}209 210// Multiple user-level mask helpers inline to this same kmov builtin.211// CIR does not implement any special lowering for those helpers.212//213// Therefore, testing the builtin (__builtin_ia32_kmov*) directly is214// sufficient to cover the CIR lowering behavior. Testing each helper215// individually would add no new CIR paths.216 217__mmask16 test_kmov_w(__mmask16 A) {218 // CIR-LABEL: test_kmov_w219 // CIR: cir.cast bitcast {{.*}} : !u16i -> !cir.vector<16 x !cir.int<u, 1>>220 // CIR: cir.cast bitcast {{.*}} : !cir.vector<16 x !cir.int<u, 1>> -> !u16i221 222 // LLVM-LABEL: test_kmov_w223 // LLVM: bitcast i16 %{{.*}} to <16 x i1>224 // LLVM: bitcast <16 x i1> {{.*}} to i16225 226 // OGCG-LABEL: test_kmov_w227 // OGCG: bitcast i16 %{{.*}} to <16 x i1>228 // OGCG: bitcast <16 x i1> {{.*}} to i16229 return __builtin_ia32_kmovw(A);230}231