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
2120using namespace clang ;
2221using namespace clang ::CIRGen;
@@ -66,9 +65,8 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
6665 getContext ().GetBuiltinType (builtinID, error, &iceArguments);
6766 assert (error == ASTContext::GE_None && " Error while getting builtin type." );
6867
69- for (auto [idx, arg] : llvm::enumerate (e->arguments ())) {
68+ for (auto [idx, arg] : llvm::enumerate (e->arguments ()))
7069 ops.push_back (emitScalarOrConstFoldImmArg (iceArguments, idx, arg));
71- }
7270
7371 CIRGenBuilderTy &builder = getBuilder ();
7472 mlir::Type voidTy = builder.getVoidTy ();
@@ -98,6 +96,10 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
9896 case X86::BI__builtin_ia32_undef128:
9997 case X86::BI__builtin_ia32_undef256:
10098 case X86::BI__builtin_ia32_undef512:
99+ cgm.errorNYI (e->getSourceRange (),
100+ std::string (" unimplemented X86 builtin call: " ) +
101+ getContext ().BuiltinInfo .getName (builtinID));
102+ return {};
101103 case X86::BI__builtin_ia32_vec_ext_v4hi:
102104 case X86::BI__builtin_ia32_vec_ext_v16qi:
103105 case X86::BI__builtin_ia32_vec_ext_v8hi:
@@ -107,7 +109,22 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
107109 case X86::BI__builtin_ia32_vec_ext_v32qi:
108110 case X86::BI__builtin_ia32_vec_ext_v16hi:
109111 case X86::BI__builtin_ia32_vec_ext_v8si:
110- case X86::BI__builtin_ia32_vec_ext_v4di:
112+ case X86::BI__builtin_ia32_vec_ext_v4di: {
113+ unsigned numElts = cast<cir::VectorType>(ops[0 ].getType ()).getSize ();
114+
115+ uint64_t index =
116+ ops[1 ].getDefiningOp <cir::ConstantOp>().getIntValue ().getZExtValue ();
117+
118+ index &= numElts - 1 ;
119+
120+ cir::ConstantOp indexVal =
121+ builder.getUInt64 (index, getLoc (e->getExprLoc ()));
122+
123+ // These builtins exist so we can ensure the index is an ICE and in range.
124+ // Otherwise we could just do this in the header file.
125+ return cir::VecExtractOp::create (builder, getLoc (e->getExprLoc ()), ops[0 ],
126+ indexVal);
127+ }
111128 case X86::BI__builtin_ia32_vec_set_v4hi:
112129 case X86::BI__builtin_ia32_vec_set_v16qi:
113130 case X86::BI__builtin_ia32_vec_set_v8hi:
0 commit comments