Skip to content

Commit 84b3939

Browse files
authored
[CIR][CIRGen][Builtin][X86] lower stmx and ldmx intrinsics (#1776)
1 parent 3edeb5d commit 84b3939

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,24 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
359359
}
360360
case X86::BI_mm_setcsr:
361361
case X86::BI__builtin_ia32_ldmxcsr: {
362-
llvm_unreachable("mm_setcsr NYI");
362+
Address tmp =
363+
CreateMemTemp(E->getArg(0)->getType(), getLoc(E->getExprLoc()));
364+
builder.createStore(getLoc(E->getExprLoc()), Ops[0], tmp);
365+
return builder
366+
.create<cir::LLVMIntrinsicCallOp>(
367+
getLoc(E->getExprLoc()), builder.getStringAttr("x86.sse.ldmxcsr"),
368+
builder.getVoidTy(), tmp.getPointer())
369+
.getResult();
363370
}
364371
case X86::BI_mm_getcsr:
365372
case X86::BI__builtin_ia32_stmxcsr: {
366-
llvm_unreachable("mm_getcsr NYI");
373+
Address tmp = CreateMemTemp(E->getType(), getLoc(E->getExprLoc()));
374+
builder
375+
.create<cir::LLVMIntrinsicCallOp>(
376+
getLoc(E->getExprLoc()), builder.getStringAttr("x86.sse.stmxcsr"),
377+
builder.getVoidTy(), tmp.getPointer())
378+
.getResult();
379+
return builder.createLoad(getLoc(E->getExprLoc()), tmp);
367380
}
368381

369382
case X86::BI__builtin_ia32_xsave:

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,26 @@ __m128 test_mm_undefined_ps(void) {
4242
// LLVM: ret <4 x float> %{{.*}}
4343
return _mm_undefined_ps();
4444
}
45+
46+
void test_mm_setcsr(unsigned int A) {
47+
// CIR-LABEL: test_mm_setcsr
48+
// CIR: cir.store {{.*}}, {{.*}} : !u32i
49+
// CIR: cir.llvm.intrinsic "x86.sse.ldmxcsr" {{.*}} : (!cir.ptr<!u32i>) -> !void
50+
51+
// LLVM-LABEL: test_mm_setcsr
52+
// LLVM: store i32
53+
// LLVM: call void @llvm.x86.sse.ldmxcsr(ptr {{.*}})
54+
_mm_setcsr(A);
55+
}
56+
57+
unsigned int test_mm_getcsr(void) {
58+
// CIR-LABEL: test_mm_getcsr
59+
// CIR: cir.llvm.intrinsic "x86.sse.stmxcsr" %{{.*}} : (!cir.ptr<!u32i>) -> !void
60+
// CIR: cir.load {{.*}} : !cir.ptr<!u32i>, !u32i
61+
62+
// LLVM-LABEL: test_mm_getcsr
63+
// LLVM: call void @llvm.x86.sse.stmxcsr(ptr %{{.*}})
64+
// LLVM: load i32
65+
return _mm_getcsr();
66+
}
67+

0 commit comments

Comments
 (0)