llvm.org GIT mirror llvm / 59d3ae6
Add addrspacecast instruction. Patch by Michele Scandale! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194760 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 5 years ago
51 changed file(s) with 589 addition(s) and 230 deletion(s). Raw diff Collapse all Expand all
23812381 Convert a constant, CST, to another TYPE. The constraints of the
23822382 operands are the same as those for the :ref:`bitcast
23832383 instruction `.
2384 ``addrspacecast (CST to TYPE)``
2385 Convert a constant pointer or constant vector of pointer, CST, to another
2386 TYPE in a different address space. The constraints of the operands are the
2387 same as those for the :ref:`addrspacecast instruction `.
23842388 ``getelementptr (CSTPTR, IDX0, IDX1, ...)``, ``getelementptr inbounds (CSTPTR, IDX0, IDX1, ...)``
23852389 Perform the :ref:`getelementptr operation ` on
23862390 constants. As with the :ref:`getelementptr `
57255729 conversion. The conversion is done as if the ``value`` had been stored
57265730 to memory and read back as type ``ty2``. Pointer (or vector of
57275731 pointers) types may only be converted to other pointer (or vector of
5728 pointers) types with this instruction if the pointer sizes are
5729 equal. To convert pointers to other types, use the :ref:`inttoptr
5730 ` or :ref:`ptrtoint ` instructions first.
5732 pointers) types with the same address space through this instruction.
5733 To convert pointers to other types, use the :ref:`inttoptr `
5734 or :ref:`ptrtoint ` instructions first.
57315735
57325736 Example:
57335737 """"""""
57385742 %Y = bitcast i32* %x to sint* ; yields sint*:%x
57395743 %Z = bitcast <2 x int> %V to i64; ; yields i64: %V
57405744 %Z = bitcast <2 x i32*> %V to <2 x i64*> ; yields <2 x i64*>
5745
5746 .. _i_addrspacecast:
5747
5748 '``addrspacecast .. to``' Instruction
5749 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5750
5751 Syntax:
5752 """""""
5753
5754 ::
5755
5756 = addrspacecast to ; yields pty2
5757
5758 Overview:
5759 """""""""
5760
5761 The '``addrspacecast``' instruction converts ``ptrval`` from ``pty`` in
5762 address space ``n`` to type ``pty2`` in address space ``m``.
5763
5764 Arguments:
5765 """"""""""
5766
5767 The '``addrspacecast``' instruction takes a pointer or vector of pointer value
5768 to cast and a pointer type to cast it to, which must have a different
5769 address space.
5770
5771 Semantics:
5772 """"""""""
5773
5774 The '``addrspacecast``' instruction converts the pointer value
5775 ``ptrval`` to type ``pty2``. It can be a *no-op cast* or a complex
5776 value modification, depending on the target and the address spaces
5777 pair. Pointers conversion within the same address space must be
5778 performed with ``bitcast`` instruction. Note that if the address space
5779 conversion is legal then both result and operand refer to the same memory
5780 location.
5781
5782 Example:
5783 """"""""
5784
5785 .. code-block:: llvm
5786
5787 %X = addrspacecast i32* %x to addrspace(1) i32* ; yields addrspace(1) i32*:%x
5788 %Y = addrspacecast addrspace(1) <2 x i32>* %y to addrspace(2) i64* ; yields addrspace(2) i32*:%y
5789 %Z = addrspacecast <4 x i32*> %z to <4 x float addrspace(3)*> ; yelds <4 x float addrspace(3)*>:%z
57415790
57425791 .. _otherops:
57435792
1414 #define LLVM_AUTOUPGRADE_H
1515
1616 namespace llvm {
17 class Constant;
1718 class Module;
1819 class GlobalVariable;
1920 class Function;
2021 class CallInst;
2122 class Instruction;
23 class Value;
24 class Type;
2225
2326 /// This is a more granular function that simply checks an intrinsic function
2427 /// for upgrading, and returns true if it requires upgrading. It may return
4346 /// If the TBAA tag for the given instruction uses the scalar TBAA format,
4447 /// we upgrade it to the struct-path aware TBAA format.
4548 void UpgradeInstWithTBAATag(Instruction *I);
49
50 /// This is an auto-upgrade for bitcast between pointers with different
51 /// address spaces: the instruction is replaced by a pair ptrtoint+inttoptr.
52 Instruction *UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy,
53 Instruction *&Temp);
54
55 /// This is an auto-upgrade for bitcast constant expression between pointers
56 /// with different address spaces: the instruction is replaced by a pair
57 /// ptrtoint+inttoptr.
58 Value *UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy);
4659 } // End llvm namespace
4760
4861 #endif
193193 CAST_FPEXT = 8,
194194 CAST_PTRTOINT = 9,
195195 CAST_INTTOPTR = 10,
196 CAST_BITCAST = 11
196 CAST_BITCAST = 11,
197 CAST_ADDRSPACECAST = 12
197198 };
198199
199200 /// BinaryOpcodes - These are values used in the bitcode files to encode which
417417 /// int-to-int or fp-to-fp conversions, but that is a noop, deleted by
418418 /// getNode().
419419 BITCAST,
420
421 /// ADDRSPACECAST - This operator converts between pointers of different
422 /// address spaces.
423 ADDRSPACECAST,
420424
421425 /// CONVERT_RNDSAT - This operator is used to support various conversions
422426 /// between various types (float, signed, unsigned and vectors of those
800800
801801 /// getMDNode - Return an MDNodeSDNode which holds an MDNode.
802802 SDValue getMDNode(const MDNode *MD);
803
804 /// getAddrSpaceCast - Return an AddrSpaceCastSDNode.
805 SDValue getAddrSpaceCast(SDLoc dl, EVT VT, SDValue Ptr,
806 unsigned SrcAS, unsigned DestAS);
803807
804808 /// getShiftAmountOperand - Return the specified value casted to
805809 /// the target's desired shift amount type.
949949 const SDValue &getValue() const { return Op; }
950950 };
951951
952 class AddrSpaceCastSDNode : public UnarySDNode {
953 private:
954 unsigned SrcAddrSpace;
955 unsigned DestAddrSpace;
956
957 public:
958 AddrSpaceCastSDNode(unsigned Order, DebugLoc dl, EVT VT, SDValue X,
959 unsigned SrcAS, unsigned DestAS);
960
961 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
962 unsigned getDestAddressSpace() const { return DestAddrSpace; }
963
964 static bool classof(const SDNode *N) {
965 return N->getOpcode() == ISD::ADDRSPACECAST;
966 }
967 };
968
952969 /// Abstact virtual class for operations for memory operations
953970 class MemSDNode : public SDNode {
954971 private:
861861 static Constant *getPtrToInt(Constant *C, Type *Ty);
862862 static Constant *getIntToPtr(Constant *C, Type *Ty);
863863 static Constant *getBitCast (Constant *C, Type *Ty);
864 static Constant *getAddrSpaceCast (Constant *C, Type *Ty);
864865
865866 static Constant *getNSWNeg(Constant *C) { return getNeg(C, false, true); }
866867 static Constant *getNUWNeg(Constant *C) { return getNeg(C, true, false); }
11321132 const Twine &Name = "") {
11331133 return CreateCast(Instruction::BitCast, V, DestTy, Name);
11341134 }
1135 Value *CreateAddrSpaceCast(Value *V, Type *DestTy,
1136 const Twine &Name = "") {
1137 return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
1138 }
11351139 Value *CreateZExtOrBitCast(Value *V, Type *DestTy,
11361140 const Twine &Name = "") {
11371141 if (V->getType() == DestTy)
153153 HANDLE_CAST_INST(42, PtrToInt, PtrToIntInst) // Pointer -> Integer
154154 HANDLE_CAST_INST(43, IntToPtr, IntToPtrInst) // Integer -> Pointer
155155 HANDLE_CAST_INST(44, BitCast , BitCastInst ) // Type cast
156 LAST_CAST_INST(44)
156 HANDLE_CAST_INST(45, AddrSpaceCast, AddrSpaceCastInst) // addrspace cast
157 LAST_CAST_INST(45)
157158
158159 // Other operators...
159 FIRST_OTHER_INST(45)
160 HANDLE_OTHER_INST(45, ICmp , ICmpInst ) // Integer comparison instruction
161 HANDLE_OTHER_INST(46, FCmp , FCmpInst ) // Floating point comparison instr.
162 HANDLE_OTHER_INST(47, PHI , PHINode ) // PHI node instruction
163 HANDLE_OTHER_INST(48, Call , CallInst ) // Call a function
164 HANDLE_OTHER_INST(49, Select , SelectInst ) // select instruction
165 HANDLE_OTHER_INST(50, UserOp1, Instruction) // May be used internally in a pass
166 HANDLE_OTHER_INST(51, UserOp2, Instruction) // Internal to passes only
167 HANDLE_OTHER_INST(52, VAArg , VAArgInst ) // vaarg instruction
168 HANDLE_OTHER_INST(53, ExtractElement, ExtractElementInst)// extract from vector
169 HANDLE_OTHER_INST(54, InsertElement, InsertElementInst) // insert into vector
170 HANDLE_OTHER_INST(55, ShuffleVector, ShuffleVectorInst) // shuffle two vectors.
171 HANDLE_OTHER_INST(56, ExtractValue, ExtractValueInst)// extract from aggregate
172 HANDLE_OTHER_INST(57, InsertValue, InsertValueInst) // insert into aggregate
173 HANDLE_OTHER_INST(58, LandingPad, LandingPadInst) // Landing pad instruction.
174 LAST_OTHER_INST(58)
160 FIRST_OTHER_INST(46)
161 HANDLE_OTHER_INST(46, ICmp , ICmpInst ) // Integer comparison instruction
162 HANDLE_OTHER_INST(47, FCmp , FCmpInst ) // Floating point comparison instr.
163 HANDLE_OTHER_INST(48, PHI , PHINode ) // PHI node instruction
164 HANDLE_OTHER_INST(49, Call , CallInst ) // Call a function
165 HANDLE_OTHER_INST(50, Select , SelectInst ) // select instruction
166 HANDLE_OTHER_INST(51, UserOp1, Instruction) // May be used internally in a pass
167 HANDLE_OTHER_INST(52, UserOp2, Instruction) // Internal to passes only
168 HANDLE_OTHER_INST(53, VAArg , VAArgInst ) // vaarg instruction
169 HANDLE_OTHER_INST(54, ExtractElement, ExtractElementInst)// extract from vector
170 HANDLE_OTHER_INST(55, InsertElement, InsertElementInst) // insert into vector
171 HANDLE_OTHER_INST(56, ShuffleVector, ShuffleVectorInst) // shuffle two vectors.
172 HANDLE_OTHER_INST(57, ExtractValue, ExtractValueInst)// extract from aggregate
173 HANDLE_OTHER_INST(58, InsertValue, InsertValueInst) // insert into aggregate
174 HANDLE_OTHER_INST(59, LandingPad, LandingPadInst) // Landing pad instruction.
175 LAST_OTHER_INST(59)
175176
176177 #undef FIRST_TERM_INST
177178 #undef HANDLE_TERM_INST
36143614 }
36153615 };
36163616
3617 //===----------------------------------------------------------------------===//
3618 // AddrSpaceCastInst Class
3619 //===----------------------------------------------------------------------===//
3620
3621 /// \brief This class represents a conversion between pointers from
3622 /// one address space to another.
3623 class AddrSpaceCastInst : public CastInst {
3624 protected:
3625 /// \brief Clone an identical AddrSpaceCastInst
3626 virtual AddrSpaceCastInst *clone_impl() const;
3627
3628 public:
3629 /// \brief Constructor with insert-before-instruction semantics
3630 AddrSpaceCastInst(
3631 Value *S, ///< The value to be casted
3632 Type *Ty, ///< The type to casted to
3633 const Twine &NameStr = "", ///< A name for the new instruction
3634 Instruction *InsertBefore = 0 ///< Where to insert the new instruction
3635 );
3636
3637 /// \brief Constructor with insert-at-end-of-block semantics
3638 AddrSpaceCastInst(
3639 Value *S, ///< The value to be casted
3640 Type *Ty, ///< The type to casted to
3641 const Twine &NameStr, ///< A name for the new instruction
3642 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
3643 );
3644
3645 // Methods for support type inquiry through isa, cast, and dyn_cast:
3646 static inline bool classof(const Instruction *I) {
3647 return I->getOpcode() == AddrSpaceCast;
3648 }
3649 static inline bool classof(const Value *V) {
3650 return isa(V) && classof(cast(V));
3651 }
3652 };
3653
36173654 } // End llvm namespace
36183655
36193656 #endif
190190 RetTy visitPtrToIntInst(PtrToIntInst &I) { DELEGATE(CastInst);}
191191 RetTy visitIntToPtrInst(IntToPtrInst &I) { DELEGATE(CastInst);}
192192 RetTy visitBitCastInst(BitCastInst &I) { DELEGATE(CastInst);}
193 RetTy visitAddrSpaceCastInst(AddrSpaceCastInst &I) { DELEGATE(CastInst);}
193194 RetTy visitSelectInst(SelectInst &I) { DELEGATE(Instruction);}
194195 RetTy visitVAArgInst(VAArgInst &I) { DELEGATE(UnaryInstruction);}
195196 RetTy visitExtractElementInst(ExtractElementInst &I) { DELEGATE(Instruction);}
826826 return 0;
827827 }
828828
829 /// Returns true if a cast between SrcAS and DestAS is a noop.
830 virtual bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const {
831 return false;
832 }
833
829834 //===--------------------------------------------------------------------===//
830835 /// \name Helpers for TargetTransformInfo implementations
831836 /// @{
221221 LLVMPtrToInt = 39,
222222 LLVMIntToPtr = 40,
223223 LLVMBitCast = 41,
224 LLVMAddrSpaceCast = 60,
224225
225226 /* Other Operators */
226227 LLVMICmp = 42,
11581159 macro(UnaryInstruction) \
11591160 macro(AllocaInst) \
11601161 macro(CastInst) \
1162 macro(AddrSpaceCastInst) \
11611163 macro(BitCastInst) \
11621164 macro(FPExtInst) \
11631165 macro(FPToSIInst) \
16291631 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
16301632 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
16311633 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
1634 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
16321635 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
16331636 LLVMTypeRef ToType);
16341637 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
26042607 LLVMTypeRef DestTy, const char *Name);
26052608 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef, LLVMValueRef Val,
26062609 LLVMTypeRef DestTy, const char *Name);
2610 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef, LLVMValueRef Val,
2611 LLVMTypeRef DestTy, const char *Name);
26072612 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
26082613 LLVMTypeRef DestTy, const char *Name);
26092614 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef, LLVMValueRef Val,
662662 if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace()) {
663663 NewPtrTy = NewPtrTy->getElementType()->getPointerTo(
664664 OldPtrTy->getAddressSpace());
665 Ptr = ConstantExpr::getBitCast(Ptr, NewPtrTy);
665 Ptr = ConstantExpr::getPointerCast(Ptr, NewPtrTy);
666666 }
667667 return Ptr;
668668 }
994994 return ConstantExpr::getCast(Opcode, Ops[0], DestTy);
995995 case Instruction::IntToPtr:
996996 // If the input is a ptrtoint, turn the pair into a ptr to ptr bitcast if
997 // the int size is >= the ptr size. This requires knowing the width of a
998 // pointer, so it can't be done in ConstantExpr::getCast.
997 // the int size is >= the ptr size and the address spaces are the same.
998 // This requires knowing the width of a pointer, so it can't be done in
999 // ConstantExpr::getCast.
9991000 if (ConstantExpr *CE = dyn_cast(Ops[0])) {
10001001 if (TD && CE->getOpcode() == Instruction::PtrToInt) {
10011002 Constant *SrcPtr = CE->getOperand(0);
10031004 unsigned MidIntSize = CE->getType()->getScalarSizeInBits();
10041005
10051006 if (MidIntSize >= SrcPtrSize) {
1006 unsigned DestPtrSize = TD->getPointerTypeSizeInBits(DestTy);
1007 if (SrcPtrSize == DestPtrSize)
1007 unsigned SrcAS = SrcPtr->getType()->getPointerAddressSpace();
1008 if (SrcAS == DestTy->getPointerAddressSpace())
10081009 return FoldBitCast(CE->getOperand(0), DestTy, *TD);
10091010 }
10101011 }
10201021 case Instruction::SIToFP:
10211022 case Instruction::FPToUI:
10221023 case Instruction::FPToSI:
1024 case Instruction::AddrSpaceCast:
10231025 return ConstantExpr::getCast(Opcode, Ops[0], DestTy);
10241026 case Instruction::BitCast:
10251027 if (TD)
664664 INSTKEYWORD(inttoptr, IntToPtr);
665665 INSTKEYWORD(ptrtoint, PtrToInt);
666666 INSTKEYWORD(bitcast, BitCast);
667 INSTKEYWORD(addrspacecast, AddrSpaceCast);
667668 INSTKEYWORD(select, Select);
668669 INSTKEYWORD(va_arg, VAArg);
669670 INSTKEYWORD(ret, Ret);
24142414 case lltok::kw_fptrunc:
24152415 case lltok::kw_fpext:
24162416 case lltok::kw_bitcast:
2417 case lltok::kw_addrspacecast:
24172418 case lltok::kw_uitofp:
24182419 case lltok::kw_sitofp:
24192420 case lltok::kw_fptoui:
33023303 case lltok::kw_fptrunc:
33033304 case lltok::kw_fpext:
33043305 case lltok::kw_bitcast:
3306 case lltok::kw_addrspacecast:
33053307 case lltok::kw_uitofp:
33063308 case lltok::kw_sitofp:
33073309 case lltok::kw_fptoui:
149149 kw_phi, kw_call,
150150 kw_trunc, kw_zext, kw_sext, kw_fptrunc, kw_fpext, kw_uitofp, kw_sitofp,
151151 kw_fptoui, kw_fptosi, kw_inttoptr, kw_ptrtoint, kw_bitcast,
152 kw_addrspacecast,
152153 kw_select, kw_va_arg,
153154
154155 kw_landingpad, kw_personality, kw_cleanup, kw_catch, kw_filter,
127127 case bitc::CAST_PTRTOINT: return Instruction::PtrToInt;
128128 case bitc::CAST_INTTOPTR: return Instruction::IntToPtr;
129129 case bitc::CAST_BITCAST : return Instruction::BitCast;
130 case bitc::CAST_ADDRSPACECAST : return Instruction::AddrSpaceCast;
130131 }
131132 }
132133 static int GetDecodedBinaryOpcode(unsigned Val, Type *Ty) {
13551356 if (!OpTy)
13561357 return Error(InvalidRecord);
13571358 Constant *Op = ValueList.getConstantFwdRef(Record[2], OpTy);
1358 V = ConstantExpr::getCast(Opc, Op, CurTy);
1359 V = UpgradeBitCastExpr(Opc, Op, CurTy);
1360 if (!V) V = ConstantExpr::getCast(Opc, Op, CurTy);
13591361 }
13601362 break;
13611363 }
22952297 int Opc = GetDecodedCastOpcode(Record[OpNum+1]);
22962298 if (Opc == -1 || ResTy == 0)
22972299 return Error(InvalidRecord);
2298 I = CastInst::Create((Instruction::CastOps)Opc, Op, ResTy);
2300 Instruction *Temp = 0;
2301 if ((I = UpgradeBitCastInst(Opc, Op, ResTy, Temp))) {
2302 if (Temp) {
2303 InstructionList.push_back(Temp);
2304 CurBB->getInstList().push_back(Temp);
2305 }
2306 } else {
2307 I = CastInst::Create((Instruction::CastOps)Opc, Op, ResTy);
2308 }
22992309 InstructionList.push_back(I);
23002310 break;
23012311 }
7777 case Instruction::PtrToInt: return bitc::CAST_PTRTOINT;
7878 case Instruction::IntToPtr: return bitc::CAST_INTTOPTR;
7979 case Instruction::BitCast : return bitc::CAST_BITCAST;
80 case Instruction::AddrSpaceCast : return bitc::CAST_ADDRSPACECAST;
8081 }
8182 }
8283
15061506 return SDValue(N, 0);
15071507 }
15081508
1509 /// getAddrSpaceCast - Return an AddrSpaceCastSDNode.
1510 SDValue SelectionDAG::getAddrSpaceCast(SDLoc dl, EVT VT, SDValue Ptr,
1511 unsigned SrcAS, unsigned DestAS) {
1512 SDValue Ops[] = {Ptr};
1513 FoldingSetNodeID ID;
1514 AddNodeIDNode(ID, ISD::ADDRSPACECAST, getVTList(VT), &Ops[0], 1);
1515 ID.AddInteger(SrcAS);
1516 ID.AddInteger(DestAS);
1517
1518 void *IP = 0;
1519 if (SDNode *E = CSEMap.FindNodeOrInsertPos(ID, IP))
1520 return SDValue(E, 0);
1521
1522 SDNode *N = new (NodeAllocator) AddrSpaceCastSDNode(dl.getIROrder(),
1523 dl.getDebugLoc(),
1524 VT, Ptr, SrcAS, DestAS);
1525 CSEMap.InsertNode(N, IP);
1526 AllNodes.push_back(N);
1527 return SDValue(N, 0);
1528 }
15091529
15101530 /// getShiftAmountOperand - Return the specified value casted to
15111531 /// the target's desired shift amount type.
59775997 TheGlobal = GA;
59785998 }
59795999
6000 AddrSpaceCastSDNode::AddrSpaceCastSDNode(unsigned Order, DebugLoc dl, EVT VT,
6001 SDValue X, unsigned SrcAS,
6002 unsigned DestAS)
6003 : UnarySDNode(ISD::ADDRSPACECAST, Order, dl, getSDVTList(VT), X),
6004 SrcAddrSpace(SrcAS), DestAddrSpace(DestAS) {}
6005
59806006 MemSDNode::MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
59816007 EVT memvt, MachineMemOperand *mmo)
59826008 : SDNode(Opc, Order, dl, VTs), MemoryVT(memvt), MMO(mmo) {
29352935 DestVT, N)); // convert types.
29362936 else
29372937 setValue(&I, N); // noop cast.
2938 }
2939
2940 void SelectionDAGBuilder::visitAddrSpaceCast(const User &I) {
2941 const TargetLowering &TLI = DAG.getTargetLoweringInfo();
2942 const Value *SV = I.getOperand(0);
2943 SDValue N = getValue(SV);
2944 EVT DestVT = TM.getTargetLowering()->getValueType(I.getType());
2945
2946 unsigned SrcAS = SV->getType()->getPointerAddressSpace();
2947 unsigned DestAS = I.getType()->getPointerAddressSpace();
2948
2949 if (!TLI.isNoopAddrSpaceCast(SrcAS, DestAS))
2950 N = DAG.getAddrSpaceCast(getCurSDLoc(), DestVT, N, SrcAS, DestAS);
2951
2952 setValue(&I, N);
29382953 }
29392954
29402955 void SelectionDAGBuilder::visitInsertElement(const User &I) {
2525
2626 namespace llvm {
2727
28 class AddrSpaceCastInst;
2829 class AliasAnalysis;
2930 class AllocaInst;
3031 class BasicBlock;
719720 void visitPtrToInt(const User &I);
720721 void visitIntToPtr(const User &I);
721722 void visitBitCast(const User &I);
723 void visitAddrSpaceCast(const User &I);
722724
723725 void visitExtractElement(const User &I);
724726 void visitInsertElement(const User &I);
223223 case ISD::FP_TO_SINT: return "fp_to_sint";
224224 case ISD::FP_TO_UINT: return "fp_to_uint";
225225 case ISD::BITCAST: return "bitcast";
226 case ISD::ADDRSPACECAST: return "addrspacecast";
226227 case ISD::FP16_TO_FP32: return "fp16_to_fp32";
227228 case ISD::FP32_TO_FP16: return "fp32_to_fp16";
228229
484485 OS << " " << offset;
485486 if (unsigned int TF = BA->getTargetFlags())
486487 OS << " [TF=" << TF << ']';
488 } else if (const AddrSpaceCastSDNode *ASC =
489 dyn_cast(this)) {
490 OS << '['
491 << ASC->getSrcAddressSpace()
492 << " -> "
493 << ASC->getDestAddressSpace()
494 << ']';
487495 }
488496
489497 if (unsigned Order = getIROrder())
12871287 case PtrToInt: return ISD::BITCAST;
12881288 case IntToPtr: return ISD::BITCAST;
12891289 case BitCast: return ISD::BITCAST;
1290 case AddrSpaceCast: return ISD::ADDRSPACECAST;
12901291 case ICmp: return ISD::SETCC;
12911292 case FCmp: return ISD::SETCC;
12921293 case PHI: return 0;
446446 I->setMetadata(LLVMContext::MD_tbaa, MDNode::get(I->getContext(), Elts));
447447 }
448448 }
449
450 Instruction *llvm::UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy,
451 Instruction *&Temp) {
452 if (Opc != Instruction::BitCast)
453 return 0;
454
455 Temp = 0;
456 Type *SrcTy = V->getType();
457 if (SrcTy->isPtrOrPtrVectorTy() && DestTy->isPtrOrPtrVectorTy() &&
458 SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace()) {
459 LLVMContext &Context = V->getContext();
460
461 // We have no information about target data layout, so we assume that
462 // the maximum pointer size is 64bit.
463 Type *MidTy = Type::getInt64Ty(Context);
464 Temp = CastInst::Create(Instruction::PtrToInt, V, MidTy);
465
466 return CastInst::Create(Instruction::IntToPtr, Temp, DestTy);
467 }
468
469 return 0;
470 }
471
472 Value *llvm::UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy) {
473 if (Opc != Instruction::BitCast)
474 return 0;
475
476 Type *SrcTy = C->getType();
477 if (SrcTy->isPtrOrPtrVectorTy() && DestTy->isPtrOrPtrVectorTy() &&
478 SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace()) {
479 LLVMContext &Context = C->getContext();
480
481 // We have no information about target data layout, so we assume that
482 // the maximum pointer size is 64bit.
483 Type *MidTy = Type::getInt64Ty(Context);
484
485 return ConstantExpr::getIntToPtr(ConstantExpr::getPtrToInt(C, MidTy),
486 DestTy);
487 }
488
489 return 0;
490 }
688688 }
689689 case Instruction::BitCast:
690690 return FoldBitCast(V, DestTy);
691 case Instruction::AddrSpaceCast:
692 return 0;
691693 }
692694 }
693695
11251125 case Instruction::PtrToInt:
11261126 case Instruction::IntToPtr:
11271127 case Instruction::BitCast:
1128 case Instruction::AddrSpaceCast:
11281129 return ConstantExpr::getCast(getOpcode(), Ops[0], Ty);
11291130 case Instruction::Select:
11301131 return ConstantExpr::getSelect(Ops[0], Ops[1], Ops[2]);
14601461 case Instruction::PtrToInt: return getPtrToInt(C, Ty);
14611462 case Instruction::IntToPtr: return getIntToPtr(C, Ty);
14621463 case Instruction::BitCast: return getBitCast(C, Ty);
1464 case Instruction::AddrSpaceCast: return getAddrSpaceCast(C, Ty);
14631465 }
14641466 }
14651467
14881490
14891491 if (Ty->isIntOrIntVectorTy())
14901492 return getPtrToInt(S, Ty);
1493
1494 unsigned SrcAS = S->getType()->getPointerAddressSpace();
1495 if (Ty->isPtrOrPtrVectorTy() && SrcAS != Ty->getPointerAddressSpace())
1496 return getAddrSpaceCast(S, Ty);
1497
14911498 return getBitCast(S, Ty);
14921499 }
14931500
16591666 if (C->getType() == DstTy) return C;
16601667
16611668 return getFoldedCast(Instruction::BitCast, C, DstTy);
1669 }
1670
1671 Constant *ConstantExpr::getAddrSpaceCast(Constant *C, Type *DstTy) {
1672 assert(CastInst::castIsValid(Instruction::AddrSpaceCast, C, DstTy) &&
1673 "Invalid constantexpr addrspacecast!");
1674
1675 return getFoldedCast(Instruction::AddrSpaceCast, C, DstTy);
16621676 }
16631677
16641678 Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2,
10301030 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
10311031 return wrap(ConstantExpr::getBitCast(unwrap(ConstantVal),
10321032 unwrap(ToType)));
1033 }
1034
1035 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal,
1036 LLVMTypeRef ToType) {
1037 return wrap(ConstantExpr::getAddrSpaceCast(unwrap(ConstantVal),
1038 unwrap(ToType)));
10331039 }
10341040
10351041 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
23172323 return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
23182324 }
23192325
2326 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef B, LLVMValueRef Val,
2327 LLVMTypeRef DestTy, const char *Name) {
2328 return wrap(unwrap(B)->CreateAddrSpaceCast(unwrap(Val), unwrap(DestTy), Name));
2329 }
2330
23202331 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
23212332 LLVMTypeRef DestTy, const char *Name) {
23222333 return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
222222 case GetElementPtr: return "getelementptr";
223223
224224 // Convert instructions...
225 case Trunc: return "trunc";
226 case ZExt: return "zext";
227 case SExt: return "sext";
228 case FPTrunc: return "fptrunc";
229 case FPExt: return "fpext";
230 case FPToUI: return "fptoui";
231 case FPToSI: return "fptosi";
232 case UIToFP: return "uitofp";
233 case SIToFP: return "sitofp";
234 case IntToPtr: return "inttoptr";
235 case PtrToInt: return "ptrtoint";
236 case BitCast: return "bitcast";
225 case Trunc: return "trunc";
226 case ZExt: return "zext";
227 case SExt: return "sext";
228 case FPTrunc: return "fptrunc";
229 case FPExt: return "fpext";
230 case FPToUI: return "fptoui";
231 case FPToSI: return "fptosi";
232 case UIToFP: return "uitofp";
233 case SIToFP: return "sitofp";
234 case IntToPtr: return "inttoptr";
235 case PtrToInt: return "ptrtoint";
236 case BitCast: return "bitcast";
237 case AddrSpaceCast: return "addrspacecast";
237238
238239 // Other instructions...
239240 case ICmp: return "icmp";
20942094 case Instruction::SIToFP:
20952095 case Instruction::FPToUI:
20962096 case Instruction::FPToSI:
2097 return false; // These always modify bits
2097 case Instruction::AddrSpaceCast:
2098 // TODO: Target informations may give a more accurate answer here.
2099 return false;
20982100 case Instruction::BitCast:
20992101 return true; // BitCast never modifies bits.
21002102 case Instruction::PtrToInt:
21362138 // ZEXT < Integral Unsigned Integer Any
21372139 // SEXT < Integral Signed Integer Any
21382140 // FPTOUI n/a FloatPt n/a Integral Unsigned
2139 // FPTOSI n/a FloatPt n/a Integral Signed
2140 // UITOFP n/a Integral Unsigned FloatPt n/a
2141 // SITOFP n/a Integral Signed FloatPt n/a
2142 // FPTRUNC > FloatPt n/a FloatPt n/a
2143 // FPEXT < FloatPt n/a FloatPt n/a
2141 // FPTOSI n/a FloatPt n/a Integral Signed
2142 // UITOFP n/a Integral Unsigned FloatPt n/a
2143 // SITOFP n/a Integral Signed FloatPt n/a
2144 // FPTRUNC > FloatPt n/a FloatPt n/a
2145 // FPEXT < FloatPt n/a FloatPt n/a
21442146 // PTRTOINT n/a Pointer n/a Integral Unsigned
21452147 // INTTOPTR n/a Integral Unsigned Pointer n/a
2146 // BITCAST = FirstClass n/a FirstClass n/a
2148 // BITCAST = FirstClass n/a FirstClass n/a
2149 // ADDRSPCST n/a Pointer n/a Pointer n/a
21472150 //
21482151 // NOTE: some transforms are safe, but we consider them to be non-profitable.
21492152 // For example, we could merge "fptoui double to i32" + "zext i32 to i64",
21502153 // into "fptoui double to i64", but this loses information about the range
2151 // of the produced value (we no longer know the top-part is all zeros).
2154 // of the produced value (we no longer know the top-part is all zeros).
21522155 // Further this conversion is often much more expensive for typical hardware,
2153 // and causes issues when building libgcc. We disallow fptosi+sext for the
2156 // and causes issues when building libgcc. We disallow fptosi+sext for the
21542157 // same reason.
2155 const unsigned numCastOps =
2158 const unsigned numCastOps =
21562159 Instruction::CastOpsEnd - Instruction::CastOpsBegin;
21572160 static const uint8_t CastResults[numCastOps][numCastOps] = {
2158 // T F F U S F F P I B -+
2159 // R Z S P P I I T P 2 N T |
2160 // U E E 2 2 2 2 R E I T C +- secondOp
2161 // N X X U S F F N X N 2 V |
2162 // C T T I I P P C T T P T -+
2163 { 1, 0, 0,99,99, 0, 0,99,99,99, 0, 3 }, // Trunc -+
2164 { 8, 1, 9,99,99, 2, 0,99,99,99, 2, 3 }, // ZExt |
2165 { 8, 0, 1,99,99, 0, 2,99,99,99, 0, 3 }, // SExt |
2166 { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3 }, // FPToUI |
2167 { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3 }, // FPToSI |
2168 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4 }, // UIToFP +- firstOp
2169 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4 }, // SIToFP |
2170 { 99,99,99, 0, 0,99,99, 1, 0,99,99, 4 }, // FPTrunc |
2171 { 99,99,99, 2, 2,99,99,10, 2,99,99, 4 }, // FPExt |
2172 { 1, 0, 0,99,99, 0, 0,99,99,99, 7, 3 }, // PtrToInt |
2173 { 99,99,99,99,99,99,99,99,99,13,99,12 }, // IntToPtr |
2174 { 5, 5, 5, 6, 6, 5, 5, 6, 6,11, 5, 1 }, // BitCast -+
2161 // T F F U S F F P I B A -+
2162 // R Z S P P I I T P 2 N T S |
2163 // U E E 2 2 2 2 R E I T C C +- secondOp
2164 // N X X U S F F N X N 2 V V |
2165 // C T T I I P P C T T P T T -+
2166 { 1, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0}, // Trunc -+
2167 { 8, 1, 9,99,99, 2, 0,99,99,99, 2, 3, 0}, // ZExt |
2168 { 8, 0, 1,99,99, 0, 2,99,99,99, 0, 3, 0}, // SExt |
2169 { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0}, // FPToUI |
2170 { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0}, // FPToSI |
2171 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // UIToFP +- firstOp
2172 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0}, // SIToFP |
2173 { 99,99,99, 0, 0,99,99, 1, 0,99,99, 4, 0}, // FPTrunc |
2174 { 99,99,99, 2, 2,99,99,10, 2,99,99, 4, 0}, // FPExt |
2175 { 1, 0, 0,99,99, 0, 0,99,99,99, 7, 3, 0}, // PtrToInt |
2176 { 99,99,99,99,99,99,99,99,99,11,99,15, 0}, // IntToPtr |
2177 { 5, 5, 5, 6, 6, 5, 5, 6, 6,16, 5, 1,14}, // BitCast |
2178 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13,12}, // AddrSpaceCast -+
21752179 };
2176
2180
21772181 // If either of the casts are a bitcast from scalar to vector, disallow the
21782182 // merging. However, bitcast of A->B->A are allowed.
21792183 bool isFirstBitcast = (firstOp == Instruction::BitCast);
21902194 [secondOp-Instruction::CastOpsBegin];
21912195 switch (ElimCase) {
21922196 case 0:
2193 // categorically disallowed
2197 // Categorically disallowed.
21942198 return 0;
21952199 case 1:
2196 // allowed, use first cast's opcode
2200 // Allowed, use first cast's opcode.
21972201 return firstOp;
21982202 case 2:
2199 // allowed, use second cast's opcode
2203 // Allowed, use second cast's opcode.
22002204 return secondOp;
22012205 case 3:
2202 // no-op cast in second op implies firstOp as long as the DestTy
2206 // No-op cast in second op implies firstOp as long as the DestTy
22032207 // is integer and we are not converting between a vector and a
22042208 // non vector type.
22052209 if (!SrcTy->isVectorTy() && DstTy->isIntegerTy())
22062210 return firstOp;
22072211 return 0;
22082212 case 4:
2209 // no-op cast in second op implies firstOp as long as the DestTy
2213 // No-op cast in second op implies firstOp as long as the DestTy
22102214 // is floating point.
22112215 if (DstTy->isFloatingPointTy())
22122216 return firstOp;
22132217 return 0;
22142218 case 5:
2215 // no-op cast in first op implies secondOp as long as the SrcTy
2219 // No-op cast in first op implies secondOp as long as the SrcTy
22162220 // is an integer.
22172221 if (SrcTy->isIntegerTy())
22182222 return secondOp;
22192223 return 0;
22202224 case 6:
2221 // no-op cast in first op implies secondOp as long as the SrcTy
2225 // No-op cast in first op implies secondOp as long as the SrcTy
22222226 // is a floating point.
22232227 if (SrcTy->isFloatingPointTy())
22242228 return secondOp;
22252229 return 0;
22262230 case 7: {
2231 // Cannot simplify if address spaces are different!
2232 if (SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
2233 return 0;
2234
22272235 unsigned MidSize = MidTy->getScalarSizeInBits();
2228 // Check the address spaces first. If we know they are in the same address
2229 // space, the pointer sizes must be the same so we can still fold this
2230 // without knowing the actual sizes as long we know that the intermediate
2231 // pointer is the largest possible pointer size.
2232 if (MidSize == 64 &&
2233 SrcTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace())
2236 // We can still fold this without knowing the actual sizes as long we
2237 // know that the intermediate pointer is the largest possible
2238 // pointer size.
2239 // FIXME: Is this always true?
2240 if (MidSize == 64)
22342241 return Instruction::BitCast;
22352242
22362243 // ptrtoint, inttoptr -> bitcast (ptr -> ptr) if int size is >= ptr size.
22532260 return firstOp;
22542261 return secondOp;
22552262 }
2256 case 9: // zext, sext -> zext, because sext can't sign extend after zext
2263 case 9:
2264 // zext, sext -> zext, because sext can't sign extend after zext
22572265 return Instruction::ZExt;
22582266 case 10:
22592267 // fpext followed by ftrunc is allowed if the bit size returned to is
22622270 return Instruction::BitCast;
22632271 return 0; // If the types are not the same we can't eliminate it.
22642272 case 11: {
2265 // bitcast followed by ptrtoint is allowed as long as the bitcast is a
2266 // pointer to pointer cast, and the pointers are the same size.
2267 PointerType *SrcPtrTy = dyn_cast(SrcTy);
2268 PointerType *MidPtrTy = dyn_cast(MidTy);
2269 if (!SrcPtrTy || !MidPtrTy)
2270 return 0;
2271
2272 // If the address spaces are the same, we know they are the same size
2273 // without size information
2274 if (SrcPtrTy->getAddressSpace() == MidPtrTy->getAddressSpace())
2275 return secondOp;
2276
2277 if (!SrcIntPtrTy || !MidIntPtrTy)
2278 return 0;
2279
2280 if (SrcIntPtrTy->getScalarSizeInBits() ==
2281 MidIntPtrTy->getScalarSizeInBits())
2282 return secondOp;
2283
2284 return 0;
2285 }
2286 case 12: {
2287 // inttoptr, bitcast -> inttoptr if bitcast is a ptr to ptr cast
2288 // and the ptrs are to address spaces of the same size
2289 PointerType *MidPtrTy = dyn_cast(MidTy);
2290 PointerType *DstPtrTy = dyn_cast(DstTy);
2291 if (!MidPtrTy || !DstPtrTy)
2292 return 0;
2293
2294 if (MidPtrTy->getAddressSpace() == DstPtrTy->getAddressSpace())
2295 return firstOp;
2296
2297 if (MidIntPtrTy &&
2298 DstIntPtrTy &&
2299 MidIntPtrTy->getScalarSizeInBits() ==
2300 DstIntPtrTy->getScalarSizeInBits())
2301 return firstOp;
2302 return 0;
2303 }
2304 case 13: {
23052273 // inttoptr, ptrtoint -> bitcast if SrcSize<=PtrSize and SrcSize==DstSize
23062274 if (!MidIntPtrTy)
23072275 return 0;
23122280 return Instruction::BitCast;
23132281 return 0;
23142282 }
2283 case 12: {
2284 // addrspacecast, addrspacecast -> bitcast, if SrcAS == DstAS
2285 // addrspacecast, addrspacecast -> addrspacecast, if SrcAS != DstAS
2286 if (SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace())
2287 return Instruction::AddrSpaceCast;
2288 return Instruction::BitCast;
2289 }
2290 case 13:
2291 // FIXME: this state can be merged with (1), but the following assert
2292 // is useful to check the correcteness of the sequence due to semantic
2293 // change of bitcast.
2294 assert(
2295 SrcTy->isPtrOrPtrVectorTy() &&
2296 MidTy->isPtrOrPtrVectorTy() &&
2297 DstTy->isPtrOrPtrVectorTy() &&
2298 SrcTy->getPointerAddressSpace() != MidTy->getPointerAddressSpace() &&
2299 MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&
2300 "Illegal addrspacecast, bitcast sequence!");
2301 // Allowed, use first cast's opcode
2302 return firstOp;
2303 case 14:
2304 // FIXME: this state can be merged with (2), but the following assert
2305 // is useful to check the correcteness of the sequence due to semantic
2306 // change of bitcast.
2307 assert(
2308 SrcTy->isPtrOrPtrVectorTy() &&
2309 MidTy->isPtrOrPtrVectorTy() &&
2310 DstTy->isPtrOrPtrVectorTy() &&
2311 SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() &&
2312 MidTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace() &&
2313 "Illegal bitcast, addrspacecast sequence!");
2314 // Allowed, use second cast's opcode
2315 return secondOp;
2316 case 15:
2317 // FIXME: this state can be merged with (1), but the following assert
2318 // is useful to check the correcteness of the sequence due to semantic
2319 // change of bitcast.
2320 assert(
2321 SrcTy->isIntOrIntVectorTy() &&
2322 MidTy->isPtrOrPtrVectorTy() &&
2323 DstTy->isPtrOrPtrVectorTy() &&
2324 MidTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&
2325 "Illegal inttoptr, bitcast sequence!");
2326 // Allowed, use first cast's opcode
2327 return firstOp;
2328 case 16:
2329 // FIXME: this state can be merged with (2), but the following assert
2330 // is useful to check the correcteness of the sequence due to semantic
2331 // change of bitcast.
2332 assert(
2333 SrcTy->isPtrOrPtrVectorTy() &&
2334 MidTy->isPtrOrPtrVectorTy() &&
2335 DstTy->isIntOrIntVectorTy() &&
2336 SrcTy->getPointerAddressSpace() == MidTy->getPointerAddressSpace() &&
2337 "Illegal bitcast, ptrtoint sequence!");
2338 // Allowed, use second cast's opcode
2339 return secondOp;
23152340 case 99:
2316 // cast combination can't happen (error in input). This is for all cases
2341 // Cast combination can't happen (error in input). This is for all cases
23172342 // where the MidTy is not the same for the two cast instructions.
23182343 llvm_unreachable("Invalid Cast Combination");
23192344 default:
23262351 assert(castIsValid(op, S, Ty) && "Invalid cast!");
23272352 // Construct and return the appropriate CastInst subclass
23282353 switch (op) {
2329 case Trunc: return new TruncInst (S, Ty, Name, InsertBefore);
2330 case ZExt: return new ZExtInst (S, Ty, Name, InsertBefore);
2331 case SExt: return new SExtInst (S, Ty, Name, InsertBefore);
2332 case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertBefore);
2333 case FPExt: return new FPExtInst (S, Ty, Name, InsertBefore);
2334 case UIToFP: return new UIToFPInst (S, Ty, Name, InsertBefore);
2335 case SIToFP: return new SIToFPInst (S, Ty, Name, InsertBefore);
2336 case FPToUI: return new FPToUIInst (S, Ty, Name, InsertBefore);
2337 case FPToSI: return new FPToSIInst (S, Ty, Name, InsertBefore);
2338 case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertBefore);
2339 case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertBefore);
2340 case BitCast: return new BitCastInst (S, Ty, Name, InsertBefore);
2341 default: llvm_unreachable("Invalid opcode provided");
2354 case Trunc: return new TruncInst (S, Ty, Name, InsertBefore);
2355 case ZExt: return new ZExtInst (S, Ty, Name, InsertBefore);
2356 case SExt: return new SExtInst (S, Ty, Name, InsertBefore);
2357 case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertBefore);
2358 case FPExt: return new FPExtInst (S, Ty, Name, InsertBefore);
2359 case UIToFP: return new UIToFPInst (S, Ty, Name, InsertBefore);
2360 case SIToFP: return new SIToFPInst (S, Ty, Name, InsertBefore);
2361 case FPToUI: return new FPToUIInst (S, Ty, Name, InsertBefore);
2362 case FPToSI: return new FPToSIInst (S, Ty, Name, InsertBefore);
2363 case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertBefore);
2364 case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertBefore);
2365 case BitCast: return new BitCastInst (S, Ty, Name, InsertBefore);
2366 case AddrSpaceCast: return new AddrSpaceCastInst (S, Ty, Name, InsertBefore);
2367 default: llvm_unreachable("Invalid opcode provided");
23422368 }
23432369 }
23442370
23472373 assert(castIsValid(op, S, Ty) && "Invalid cast!");
23482374 // Construct and return the appropriate CastInst subclass
23492375 switch (op) {
2350 case Trunc: return new TruncInst (S, Ty, Name, InsertAtEnd);
2351 case ZExt: return new ZExtInst (S, Ty, Name, InsertAtEnd);
2352 case SExt: return new SExtInst (S, Ty, Name, InsertAtEnd);
2353 case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertAtEnd);
2354 case FPExt: return new FPExtInst (S, Ty, Name, InsertAtEnd);
2355 case UIToFP: return new UIToFPInst (S, Ty, Name, InsertAtEnd);
2356 case SIToFP: return new SIToFPInst (S, Ty, Name, InsertAtEnd);
2357 case FPToUI: return new FPToUIInst (S, Ty, Name, InsertAtEnd);
2358 case FPToSI: return new FPToSIInst (S, Ty, Name, InsertAtEnd);
2359 case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertAtEnd);
2360 case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertAtEnd);
2361 case BitCast: return new BitCastInst (S, Ty, Name, InsertAtEnd);
2362 default: llvm_unreachable("Invalid opcode provided");
2376 case Trunc: return new TruncInst (S, Ty, Name, InsertAtEnd);
2377 case ZExt: return new ZExtInst (S, Ty, Name, InsertAtEnd);
2378 case SExt: return new SExtInst (S, Ty, Name, InsertAtEnd);
2379 case FPTrunc: return new FPTruncInst (S, Ty, Name, InsertAtEnd);
2380 case FPExt: return new FPExtInst (S, Ty, Name, InsertAtEnd);
2381 case UIToFP: return new UIToFPInst (S, Ty, Name, InsertAtEnd);
2382 case SIToFP: return new SIToFPInst (S, Ty, Name, InsertAtEnd);
2383 case FPToUI: return new FPToUIInst (S, Ty, Name, InsertAtEnd);
2384 case FPToSI: return new FPToSIInst (S, Ty, Name, InsertAtEnd);
2385 case PtrToInt: return new PtrToIntInst (S, Ty, Name, InsertAtEnd);
2386 case IntToPtr: return new IntToPtrInst (S, Ty, Name, InsertAtEnd);
2387 case BitCast: return new BitCastInst (S, Ty, Name, InsertAtEnd);
2388 case AddrSpaceCast: return new AddrSpaceCastInst (S, Ty, Name, InsertAtEnd);
2389 default: llvm_unreachable("Invalid opcode provided");
23632390 }
23642391 }
23652392
24242451
24252452 if (Ty->isIntOrIntVectorTy())
24262453 return Create(Instruction::PtrToInt, S, Ty, Name, InsertAtEnd);
2454
2455 Type *STy = S->getType();
2456 if (STy->getPointerAddressSpace() != Ty->getPointerAddressSpace())
2457 return Create(Instruction::AddrSpaceCast, S, Ty, Name, InsertAtEnd);
2458
24272459 return Create(Instruction::BitCast, S, Ty, Name, InsertAtEnd);
24282460 }
24292461
24412473
24422474 if (Ty->isIntOrIntVectorTy())
24432475 return Create(Instruction::PtrToInt, S, Ty, Name, InsertBefore);
2476
2477 Type *STy = S->getType();
2478 if (STy->getPointerAddressSpace() != Ty->getPointerAddressSpace())
2479 return Create(Instruction::AddrSpaceCast, S, Ty, Name, InsertBefore);
2480
24442481 return Create(Instruction::BitCast, S, Ty, Name, InsertBefore);
24452482 }
24462483
26862723 return BitCast;
26872724 } else if (DestTy->isPointerTy()) {
26882725 if (SrcTy->isPointerTy()) {
2689 // TODO: Address space pointer sizes may not match
2726 if (DestTy->getPointerAddressSpace() != SrcTy->getPointerAddressSpace())
2727 return AddrSpaceCast;
26902728 return BitCast; // ptr -> ptr
26912729 } else if (SrcTy->isIntegerTy()) {
26922730 return IntToPtr; // int -> ptr
27812819 case Instruction::BitCast:
27822820 // BitCast implies a no-op cast of type only. No bits change.
27832821 // However, you can't cast pointers to anything but pointers.
2784 if (SrcTy->isPointerTy() != DstTy->isPointerTy())
2822 if (SrcTy->isPtrOrPtrVectorTy() != DstTy->isPtrOrPtrVectorTy())
27852823 return false;
27862824
2787 // Now we know we're not dealing with a pointer/non-pointer mismatch. In all
2788 // these cases, the cast is okay if the source and destination bit widths
2789 // are identical.
2790 return SrcTy->getPrimitiveSizeInBits() == DstTy->getPrimitiveSizeInBits();
2825 // For non pointer cases, the cast is okay if the source and destination bit
2826 // widths are identical.
2827 if (!SrcTy->isPtrOrPtrVectorTy())
2828 return SrcTy->getPrimitiveSizeInBits() == DstTy->getPrimitiveSizeInBits();
2829
2830 // If both are pointers then the address spaces must match and vector of
2831 // pointers must have the same number of elements.
2832 return SrcTy->getPointerAddressSpace() == DstTy->getPointerAddressSpace() &&
2833 SrcTy->isVectorTy() == DstTy->isVectorTy() &&
2834 (!SrcTy->isVectorTy() ||
2835 SrcTy->getVectorNumElements() == SrcTy->getVectorNumElements());
2836
2837 case Instruction::AddrSpaceCast:
2838 return SrcTy->isPtrOrPtrVectorTy() && DstTy->isPtrOrPtrVectorTy() &&
2839 SrcTy->getPointerAddressSpace() != DstTy->getPointerAddressSpace() &&
2840 SrcTy->isVectorTy() == DstTy->isVectorTy() &&
2841 (!SrcTy->isVectorTy() ||
2842 SrcTy->getVectorNumElements() == SrcTy->getVectorNumElements());
27912843 }
27922844 }
27932845
29322984 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
29332985 ) : CastInst(Ty, BitCast, S, Name, InsertAtEnd) {
29342986 assert(castIsValid(getOpcode(), S, Ty) && "Illegal BitCast");
2987 }
2988
2989 AddrSpaceCastInst::AddrSpaceCastInst(
2990 Value *S, Type *Ty, const Twine &Name, Instruction *InsertBefore
2991 ) : CastInst(Ty, AddrSpaceCast, S, Name, InsertBefore) {
2992 assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast");
2993 }
2994
2995 AddrSpaceCastInst::AddrSpaceCastInst(
2996 Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd
2997 ) : CastInst(Ty, AddrSpaceCast, S, Name, InsertAtEnd) {
2998 assert(castIsValid(getOpcode(), S, Ty) && "Illegal AddrSpaceCast");
29352999 }
29363000
29373001 //===----------------------------------------------------------------------===//
35523616 return new BitCastInst(getOperand(0), getType());
35533617 }
35543618
3619 AddrSpaceCastInst *AddrSpaceCastInst::clone_impl() const {
3620 return new AddrSpaceCastInst(getOperand(0), getType());
3621 }
3622
35553623 CallInst *CallInst::clone_impl() const {
35563624 return new(getNumOperands()) CallInst(*this);
35573625 }
364364 break;
365365 }
366366 V = GEP->getPointerOperand();
367 } else if (Operator::getOpcode(V) == Instruction::BitCast) {
367 } else if (Operator::getOpcode(V) == Instruction::BitCast ||
368 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
368369 V = cast(V)->getOperand(0);
369370 } else if (GlobalAlias *GA = dyn_cast(V)) {
370371 if (StripKind == PSK_ZeroIndices || GA->mayBeOverridden())
282282 void visitIntToPtrInst(IntToPtrInst &I);
283283 void visitPtrToIntInst(PtrToIntInst &I);
284284 void visitBitCastInst(BitCastInst &I);
285 void visitAddrSpaceCastInst(AddrSpaceCastInst &I);
285286 void visitPHINode(PHINode &PN);
286287 void visitBinaryOperator(BinaryOperator &B);
287288 void visitICmpInst(ICmpInst &IC);
964965 unsigned SrcAS = SrcTy->getPointerAddressSpace();
965966 unsigned DstAS = DestTy->getPointerAddressSpace();
966967
967 unsigned SrcASSize = DL->getPointerSizeInBits(SrcAS);
968 unsigned DstASSize = DL->getPointerSizeInBits(DstAS);
969 Assert1(SrcASSize == DstASSize,
970 "Bitcasts between pointers of different address spaces must have "
971 "the same size pointers, otherwise use PtrToInt/IntToPtr.", V);
968 Assert1(SrcAS == DstAS,
969 "Bitcasts between pointers of different address spaces is not legal."
970 "Use AddrSpaceCast instead.", V);
972971 }
973972
974973 void Verifier::VerifyConstantExprBitcastType(const ConstantExpr *CE) {
14511450 Type *SrcTy = I.getOperand(0)->getType();
14521451 Type *DestTy = I.getType();
14531452 VerifyBitcastType(&I, DestTy, SrcTy);
1453 visitInstruction(I);
1454 }
1455
1456 void Verifier::visitAddrSpaceCastInst(AddrSpaceCastInst &I) {
1457 Type *SrcTy = I.getOperand(0)->getType();
1458 Type *DestTy = I.getType();
1459
1460 Assert1(SrcTy->isPtrOrPtrVectorTy(),
1461 "AddrSpaceCast source must be a pointer", &I);
1462 Assert1(DestTy->isPtrOrPtrVectorTy(),
1463 "AddrSpaceCast result must be a pointer", &I);
1464 Assert1(SrcTy->getPointerAddressSpace() != DestTy->getPointerAddressSpace(),
1465 "AddrSpaceCast must be between different address spaces", &I);
1466 if (SrcTy->isVectorTy())
1467 Assert1(SrcTy->getVectorNumElements() == DestTy->getVectorNumElements(),
1468 "AddrSpaceCast vector pointer number of elements mismatch", &I);
14541469 visitInstruction(I);
14551470 }
14561471
141141 GlobalVariable *GV = I->first;
142142 GlobalVariable *NewGV = I->second;
143143 ++I;
144 Constant *BitCastNewGV = ConstantExpr::getBitCast(NewGV, GV->getType());
144 Constant *BitCastNewGV = ConstantExpr::getPointerCast(NewGV, GV->getType());
145145 // At this point, the remaining uses of GV should be found only in global
146146 // variable initializers, as other uses have been already been removed
147147 // while walking through the instructions in function definitions.
9191 VecIdx);
9292
9393 return Result;
94
94
9595 }
9696 /// Generate a DAG to grab 128-bits from a vector > 128 bits. This
9797 /// sets things up to match to an AVX VEXTRACTF128 / VEXTRACTI128
17621762 AddressSpace = 256;
17631763 }
17641764 return true;
1765 }
1766
1767 bool X86TargetLowering::isNoopAddrSpaceCast(unsigned SrcAS,
1768 unsigned DestAS) const {
1769 assert(SrcAS != DestAS && "Expected different address spaces!");
1770
1771 return SrcAS < 256 && DestAS < 256;
17651772 }
17661773
17671774 //===----------------------------------------------------------------------===//
773773
774774 SDValue BuildFILD(SDValue Op, EVT SrcVT, SDValue Chain, SDValue StackSlot,
775775 SelectionDAG &DAG) const;
776
777 virtual bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const LLVM_OVERRIDE;
776778
777779 /// \brief Reset the operation actions based on target options.
778780 virtual void resetOperationActions();
1111 @F = global i32* inttoptr (i32 add (i32 5, i32 -5) to i32*)
1212 @G = global i32* inttoptr (i32 sub (i32 5, i32 5) to i32*)
1313
14 ; Address space cast AS0 null-> AS1 null
15 @H = global i32 addrspace(1)* addrspacecast(i32* null to i32 addrspace(1)*)
2020
2121 ; CHECK: @D = global i1 icmp eq (i64* getelementptr inbounds (i64* @A, i64 1), i64* getelementptr inbounds (i64* @B, i64 2))
2222 @D = global i1 icmp eq (i64* getelementptr inbounds (i64* @A, i64 1), i64* getelementptr inbounds (i64* @B, i64 2))
23
24 ; CHECK: @E = global i64 addrspace(1)* addrspacecast (i64* @A to i64 addrspace(1)*)
25 @E = global i64 addrspace(1)* addrspacecast(i64* @A to i64 addrspace(1)*)
3333 vector_kernel_entry.i: ; preds = %vector_kernel_entry.i, %dim_0_vector_pre_head.i
3434 %asr.iv9 = phi i8* [ %scevgep10, %vector_kernel_entry.i ], [ %asr.iv6, %dim_0_vector_pre_head.i ]
3535 %asr.iv = phi i64 [ %asr.iv.next, %vector_kernel_entry.i ], [ %vector.size.i, %dim_0_vector_pre_head.i ]
36 %8 = bitcast i8* %ptrtoarg4 to i32 addrspace(1)*
37 %asr.iv911 = bitcast i8* %asr.iv9 to <8 x i32> addrspace(1)*
36 %8 = addrspacecast i8* %ptrtoarg4 to i32 addrspace(1)*
37 %asr.iv911 = addrspacecast i8* %asr.iv9 to <8 x i32> addrspace(1)*
3838 %9 = load <8 x i32> addrspace(1)* %asr.iv911, align 4
3939 %extract8vector_func.i = extractelement <8 x i32> %9, i32 0
4040 %extract9vector_func.i = extractelement <8 x i32> %9, i32 1
7272
7373 scalar_kernel_entry.i: ; preds = %scalar_kernel_entry.i, %dim_0_pre_head.i
7474 %asr.iv12 = phi i64 [ %asr.iv.next13, %scalar_kernel_entry.i ], [ %22, %dim_0_pre_head.i ]
75 %23 = bitcast i8* %asr.iv6 to i32 addrspace(1)*
76 %24 = bitcast i8* %ptrtoarg4 to i32 addrspace(1)*
75 %23 = addrspacecast i8* %asr.iv6 to i32 addrspace(1)*
76 %24 = addrspacecast i8* %ptrtoarg4 to i32 addrspace(1)*
7777 %scevgep16 = getelementptr i32 addrspace(1)* %23, i64 %asr.iv12
7878 %25 = load i32 addrspace(1)* %scevgep16, align 4
7979 %26 = atomicrmw min i32 addrspace(1)* %24, i32 %25 seq_cst
88 @sgv = internal addrspace(2) constant [1 x i8] zeroinitializer
99 @fgv = internal addrspace(2) constant [1 x i8] zeroinitializer
1010 @lvgv = internal constant [0 x i8*] zeroinitializer
11 @llvm.global.annotations = appending global [1 x %0] [%0 { i8* bitcast (void (i32 addrspace(1)*)* @__OpenCL_nbt02_kernel to i8*), i8* bitcast ([1 x i8] addrspace(2)* @sgv to i8*), i8* bitcast ([1 x i8] addrspace(2)* @fgv to i8*), i8* bitcast ([0 x i8*]* @lvgv to i8*), i32 0 }], section "llvm.metadata"
11 @llvm.global.annotations = appending global [1 x %0] [%0 { i8* bitcast (void (i32 addrspace(1)*)* @__OpenCL_nbt02_kernel to i8*), i8* addrspacecast ([1 x i8] addrspace(2)* @sgv to i8*), i8* addrspacecast ([1 x i8] addrspace(2)* @fgv to i8*), i8* bitcast ([0 x i8*]* @lvgv to i8*), i32 0 }], section "llvm.metadata"
1212
1313 define void @__OpenCL_nbt02_kernel(i32 addrspace(1)* %ip) nounwind {
1414 entry:
1919 %p = uitofp <4 x i32> %n to <4 x float>
2020 %q = fptosi <4 x float> %p to <4 x i32>
2121 %r = fptoui <4 x float> %p to <4 x i32>
22 %s = inttoptr <4 x i32> %n to <4 x i32*>
23 %t = addrspacecast <4 x i32*> %s to <4 x i32 addrspace(1)*>
24 %z = addrspacecast <4 x i32*> %s to <4 x float addrspace(2)*>
2225 ret void
2326 }
2427
453453
454454 define i8* @different_addrspace() nounwind noinline {
455455 ; OPT: different_addrspace
456 %p = getelementptr inbounds i8* bitcast ([4 x i8] addrspace(12)* @p12 to i8*),
456 %p = getelementptr inbounds i8* addrspacecast ([4 x i8] addrspace(12)* @p12 to i8*),
457457 i32 2
458458 ret i8* %p
459 ; OPT: ret i8* getelementptr (i8* bitcast ([4 x i8] addrspace(12)* @p12 to i8*), i32 2)
459 ; OPT: ret i8* getelementptr (i8* addrspacecast ([4 x i8] addrspace(12)* @p12 to i8*), i32 2)
460460 }
461461
462462 define i8* @same_addrspace() nounwind noinline {
44
55 define i32 @test(i32* %P) nounwind {
66 entry:
7 %Q = bitcast i32* %P to i32 addrspace(1)*
7 %Q = addrspacecast i32* %P to i32 addrspace(1)*
88 store i32 0, i32 addrspace(1)* %Q, align 4
99 ret i32 0
1010 }
0 ; RUN: opt < %s -instcombine -S | FileCheck %s
1 ; CHECK: bitcast
1 ; CHECK: addrspacecast
22
33 @base = internal addrspace(3) unnamed_addr global [16 x i32] zeroinitializer, align 16
44 declare void @foo(i32*)
55
66 define void @test() nounwind {
7 call void @foo(i32* getelementptr (i32* bitcast ([16 x i32] addrspace(3)* @base to i32*), i64 2147483647)) nounwind
7 call void @foo(i32* getelementptr (i32* addrspacecast ([16 x i32] addrspace(3)* @base to i32*), i64 2147483647)) nounwind
88 ret void
99 }
9999
100100 define i8 @test6(i8 addrspace(1)* %source) {
101101 entry:
102 %arrayidx223 = bitcast i8 addrspace(1)* %source to i8*
102 %arrayidx223 = addrspacecast i8 addrspace(1)* %source to i8*
103103 %tmp4 = load i8* %arrayidx223
104104 ret i8 %tmp4
105105 ; CHECK-LABEL: @test6(
3131 }
3232
3333 ; Different address spaces that are the same size, but they are
34 ; different so there should be a bitcast.
34 ; different so nothing should happen
3535 define i32 addrspace(4)* @test_constant_fold_inttoptr_as_pointer_smaller_different_as() {
3636 ; CHECK-LABEL: @test_constant_fold_inttoptr_as_pointer_smaller_different_as(
37 ; CHECK-NEXT: ret i32 addrspace(4)* bitcast (i32 addrspace(3)* @const_zero_i32_as3 to i32 addrspace(4)*)
37 ; CHECK-NEXT: ret i32 addrspace(4)* inttoptr (i16 ptrtoint (i32 addrspace(3)* @const_zero_i32_as3 to i16) to i32 addrspace(4)*)
3838 %x = ptrtoint i32 addrspace(3)* @const_zero_i32_as3 to i16
3939 %y = inttoptr i16 %x to i32 addrspace(4)*
4040 ret i32 addrspace(4)* %y
88 define void @func(%myStruct addrspace(1)* nocapture %p) nounwind {
99 ST:
1010 %A = getelementptr inbounds %myStruct addrspace(1)* %p, i64 0
11 %B = bitcast %myStruct addrspace(1)* %A to %myStruct*
11 %B = addrspacecast %myStruct addrspace(1)* %A to %myStruct*
1212 %C = getelementptr inbounds %myStruct* %B, i32 0, i32 1
1313 %D = getelementptr inbounds [3 x float]* %C, i32 0, i32 2
1414 %E = load float* %D, align 4
4848 define i32 @pointer_array_as1() {
4949 ; CHECK-LABEL: @pointer_array_as1(
5050 ; CHECK-NEXT: ret i32 80
51 %bc = bitcast [10 x i32 addrspace(1)*]* @array_as1_pointers to i8 addrspace(1)*
51 %bc = addrspacecast [10 x i32 addrspace(1)*]* @array_as1_pointers to i8 addrspace(1)*
5252 %1 = call i32 @llvm.objectsize.i32.p1i8(i8 addrspace(1)* %bc, i1 false)
5353 ret i32 %1
5454 }
148148 const Constant* c8 = Constant::getNullValue(V8x8Ty);
149149 const Constant* c64 = Constant::getNullValue(V8x64Ty);
150150
151 const Constant *v2ptr32 = Constant::getNullValue(V2Int32PtrTy);
152
151153 EXPECT_TRUE(CastInst::isCastable(V8x8Ty, X86MMXTy));
152154 EXPECT_TRUE(CastInst::isCastable(X86MMXTy, V8x8Ty));
153155 EXPECT_FALSE(CastInst::isCastable(Int64Ty, X86MMXTy));
168170 EXPECT_FALSE(CastInst::isBitCastable(V2Int32PtrTy, V2Int32PtrAS1Ty));
169171 EXPECT_FALSE(CastInst::isBitCastable(V2Int32PtrAS1Ty, V2Int32PtrTy));
170172 EXPECT_TRUE(CastInst::isBitCastable(V2Int32PtrAS1Ty, V2Int64PtrAS1Ty));
173 EXPECT_TRUE(CastInst::isCastable(V2Int32PtrAS1Ty, V2Int32PtrTy));
174 EXPECT_EQ(CastInst::AddrSpaceCast, CastInst::getCastOpcode(v2ptr32, true,
175 V2Int32PtrAS1Ty,
176 true));
171177
172178 // Test mismatched number of elements for pointers
173179 EXPECT_FALSE(CastInst::isBitCastable(V2Int32PtrAS1Ty, V4Int64PtrAS1Ty));
370376 0, Int32Ty, 0),
371377 0U);
372378
373
374379 // Test that we don't eliminate bitcasts between different address spaces,
375380 // or if we don't have available pointer size information.
376381 DataLayout DL("e-p:32:32:32-p1:16:16:16-p2:64:64:64-i1:8:8-i8:8:8-i16:16:16"
383388 IntegerType *Int16SizePtr = DL.getIntPtrType(C, 1);
384389 IntegerType *Int64SizePtr = DL.getIntPtrType(C, 2);
385390
386 // Fail since the ptr int types are not provided
391 // Cannot simplify inttoptr, addrspacecast
387392 EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
388 CastInst::BitCast,
389 Int16Ty, Int64PtrTyAS1, Int64PtrTyAS2,
390 0, 0, 0),
391 0U);
392
393 // Fail since the the bitcast is between different sized address spaces
394 EXPECT_EQ(CastInst::isEliminableCastPair(
395 CastInst::IntToPtr,
396 CastInst::BitCast,
397 Int16Ty, Int64PtrTyAS1, Int64PtrTyAS2,
398 0, Int16SizePtr, Int64SizePtr),
399 0U);
400
401 // Fail since the the bitcast is between different sized address spaces
402 EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::IntToPtr,
403 CastInst::BitCast,
393 CastInst::AddrSpaceCast,
404394 Int16Ty, Int64PtrTyAS1, Int64PtrTyAS2,
405395 0, Int16SizePtr, Int64SizePtr),
396 0U);
397
398 // Cannot simplify addrspacecast, ptrtoint
399 EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::AddrSpaceCast,
400 CastInst::PtrToInt,
401 Int64PtrTyAS1, Int64PtrTyAS2, Int16Ty,
402 Int64SizePtr, Int16SizePtr, 0),
406403 0U);
407404
408405 // Pass since the bitcast address spaces are the same
412409 0, 0, 0),
413410 CastInst::IntToPtr);
414411
415
416 // Fail without known pointer sizes and different address spaces
417 EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::BitCast,
418 CastInst::PtrToInt,
419 Int64PtrTyAS1, Int64PtrTyAS2, Int16Ty,
420 0, 0, 0),
421 0U);
422
423 // Pass since the address spaces are the same, even though the pointer sizes
424 // are unknown
425 EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::BitCast,
426 CastInst::PtrToInt,
427 Int64PtrTyAS1, Int64PtrTyAS1, Int32Ty,
428 0, 0, 0),
429 Instruction::PtrToInt);
430
431 // Fail since the bitcast is the wrong size
432 EXPECT_EQ(CastInst::isEliminableCastPair(CastInst::BitCast,
433 CastInst::PtrToInt,
434 Int64PtrTyAS1, Int64PtrTyAS2, Int64Ty,
435 Int16SizePtr, Int64SizePtr, 0),
436 0U);
437412 }
438413
439414 } // end anonymous namespace
4242 ;; Memory operators
4343 `(,(regexp-opt '("malloc" "alloca" "free" "load" "store" "getelementptr" "fence" "cmpxchg" "atomicrmw") 'words) . font-lock-keyword-face)
4444 ;; Casts
45 `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp") 'words) . font-lock-keyword-face)
45 `(,(regexp-opt '("bitcast" "inttoptr" "ptrtoint" "trunc" "zext" "sext" "fptrunc" "fpext" "fptoui" "fptosi" "uitofp" "sitofp" "addrspacecast") 'words) . font-lock-keyword-face)
4646 ;; Vector ops
4747 `(,(regexp-opt '("extractelement" "insertelement" "shufflevector") 'words) . font-lock-keyword-face)
4848 ;; Aggregate ops
156156 ptrtoint
157157 inttoptr
158158 bitcast
159 addrspacecast
159160 icmp
160161 fcmp
161162 phi
2121 " Instructions.
2222 " The true and false tokens can be used for comparison opcodes, but it's
2323 " much more common for these tokens to be used for boolean constants.
24 syn keyword llvmStatement add alloca and arcp ashr atomicrmw bitcast br call
25 syn keyword llvmStatement cmpxchg eq exact extractelement extractvalue fadd fast
26 syn keyword llvmStatement fcmp fdiv fence fmul fpext fptosi fptoui fptrunc free
27 syn keyword llvmStatement frem fsub getelementptr icmp inbounds indirectbr
28 syn keyword llvmStatement insertelement insertvalue inttoptr invoke landingpad
29 syn keyword llvmStatement load lshr malloc max min mul nand ne ninf nnan nsw nsz
30 syn keyword llvmStatement nuw oeq oge ogt ole olt one or ord phi ptrtoint resume
31 syn keyword llvmStatement ret sdiv select sext sge sgt shl shufflevector sitofp
32 syn keyword llvmStatement sle slt srem store sub switch trunc udiv ueq uge ugt
33 syn keyword llvmStatement uitofp ule ult umax umin une uno unreachable unwind
34 syn keyword llvmStatement urem va_arg xchg xor zext
24 syn keyword llvmStatement add addrspacecast alloca and arcp ashr atomicrmw
25 syn keyword llvmStatement bitcast br call cmpxchg eq exact extractelement
26 syn keyword llvmStatement extractvalue fadd fast fcmp fdiv fence fmul fpext
27 syn keyword llvmStatement fptosi fptoui fptrunc free frem fsub getelementptr
28 syn keyword llvmStatement icmp inbounds indirectbr insertelement insertvalue
29 syn keyword llvmStatement inttoptr invoke landingpad load lshr malloc max min
30 syn keyword llvmStatement mul nand ne ninf nnan nsw nsz nuw oeq oge ogt ole
31 syn keyword llvmStatement olt one or ord phi ptrtoint resume ret sdiv select
32 syn keyword llvmStatement sext sge sgt shl shufflevector sitofp sle slt srem
33 syn keyword llvmStatement store sub switch trunc udiv ueq uge ugt uitofp ule ult
34 syn keyword llvmStatement umax umin une uno unreachable unwind urem va_arg
35 syn keyword llvmStatement xchg xor zext
3536
3637 " Keywords.
3738 syn keyword llvmKeyword acq_rel acquire sanitize_address addrspace alias align