Skip to content

Commit 677fbf8

Browse files
[CIR] Upstream CIR codegen for undef x86 builtins (#167945)
1 parent 7e6c913 commit 677fbf8

File tree

8 files changed

+356
-4
lines changed

8 files changed

+356
-4
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,13 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
144144
case X86::BI__builtin_ia32_undef128:
145145
case X86::BI__builtin_ia32_undef256:
146146
case X86::BI__builtin_ia32_undef512:
147-
cgm.errorNYI(expr->getSourceRange(),
148-
std::string("unimplemented X86 builtin call: ") +
149-
getContext().BuiltinInfo.getName(builtinID));
150-
return {};
147+
// The x86 definition of "undef" is not the same as the LLVM definition
148+
// (PR32176). We leave optimizing away an unnecessary zero constant to the
149+
// IR optimizer and backend.
150+
// TODO: If we had a "freeze" IR instruction to generate a fixed undef
151+
// value, we should use that here instead of a zero.
152+
return builder.getNullValue(convertType(expr->getType()),
153+
getLoc(expr->getExprLoc()));
151154
case X86::BI__builtin_ia32_vec_ext_v4hi:
152155
case X86::BI__builtin_ia32_vec_ext_v16qi:
153156
case X86::BI__builtin_ia32_vec_ext_v8hi:
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fclangir -emit-cir -o %t.cir -Wall -Werror
2+
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fno-signed-char -fclangir -emit-cir -o %t.cir -Wall -Werror
4+
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
5+
6+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fclangir -emit-llvm -o %t.ll -Wall -Werror
7+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
8+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fno-signed-char -fclangir -emit-llvm -o %t.ll -Wall -Werror
9+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
10+
11+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fclangir -emit-cir -o %t.cir -Wall -Werror
12+
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
13+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fno-signed-char -fclangir -emit-cir -o %t.cir -Wall -Werror
14+
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
15+
16+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fclangir -emit-llvm -o %t.ll -Wall -Werror
17+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
18+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fno-signed-char -fclangir -emit-llvm -o %t.ll -Wall -Werror
19+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
20+
21+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
22+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
23+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
24+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
25+
26+
// This test mimics clang/test/CodeGen/X86/avx-builtins.c, which eventually
27+
// CIR shall be able to support fully.
28+
29+
#include <immintrin.h>
30+
31+
__m256 test_mm256_undefined_ps(void) {
32+
// CIR-LABEL: _mm256_undefined_ps
33+
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<4 x !cir.double>
34+
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<4 x !cir.double> -> !cir.vector<8 x !cir.float>
35+
// CIR: cir.return %{{.*}} : !cir.vector<8 x !cir.float>
36+
37+
// LLVM-LABEL: test_mm256_undefined_ps
38+
// LLVM: store <8 x float> zeroinitializer, ptr %[[A:.*]], align 32
39+
// LLVM: %{{.*}} = load <8 x float>, ptr %[[A]], align 32
40+
// LLVM: ret <8 x float> %{{.*}}
41+
42+
// OGCG-LABEL: test_mm256_undefined_ps
43+
// OGCG: ret <8 x float> zeroinitializer
44+
return _mm256_undefined_ps();
45+
}
46+
47+
__m256d test_mm256_undefined_pd(void) {
48+
// CIR-LABEL: _mm256_undefined_pd
49+
// CIR: %{{.*}} = cir.const #cir.zero : !cir.vector<4 x !cir.double>
50+
// CIR: cir.return %{{.*}} : !cir.vector<4 x !cir.double>
51+
52+
// LLVM-LABEL: test_mm256_undefined_pd
53+
// LLVM: store <4 x double> zeroinitializer, ptr %[[A:.*]], align 32
54+
// LLVM: %{{.*}} = load <4 x double>, ptr %[[A]], align 32
55+
// LLVM: ret <4 x double> %{{.*}}
56+
57+
// OGCG-LABEL: test_mm256_undefined_pd
58+
// OGCG: ret <4 x double> zeroinitializer
59+
return _mm256_undefined_pd();
60+
}
61+
62+
__m256i test_mm256_undefined_si256(void) {
63+
// CIR-LABEL: _mm256_undefined_si256
64+
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<4 x !cir.double>
65+
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<4 x !cir.double> -> !cir.vector<4 x !s64i>
66+
// CIR: cir.return %{{.*}} : !cir.vector<4 x !s64i>
67+
68+
// LLVM-LABEL: test_mm256_undefined_si256
69+
// LLVM: store <4 x i64> zeroinitializer, ptr %[[A:.*]], align 32
70+
// LLVM: %{{.*}} = load <4 x i64>, ptr %[[A]], align 32
71+
// LLVM: ret <4 x i64> %{{.*}}
72+
73+
// OGCG-LABEL: test_mm256_undefined_si256
74+
// OGCG: ret <4 x i64> zeroinitializer
75+
return _mm256_undefined_si256();
76+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx10.2-512 -fclangir -emit-cir -o %t.cir -Wno-invalid-feature-combination -Wall -Werror -Wsign-conversion
2+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx10.2-512 -fclangir -emit-llvm -o %t.ll -Wno-invalid-feature-combination -Wall -Werror -Wsign-conversion
4+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
5+
6+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx10.2 -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=OGCG
7+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx10.2 -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=OGCG
8+
9+
#include <immintrin.h>
10+
11+
__m512bh test_mm512_undefined_pbh(void) {
12+
// CIR-LABEL: _mm512_undefined_pbh
13+
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<8 x !cir.double>
14+
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<8 x !cir.double> -> !cir.vector<32 x !cir.bf16>
15+
// CIR: cir.return %{{.*}} : !cir.vector<32 x !cir.bf16>
16+
17+
// CIR-LABEL: cir.func {{.*}}test_mm512_undefined_pbh
18+
// CIR: call @_mm512_undefined_pbh
19+
20+
// LLVM-LABEL: test_mm512_undefined_pbh
21+
// LLVM: store <32 x bfloat> zeroinitializer, ptr %[[A:.*]], align 64
22+
// LLVM: %{{.*}} = load <32 x bfloat>, ptr %[[A]], align 64
23+
// LLVM: ret <32 x bfloat> %{{.*}}
24+
25+
// OGCG-LABEL: test_mm512_undefined_pbh
26+
// OGCG: ret <32 x bfloat> zeroinitializer
27+
return _mm512_undefined_pbh();
28+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx10.2-256 -fclangir -emit-cir -o %t.cir -Wno-invalid-feature-combination -Wall -Werror -Wsign-conversion
2+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx10.2-256 -fclangir -emit-llvm -o %t.ll -Wno-invalid-feature-combination -Wall -Werror -Wsign-conversion
4+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
5+
6+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx10.2 -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=OGCG
7+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx10.2 -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=OGCG
8+
9+
#include <immintrin.h>
10+
11+
__m128bh test_mm_undefined_pbh(void) {
12+
// CIR-LABEL: _mm_undefined_pbh
13+
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<2 x !cir.double>
14+
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<2 x !cir.double> -> !cir.vector<8 x !cir.bf16>
15+
// CIR: cir.return %{{.*}} : !cir.vector<8 x !cir.bf16>
16+
17+
// CIR-LABEL: cir.func {{.*}}test_mm_undefined_pbh
18+
// CIR: call @_mm_undefined_pbh
19+
20+
// LLVM-LABEL: @test_mm_undefined_pbh
21+
// LLVM: store <8 x bfloat> zeroinitializer, ptr %[[A:.*]], align 16
22+
// LLVM: %{{.*}} = load <8 x bfloat>, ptr %[[A]], align 16
23+
// LLVM: ret <8 x bfloat> %{{.*}}
24+
25+
// OGCG-LABEL: test_mm_undefined_pbh
26+
// OGCG: ret <8 x bfloat> zeroinitializer
27+
return _mm_undefined_pbh();
28+
}
29+
30+
__m256bh test_mm256_undefined_pbh(void) {
31+
// CIR-LABEL: _mm256_undefined_pbh
32+
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<4 x !cir.double>
33+
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<4 x !cir.double> -> !cir.vector<16 x !cir.bf16>
34+
// CIR: cir.return %{{.*}} : !cir.vector<16 x !cir.bf16>
35+
36+
// CIR-LABEL: cir.func {{.*}}test_mm256_undefined_pbh
37+
// CIR: call @_mm256_undefined_pbh
38+
39+
// LLVM-LABEL: @test_mm256_undefined_pbh
40+
// LLVM: store <16 x bfloat> zeroinitializer, ptr %[[A:.*]], align 32
41+
// LLVM: %{{.*}} = load <16 x bfloat>, ptr %[[A]], align 32
42+
// LLVM: ret <16 x bfloat> %{{.*}}
43+
44+
// OGCG-LABEL: test_mm256_undefined_pbh
45+
// OGCG: ret <16 x bfloat> zeroinitializer
46+
return _mm256_undefined_pbh();
47+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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-conversion
2+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
3+
// 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-conversion
4+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
5+
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-conversion
7+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
8+
// 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-conversion
9+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
10+
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=OGCG
12+
// 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=OGCG
13+
// 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=OGCG
14+
// 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=OGCG
15+
16+
#include <immintrin.h>
17+
18+
__m512 test_mm512_undefined(void) {
19+
// CIR-LABEL: _mm512_undefined
20+
// 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_undefined
25+
// LLVM: store <16 x float> zeroinitializer, ptr %[[A:.*]], align 64
26+
// LLVM: %{{.*}} = load <16 x float>, ptr %[[A]], align 64
27+
// LLVM: ret <16 x float> %{{.*}}
28+
29+
// OGCG-LABEL: test_mm512_undefined
30+
// OGCG: ret <16 x float> zeroinitializer
31+
return _mm512_undefined();
32+
}
33+
34+
__m512 test_mm512_undefined_ps(void) {
35+
// CIR-LABEL: _mm512_undefined_ps
36+
// 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_ps
41+
// LLVM: store <16 x float> zeroinitializer, ptr %[[A:.*]], align 64
42+
// LLVM: %{{.*}} = load <16 x float>, ptr %[[A]], align 64
43+
// LLVM: ret <16 x float> %{{.*}}
44+
45+
// OGCG-LABEL: test_mm512_undefined_ps
46+
// OGCG: ret <16 x float> zeroinitializer
47+
return _mm512_undefined_ps();
48+
}
49+
50+
__m512d test_mm512_undefined_pd(void) {
51+
// CIR-LABEL: _mm512_undefined_pd
52+
// 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_pd
56+
// LLVM: store <8 x double> zeroinitializer, ptr %[[A:.*]], align 64
57+
// LLVM: %{{.*}} = load <8 x double>, ptr %[[A]], align 64
58+
// LLVM: ret <8 x double> %{{.*}}
59+
60+
// OGCG-LABEL: test_mm512_undefined_pd
61+
// OGCG: ret <8 x double> zeroinitializer
62+
return _mm512_undefined_pd();
63+
}
64+
65+
__m512i test_mm512_undefined_epi32(void) {
66+
// CIR-LABEL: _mm512_undefined_epi32
67+
// 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_epi32
72+
// LLVM: store <8 x i64> zeroinitializer, ptr %[[A:.*]], align 64
73+
// LLVM: %{{.*}} = load <8 x i64>, ptr %[[A]], align 64
74+
// LLVM: ret <8 x i64> %{{.*}}
75+
76+
// OGCG-LABEL: test_mm512_undefined_epi32
77+
// OGCG: ret <8 x i64> zeroinitializer
78+
return _mm512_undefined_epi32();
79+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512fp16 -fclangir -emit-cir -o %t.cir -Wall -Werror
2+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512fp16 -fclangir -emit-llvm -o %t.ll -Wall -Werror
4+
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
5+
6+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512fp16 -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=OGCG
7+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512fp16 -emit-llvm -o - -Wall -Werror | FileCheck %s -check-prefix=OGCG
8+
9+
#include <immintrin.h>
10+
11+
__m128h test_mm_undefined_ph(void) {
12+
// CIR-LABEL: _mm_undefined_ph
13+
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<2 x !cir.double>
14+
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<2 x !cir.double> -> !cir.vector<8 x !cir.f16>
15+
// CIR: cir.return %{{.*}} : !cir.vector<8 x !cir.f16>
16+
17+
// CIR-LABEL: cir.func {{.*}}test_mm_undefined_ph
18+
// CIR: call @_mm_undefined_ph
19+
20+
// LLVM-LABEL: @test_mm_undefined_ph
21+
// LLVM: store <8 x half> zeroinitializer, ptr %[[A:.*]], align 16
22+
// LLVM: %{{.*}} = load <8 x half>, ptr %[[A]], align 16
23+
// LLVM: ret <8 x half> %{{.*}}
24+
25+
// OGCG-LABEL: test_mm_undefined_ph
26+
// OGCG: ret <8 x half> zeroinitializer
27+
return _mm_undefined_ph();
28+
}
29+
30+
__m256h test_mm256_undefined_ph(void) {
31+
// CIR-LABEL: _mm256_undefined_ph
32+
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<4 x !cir.double>
33+
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<4 x !cir.double> -> !cir.vector<16 x !cir.f16>
34+
// CIR: cir.return %{{.*}} : !cir.vector<16 x !cir.f16>
35+
36+
// CIR-LABEL: cir.func {{.*}}test_mm256_undefined_ph
37+
// CIR: call @_mm256_undefined_ph
38+
39+
// LLVM-LABEL: @test_mm256_undefined_ph
40+
// LLVM: store <16 x half> zeroinitializer, ptr %[[A:.*]], align 32
41+
// LLVM: %{{.*}} = load <16 x half>, ptr %[[A]], align 32
42+
// LLVM: ret <16 x half> %{{.*}}
43+
44+
// OGCG-LABEL: test_mm256_undefined_ph
45+
// OGCG: ret <16 x half> zeroinitializer
46+
return _mm256_undefined_ph();
47+
}
48+
49+
__m512h test_mm512_undefined_ph(void) {
50+
// CIR-LABEL: _mm512_undefined_ph
51+
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<8 x !cir.double>
52+
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<8 x !cir.double> -> !cir.vector<32 x !cir.f16>
53+
// CIR: cir.return %{{.*}} : !cir.vector<32 x !cir.f16>
54+
55+
// CIR-LABEL: cir.func {{.*}}test_mm512_undefined_ph
56+
// CIR: call @_mm512_undefined_ph
57+
58+
// LLVM-LABEL: @test_mm512_undefined_ph
59+
// LLVM: store <32 x half> zeroinitializer, ptr %[[A:.*]], align 64
60+
// LLVM: %{{.*}} = load <32 x half>, ptr %[[A]], align 64
61+
// LLVM: ret <32 x half> %{{.*}}
62+
63+
// OGCG-LABEL: test_mm512_undefined_ph
64+
// OGCG: ret <32 x half> zeroinitializer
65+
return _mm512_undefined_ph();
66+
}

clang/test/CIR/CodeGen/X86/sse-builtins.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,19 @@ void test_mm_sfence(void) {
5555
// LLVM: call void @llvm.x86.sse.sfence()
5656
// OGCG: call void @llvm.x86.sse.sfence()
5757
}
58+
59+
__m128 test_mm_undefined_ps(void) {
60+
// CIR-LABEL: _mm_undefined_ps
61+
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<2 x !cir.double>
62+
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<2 x !cir.double> -> !cir.vector<4 x !cir.float>
63+
// CIR: cir.return %{{.*}} : !cir.vector<4 x !cir.float>
64+
65+
// LLVM-LABEL: test_mm_undefined_ps
66+
// LLVM: store <4 x float> zeroinitializer, ptr %[[A:.*]], align 16
67+
// LLVM: %{{.*}} = load <4 x float>, ptr %[[A]], align 16
68+
// LLVM: ret <4 x float> %{{.*}}
69+
70+
// OGCG-LABEL: test_mm_undefined_ps
71+
// OGCG: ret <4 x float> zeroinitializer
72+
return _mm_undefined_ps();
73+
}

clang/test/CIR/CodeGen/X86/sse2-builtins.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,43 @@
1616

1717
#include <immintrin.h>
1818

19+
__m128d test_mm_undefined_pd(void) {
20+
// CIR-LABEL: _mm_undefined_pd
21+
// CIR: %{{.*}} = cir.const #cir.zero : !cir.vector<2 x !cir.double>
22+
// CIR: cir.return %{{.*}} : !cir.vector<2 x !cir.double>
23+
24+
// CIR-LABEL: cir.func {{.*}}test_mm_undefined_pd
25+
// CIR: call @_mm_undefined_pd
26+
27+
// LLVM-LABEL: test_mm_undefined_pd
28+
// LLVM: store <2 x double> zeroinitializer, ptr %[[A:.*]], align 16
29+
// LLVM: %{{.*}} = load <2 x double>, ptr %[[A]], align 16
30+
// LLVM: ret <2 x double> %{{.*}}
31+
32+
// OGCG-LABEL: test_mm_undefined_pd
33+
// OGCG: ret <2 x double> zeroinitializer
34+
return _mm_undefined_pd();
35+
}
36+
37+
__m128i test_mm_undefined_si128(void) {
38+
// CIR-LABEL: _mm_undefined_si128
39+
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<2 x !cir.double>
40+
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<2 x !cir.double> ->
41+
// CIR: cir.return %{{.*}} :
42+
43+
// CIR-LABEL: cir.func {{.*}}test_mm_undefined_si128
44+
// CIR: call @_mm_undefined_si128
45+
46+
// LLVM-LABEL: test_mm_undefined_si128
47+
// LLVM: store <2 x i64> zeroinitializer, ptr %[[A:.*]], align 16
48+
// LLVM: %{{.*}} = load <2 x i64>, ptr %[[A]], align 16
49+
// LLVM: ret <2 x i64> %{{.*}}
50+
51+
// OGCG-LABEL: test_mm_undefined_si128
52+
// OGCG: ret <2 x i64> zeroinitializer
53+
return _mm_undefined_si128();
54+
}
55+
1956
// Lowering to pextrw requires optimization.
2057
int test_mm_extract_epi16(__m128i A) {
2158
// CIR-LABEL: test_mm_extract_epi16

0 commit comments

Comments
 (0)