================
@@ -4230,6 +4230,38 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl
GD, unsigned BuiltinID,
return RValue::get(Phi);
}
+ // stdc_memreverse8u8 is a no-op (single byte, nothing to swap).
+ case Builtin::BIstdc_memreverse8u8:
+ return RValue::get(EmitScalarExpr(E->getArg(0)));
+
+ case Builtin::BIstdc_memreverse8u16:
+ case Builtin::BIstdc_memreverse8u32:
+ case Builtin::BIstdc_memreverse8u64:
+ return RValue::get(
+ emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::bswap));
+
+ case Builtin::BIstdc_memreverse8:
+ case Builtin::BI__builtin_stdc_memreverse8: {
+ Value *N = EmitScalarExpr(E->getArg(0));
+ Address PtrAddr = EmitPointerWithAlignment(E->getArg(1));
+
+ if (auto *CI = dyn_cast<ConstantInt>(N)) {
+ uint64_t Size = CI->getZExtValue();
+ if (Size == 2 || Size == 4 || Size == 8) {
+ llvm::Type *IntTy = Builder.getIntNTy(Size * 8);
+ Address Addr = PtrAddr.withElementType(IntTy);
+ Value *Val = Builder.CreateLoad(Addr);
+ Function *F = CGM.getIntrinsic(Intrinsic::bswap, IntTy);
+ Value *Swapped = Builder.CreateCall(F, Val);
+ Builder.CreateStore(Swapped, Addr);
+ return RValue::get(nullptr);
+ }
+ }
+
+ // General case: fall back to the library function stdc_memreverse8.
----------------
efriedma-quic wrote:
You can't fall back after you've already emitted the argument expressions; that
will double-emit the arguments.
https://github.com/llvm/llvm-project/pull/197358
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits