Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,20 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
case X86::BI__builtin_ia32_tzcnt_u16:
case X86::BI__builtin_ia32_tzcnt_u32:
case X86::BI__builtin_ia32_tzcnt_u64:
case X86::BI__builtin_ia32_undef128:
case X86::BI__builtin_ia32_undef256:
case X86::BI__builtin_ia32_undef512:
cgm.errorNYI(e->getSourceRange(),
std::string("unimplemented X86 builtin call: ") +
getContext().BuiltinInfo.getName(builtinID));
return {};
case X86::BI__builtin_ia32_undef128:
case X86::BI__builtin_ia32_undef256:
case X86::BI__builtin_ia32_undef512:
// The x86 definition of "undef" is not the same as the LLVM definition
// (PR32176). We leave optimizing away an unnecessary zero constant to the
// IR optimizer and backend.
// TODO: If we had a "freeze" IR instruction to generate a fixed undef
// value, we should use that here instead of a zero.
return builder.getNullValue(convertType(e->getType()),
getLoc(e->getExprLoc()));
case X86::BI__builtin_ia32_vec_ext_v4hi:
case X86::BI__builtin_ia32_vec_ext_v16qi:
case X86::BI__builtin_ia32_vec_ext_v8hi:
Expand Down
37 changes: 37 additions & 0 deletions clang/test/CIR/CodeGen/X86/sse2-builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,43 @@

#include <immintrin.h>

__m128d test_mm_undefined_pd(void) {
// CIR-LABEL: _mm_undefined_pd
// CIR: %{{.*}} = cir.const #cir.zero : !cir.vector<2 x !cir.double>
// CIR: cir.return %{{.*}} : !cir.vector<2 x !cir.double>

// CIR-LABEL: cir.func {{.*}}test_mm_undefined_pd
// CIR: call @_mm_undefined_pd

// LLVM-LABEL: test_mm_undefined_pd
// LLVM: store <2 x double> zeroinitializer, ptr %[[A:.*]], align 16
// LLVM: %{{.*}} = load <2 x double>, ptr %[[A]], align 16
// LLVM: ret <2 x double> %{{.*}}

// OGCG-LABEL: test_mm_undefined_pd
// OGCG: ret <2 x double> zeroinitializer
return _mm_undefined_pd();
}

__m128i test_mm_undefined_si128(void) {
// CIR-LABEL: _mm_undefined_si128
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<2 x !cir.double>
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<2 x !cir.double> ->
// CIR: cir.return %{{.*}} :

// CIR-LABEL: cir.func {{.*}}test_mm_undefined_si128
// CIR: call @_mm_undefined_si128

// LLVM-LABEL: test_mm_undefined_si128
// LLVM: store <2 x i64> zeroinitializer, ptr %[[A:.*]], align 16
// LLVM: %{{.*}} = load <2 x i64>, ptr %[[A]], align 16
// LLVM: ret <2 x i64> %{{.*}}

// OGCG-LABEL: test_mm_undefined_si128
// OGCG: ret <2 x i64> zeroinitializer
return _mm_undefined_si128();
}

// Lowering to pextrw requires optimization.
int test_mm_extract_epi16(__m128i A) {
// CIR-LABEL: test_mm_extract_epi16
Expand Down
Loading