@@ -463,7 +463,7 @@ Function *AArch64Arm64ECCallLowering::buildExitThunk(FunctionType *FT,
463463 IRB.CreateStore (&Arg, Mem);
464464 if (ArgTranslation == ThunkArgTranslation::Bitcast) {
465465 Type *IntTy = IRB.getIntNTy (DL.getTypeStoreSizeInBits (Arg.getType ()));
466- Args.push_back (IRB.CreateLoad (IntTy, IRB. CreateBitCast ( Mem, PtrTy) ));
466+ Args.push_back (IRB.CreateLoad (IntTy, Mem));
467467 } else {
468468 assert (ArgTranslation == ThunkArgTranslation::PointerIndirection);
469469 Args.push_back (Mem);
@@ -475,7 +475,6 @@ Function *AArch64Arm64ECCallLowering::buildExitThunk(FunctionType *FT,
475475 }
476476 // FIXME: Transfer necessary attributes? sret? anything else?
477477
478- Callee = IRB.CreateBitCast (Callee, PtrTy);
479478 CallInst *Call = IRB.CreateCall (X64Ty, Callee, Args);
480479 Call->setCallingConv (CallingConv::ARM64EC_Thunk_X64);
481480
@@ -487,7 +486,7 @@ Function *AArch64Arm64ECCallLowering::buildExitThunk(FunctionType *FT,
487486 RetVal = IRB.CreateLoad (RetTy, Args[1 ]);
488487 } else {
489488 Value *CastAlloca = IRB.CreateAlloca (RetTy);
490- IRB.CreateStore (Call, IRB. CreateBitCast ( CastAlloca, PtrTy) );
489+ IRB.CreateStore (Call, CastAlloca);
491490 RetVal = IRB.CreateLoad (RetTy, CastAlloca);
492491 }
493492 }
@@ -542,11 +541,11 @@ Function *AArch64Arm64ECCallLowering::buildEntryThunk(Function *F) {
542541 // Translate array/struct arguments to the expected type.
543542 if (ArgTranslation == ThunkArgTranslation::Bitcast) {
544543 Value *CastAlloca = IRB.CreateAlloca (ArgTy);
545- IRB.CreateStore (Arg, IRB. CreateBitCast ( CastAlloca, PtrTy) );
544+ IRB.CreateStore (Arg, CastAlloca);
546545 Arg = IRB.CreateLoad (ArgTy, CastAlloca);
547546 } else {
548547 assert (ArgTranslation == ThunkArgTranslation::PointerIndirection);
549- Arg = IRB.CreateLoad (ArgTy, IRB. CreateBitCast ( Arg, PtrTy) );
548+ Arg = IRB.CreateLoad (ArgTy, Arg);
550549 }
551550 }
552551 assert (Arg->getType () == ArgTy);
@@ -571,7 +570,6 @@ Function *AArch64Arm64ECCallLowering::buildEntryThunk(Function *F) {
571570
572571 // Call the function passed to the thunk.
573572 Value *Callee = Thunk->getArg (0 );
574- Callee = IRB.CreateBitCast (Callee, PtrTy);
575573 CallInst *Call = IRB.CreateCall (Arm64Ty, Callee, Args);
576574
577575 auto SRetAttr = F->getAttributes ().getParamAttr (0 , Attribute::StructRet);
@@ -583,10 +581,10 @@ Function *AArch64Arm64ECCallLowering::buildEntryThunk(Function *F) {
583581
584582 Value *RetVal = Call;
585583 if (TransformDirectToSRet) {
586- IRB.CreateStore (RetVal, IRB. CreateBitCast ( Thunk->getArg (1 ), PtrTy ));
584+ IRB.CreateStore (RetVal, Thunk->getArg (1 ));
587585 } else if (X64RetType != RetTy) {
588586 Value *CastAlloca = IRB.CreateAlloca (X64RetType);
589- IRB.CreateStore (Call, IRB. CreateBitCast ( CastAlloca, PtrTy) );
587+ IRB.CreateStore (Call, CastAlloca);
590588 RetVal = IRB.CreateLoad (X64RetType, CastAlloca);
591589 }
592590
@@ -649,15 +647,13 @@ Function *AArch64Arm64ECCallLowering::buildGuestExitThunk(Function *F) {
649647 // even if the original CallBase is an Invoke or CallBr instruction.
650648 Function *Thunk = buildExitThunk (F->getFunctionType (), F->getAttributes ());
651649 CallInst *GuardCheck = B.CreateCall (
652- GuardFnType, GuardCheckLoad,
653- {B.CreateBitCast (F, B.getPtrTy ()), B.CreateBitCast (Thunk, B.getPtrTy ())});
650+ GuardFnType, GuardCheckLoad, {F, Thunk});
654651
655652 // Ensure that the first argument is passed in the correct register.
656653 GuardCheck->setCallingConv (CallingConv::CFGuard_Check);
657654
658- Value *GuardRetVal = B.CreateBitCast (GuardCheck, PtrTy);
659655 SmallVector<Value *> Args (llvm::make_pointer_range (GuestExit->args ()));
660- CallInst *Call = B.CreateCall (Arm64Ty, GuardRetVal , Args);
656+ CallInst *Call = B.CreateCall (Arm64Ty, GuardCheck , Args);
661657 Call->setTailCallKind (llvm::CallInst::TCK_MustTail);
662658
663659 if (Call->getType ()->isVoidTy ())
@@ -712,9 +708,8 @@ AArch64Arm64ECCallLowering::buildPatchableThunk(GlobalAlias *UnmangledAlias,
712708 // Ensure that the first arguments are passed in the correct registers.
713709 Dispatch->setCallingConv (CallingConv::CFGuard_Check);
714710
715- Value *DispatchRetVal = B.CreateBitCast (Dispatch, PtrTy);
716711 SmallVector<Value *> Args (llvm::make_pointer_range (GuestExit->args ()));
717- CallInst *Call = B.CreateCall (Arm64Ty, DispatchRetVal , Args);
712+ CallInst *Call = B.CreateCall (Arm64Ty, Dispatch , Args);
718713 Call->setTailCallKind (llvm::CallInst::TCK_MustTail);
719714
720715 if (Call->getType ()->isVoidTy ())
@@ -759,16 +754,13 @@ void AArch64Arm64ECCallLowering::lowerCall(CallBase *CB) {
759754 // even if the original CallBase is an Invoke or CallBr instruction.
760755 Function *Thunk = buildExitThunk (CB->getFunctionType (), CB->getAttributes ());
761756 CallInst *GuardCheck =
762- B.CreateCall (GuardFnType, GuardCheckLoad,
763- {B.CreateBitCast (CalledOperand, B.getPtrTy ()),
764- B.CreateBitCast (Thunk, B.getPtrTy ())},
757+ B.CreateCall (GuardFnType, GuardCheckLoad, {CalledOperand, Thunk},
765758 Bundles);
766759
767760 // Ensure that the first argument is passed in the correct register.
768761 GuardCheck->setCallingConv (CallingConv::CFGuard_Check);
769762
770- Value *GuardRetVal = B.CreateBitCast (GuardCheck, CalledOperand->getType ());
771- CB->setCalledOperand (GuardRetVal);
763+ CB->setCalledOperand (GuardCheck);
772764}
773765
774766bool AArch64Arm64ECCallLowering::runOnModule (Module &Mod) {
@@ -912,8 +904,7 @@ bool AArch64Arm64ECCallLowering::runOnModule(Module &Mod) {
912904 SmallVector<Constant *> ThunkMappingArrayElems;
913905 for (ThunkInfo &Thunk : ThunkMapping) {
914906 ThunkMappingArrayElems.push_back (ConstantStruct::getAnon (
915- {ConstantExpr::getBitCast (Thunk.Src , PtrTy),
916- ConstantExpr::getBitCast (Thunk.Dst , PtrTy),
907+ {Thunk.Src , Thunk.Dst ,
917908 ConstantInt::get (M->getContext (), APInt (32 , uint8_t (Thunk.Kind )))}));
918909 }
919910 Constant *ThunkMappingArray = ConstantArray::get (
0 commit comments