@@ -1964,26 +1964,10 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
19641964 Value *Src = Visit (const_cast <Expr*>(E));
19651965 llvm::Type *SrcTy = Src->getType ();
19661966 llvm::Type *DstTy = ConvertType (DestTy);
1967- bool NeedAddrspaceCast = false ;
19681967 if (SrcTy->isPtrOrPtrVectorTy () && DstTy->isPtrOrPtrVectorTy () &&
19691968 SrcTy->getPointerAddressSpace () != DstTy->getPointerAddressSpace ()) {
1970- // If we have the same address space in AST, which is then codegen'ed to
1971- // different address spaces in IR, then an address space cast should be
1972- // valid.
1973- //
1974- // This is the case for SYCL, where both types have Default address space
1975- // in AST, but in IR one of them may be in opencl_private, and another in
1976- // opencl_generic address space:
1977- //
1978- // int arr[5]; // automatic variable, default AS in AST,
1979- // // private AS in IR
1980- //
1981- // char* p = arr; // default AS in AST, generic AS in IR
1982- //
1983- if (E->getType ().getAddressSpace () != DestTy.getAddressSpace ())
1984- llvm_unreachable (" wrong cast for pointers in different address spaces"
1985- " (must be an address space cast)!" );
1986- NeedAddrspaceCast = true ;
1969+ llvm_unreachable (" wrong cast for pointers in different address spaces"
1970+ " (must be an address space cast)!" );
19871971 }
19881972
19891973 if (CGF.SanOpts .has (SanitizerKind::CFIUnrelatedCast)) {
@@ -2022,14 +2006,6 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
20222006 }
20232007 }
20242008
2025- if (NeedAddrspaceCast) {
2026- llvm::Type *SrcPointeeTy = Src->getType ()->getPointerElementType ();
2027- llvm::Type *SrcNewAS = llvm::PointerType::get (
2028- SrcPointeeTy, cast<llvm::PointerType>(DstTy)->getAddressSpace ());
2029-
2030- Src = Builder.CreateAddrSpaceCast (Src, SrcNewAS);
2031- }
2032-
20332009 // If Src is a fixed vector and Dst is a scalable vector, and both have the
20342010 // same element type, use the llvm.experimental.vector.insert intrinsic to
20352011 // perform the bitcast.
@@ -2966,53 +2942,6 @@ Value *ScalarExprEmitter::VisitUnaryImag(const UnaryOperator *E) {
29662942// Binary Operators
29672943// ===----------------------------------------------------------------------===//
29682944
2969- static Value *insertAddressSpaceCast (Value *V, unsigned NewAS) {
2970- auto *VTy = cast<llvm::PointerType>(V->getType ());
2971- if (VTy->getAddressSpace () == NewAS)
2972- return V;
2973-
2974- llvm::PointerType *VTyNewAS =
2975- llvm::PointerType::get (VTy->getElementType (), NewAS);
2976-
2977- if (auto *Constant = dyn_cast<llvm::Constant>(V))
2978- return llvm::ConstantExpr::getAddrSpaceCast (Constant, VTyNewAS);
2979-
2980- llvm::Instruction *NewV =
2981- new llvm::AddrSpaceCastInst (V, VTyNewAS, V->getName () + " .ascast" );
2982- NewV->insertAfter (cast<llvm::Instruction>(V));
2983- return NewV;
2984- }
2985-
2986- static void ensureSameAddrSpace (Value *&RHS, Value *&LHS,
2987- bool CanInsertAddrspaceCast,
2988- const LangOptions &Opts,
2989- const ASTContext &Context) {
2990- if (RHS->getType () == LHS->getType ())
2991- return ;
2992-
2993- auto *RHSTy = dyn_cast<llvm::PointerType>(RHS->getType ());
2994- auto *LHSTy = dyn_cast<llvm::PointerType>(LHS->getType ());
2995- if (!RHSTy || !LHSTy || RHSTy->getAddressSpace () == LHSTy->getAddressSpace ())
2996- return ;
2997-
2998- if (!CanInsertAddrspaceCast)
2999- // Pointers have different address spaces and we cannot do anything with
3000- // this.
3001- llvm_unreachable (" Pointers are expected to have the same address space." );
3002-
3003- // Language rules define if it is legal to cast from one address space to
3004- // another, and which address space we should use as a "common
3005- // denominator". In SYCL, generic address space overlaps with all other
3006- // address spaces.
3007- if (Opts.SYCLIsDevice ) {
3008- unsigned GenericAS = Context.getTargetAddressSpace (LangAS::opencl_generic);
3009- RHS = insertAddressSpaceCast (RHS, GenericAS);
3010- LHS = insertAddressSpaceCast (LHS, GenericAS);
3011- } else
3012- llvm_unreachable (" Unable to find a common address space for "
3013- " two pointers." );
3014- }
3015-
30162945BinOpInfo ScalarExprEmitter::EmitBinOps (const BinaryOperator *E) {
30172946 TestAndClearIgnoreResultAssign ();
30182947 BinOpInfo Result;
@@ -4134,14 +4063,6 @@ Value *ScalarExprEmitter::EmitCompare(const BinaryOperator *E,
41344063 RHS = Builder.CreateStripInvariantGroup (RHS);
41354064 }
41364065
4137- // Expression operands may have the same addrspace in AST, but different
4138- // addrspaces in LLVM IR, in which case an addrspacecast should be valid.
4139- bool CanInsertAddrspaceCast =
4140- LHSTy.getAddressSpace () == RHSTy.getAddressSpace ();
4141-
4142- ensureSameAddrSpace (RHS, LHS, CanInsertAddrspaceCast, CGF.getLangOpts (),
4143- CGF.getContext ());
4144-
41454066 Result = Builder.CreateICmp (UICmpOpc, LHS, RHS, " cmp" );
41464067 }
41474068
@@ -4513,6 +4434,7 @@ static bool isCheapEnoughToEvaluateUnconditionally(const Expr *E,
45134434 // exist in the source-level program.
45144435}
45154436
4437+
45164438Value *ScalarExprEmitter::
45174439VisitAbstractConditionalOperator (const AbstractConditionalOperator *E) {
45184440 TestAndClearIgnoreResultAssign ();
@@ -4621,15 +4543,6 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
46214543 assert (!RHS && " LHS and RHS types must match" );
46224544 return nullptr ;
46234545 }
4624-
4625- // Expressions may have the same addrspace in AST, but different address
4626- // space in LLVM IR, in which case an addrspacecast should be valid.
4627- bool CanInsertAddrspaceCast = rhsExpr->getType ().getAddressSpace () ==
4628- lhsExpr->getType ().getAddressSpace ();
4629-
4630- ensureSameAddrSpace (RHS, LHS, CanInsertAddrspaceCast, CGF.getLangOpts (),
4631- CGF.getContext ());
4632-
46334546 return Builder.CreateSelect (CondV, LHS, RHS, " cond" );
46344547 }
46354548
@@ -4664,14 +4577,6 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
46644577 if (!RHS)
46654578 return LHS;
46664579
4667- // Expressions may have the same addrspace in AST, but different address
4668- // space in LLVM IR, in which case an addrspacecast should be valid.
4669- bool CanInsertAddrspaceCast = rhsExpr->getType ().getAddressSpace () ==
4670- lhsExpr->getType ().getAddressSpace ();
4671-
4672- ensureSameAddrSpace (RHS, LHS, CanInsertAddrspaceCast, CGF.getLangOpts (),
4673- CGF.getContext ());
4674-
46754580 // Create a PHI node for the real part.
46764581 llvm::PHINode *PN = Builder.CreatePHI (LHS->getType (), 2 , " cond" );
46774582 PN->addIncoming (LHS, LHSBlock);
0 commit comments