Skip to content

Commit e2cc7e2

Browse files
Upstream CIR codegen for undef x86 builtins
1 parent 938f521 commit e2cc7e2

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "clang/Basic/Builtins.h"
1717
#include "clang/Basic/TargetBuiltins.h"
1818
#include "clang/CIR/MissingFeatures.h"
19-
#include "llvm/IR/IntrinsicsX86.h"
2019

2120
using namespace clang;
2221
using namespace clang::CIRGen;
@@ -60,9 +59,20 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
6059
case X86::BI__builtin_ia32_tzcnt_u16:
6160
case X86::BI__builtin_ia32_tzcnt_u32:
6261
case X86::BI__builtin_ia32_tzcnt_u64:
62+
cgm.errorNYI(e->getSourceRange(),
63+
std::string("unimplemented X86 builtin call: ") +
64+
getContext().BuiltinInfo.getName(builtinID));
65+
return {};
6366
case X86::BI__builtin_ia32_undef128:
6467
case X86::BI__builtin_ia32_undef256:
6568
case X86::BI__builtin_ia32_undef512:
69+
// The x86 definition of "undef" is not the same as the LLVM definition
70+
// (PR32176). We leave optimizing away an unnecessary zero constant to the
71+
// IR optimizer and backend.
72+
// TODO: If we had a "freeze" IR instruction to generate a fixed undef
73+
// value, we should use that here instead of a zero.
74+
return builder.getNullValue(convertType(e->getType()),
75+
getLoc(e->getExprLoc()));
6676
case X86::BI__builtin_ia32_vec_ext_v4hi:
6777
case X86::BI__builtin_ia32_vec_ext_v16qi:
6878
case X86::BI__builtin_ia32_vec_ext_v8hi:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +sse2 -fclangir -emit-cir -o %t.cir -Wall -Werror
2+
// RUN: FileCheck --check-prefixes=CIR-CHECK,CIR-X64 --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +sse2 -fno-signed-char -fclangir -emit-cir -o %t.cir -Wall -Werror
4+
// RUN: FileCheck --check-prefixes=CIR-CHECK,CIR-X64 --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 +sse2 -fclangir -emit-llvm -o %t.ll -Wall -Werror
7+
// RUN: FileCheck --check-prefixes=LLVM-CHECK,LLVM-X64 --input-file=%t.ll %s
8+
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +sse2 -fno-signed-char -fclangir -emit-llvm -o %t.ll -Wall -Werror
9+
// RUN: FileCheck --check-prefixes=LLVM-CHECK,LLVM-X64 --input-file=%t.ll %s
10+
11+
// This test mimics clang/test/CodeGen/X86/sse2-builtins.c, which eventually
12+
// CIR shall be able to support fully.
13+
14+
#include <immintrin.h>
15+
16+
__m128d test_mm_undefined_pd(void) {
17+
// CIR-X64-LABEL: _mm_undefined_pd
18+
// CIR-X64: %{{.*}} = cir.const #cir.zero : !cir.vector<2 x !cir.double>
19+
// CIR-X64: cir.return %{{.*}} : !cir.vector<2 x !cir.double>
20+
21+
// LLVM-X64-LABEL: test_mm_undefined_pd
22+
// LLVM-X64: store <2 x double> zeroinitializer, ptr %[[A:.*]], align 16
23+
// LLVM-X64: %{{.*}} = load <2 x double>, ptr %[[A]], align 16
24+
// LLVM-X64: ret <2 x double> %{{.*}}
25+
return _mm_undefined_pd();
26+
}
27+
28+
__m128i test_mm_undefined_si128(void) {
29+
// CIR-LABEL: _mm_undefined_si128
30+
// CIR-CHECK: %[[A:.*]] = cir.const #cir.zero : !cir.vector<2 x !cir.double>
31+
// CIR-CHECK: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<2 x !cir.double> -> !cir.vector<2 x !s64i>
32+
// CIR-CHECK: cir.return %{{.*}} : !cir.vector<2 x !s64i>
33+
34+
// LLVM-CHECK-LABEL: test_mm_undefined_si128
35+
// LLVM-CHECK: store <2 x i64> zeroinitializer, ptr %[[A:.*]], align 16
36+
// LLVM-CHECK: %{{.*}} = load <2 x i64>, ptr %[[A]], align 16
37+
// LLVM-CHECK: ret <2 x i64> %{{.*}}
38+
return _mm_undefined_si128();
39+
}

0 commit comments

Comments
 (0)