@@ -293,21 +293,19 @@ static RValue emitBinaryAtomic(CIRGenFunction &CGF, cir::AtomicFetchKind kind,
293293
294294static RValue emitBinaryAtomicPost (CIRGenFunction &cgf,
295295 cir::AtomicFetchKind atomicOpkind,
296- const CallExpr *e,
297- cir::BinOpKind binopKind ) {
296+ const CallExpr *e, cir::BinOpKind binopKind,
297+ bool invert = false ) {
298298 mlir::Value val;
299299 mlir::Type valueType;
300300 clang::QualType typ = e->getType ();
301301 mlir::Value result =
302302 makeBinaryAtomicValue (cgf, atomicOpkind, e, &val, &valueType);
303303 clang::CIRGen::CIRGenBuilderTy &builder = cgf.getBuilder ();
304304 result = builder.create <cir::BinOp>(result.getLoc (), binopKind, result, val);
305+ if (invert)
306+ result = builder.create <cir::UnaryOp>(result.getLoc (),
307+ cir::UnaryOpKind::Not, result);
305308 result = emitFromInt (cgf, result, typ, valueType);
306- // FIXME: Some callers of this function expect the result to be inverted,
307- // which would need invert flag passed in and do the inversion here like
308- // traditional clang code gen does. When we implment those caller builtins
309- // we should implement the inversion here.
310- assert (!MissingFeatures::emitBinaryAtomicPostHasInvert ());
311309 return RValue::get (result);
312310}
313311
@@ -1841,7 +1839,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
18411839 case Builtin::BI__sync_nand_and_fetch_4:
18421840 case Builtin::BI__sync_nand_and_fetch_8:
18431841 case Builtin::BI__sync_nand_and_fetch_16:
1844- llvm_unreachable (" BI__sync_nand_and_fetch like NYI" );
1842+ return emitBinaryAtomicPost (*this , cir::AtomicFetchKind::Nand, E,
1843+ cir::BinOpKind::And, true );
18451844
18461845 case Builtin::BI__sync_val_compare_and_swap_1:
18471846 case Builtin::BI__sync_val_compare_and_swap_2:
0 commit comments