mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-11-03 14:21:30 +00:00 
			
		
		
		
	Change behavior of calling bitcasted alias functions.
It will now only convert the arguments / return value and call the underlying function if the types are able to be bitcasted. This avoids using fp<->int conversions that would occur before. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187444 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		@@ -531,6 +531,12 @@ public:
 | 
				
			|||||||
    Type *DestTy ///< The Type to which the value should be cast.
 | 
					    Type *DestTy ///< The Type to which the value should be cast.
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /// @brief Check whether a bitcast between these types is valid
 | 
				
			||||||
 | 
					  static bool isBitCastable(
 | 
				
			||||||
 | 
					    Type *SrcTy, ///< The Type from which the value should be cast.
 | 
				
			||||||
 | 
					    Type *DestTy ///< The Type to which the value should be cast.
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Returns the opcode necessary to cast Val into Ty using usual casting
 | 
					  /// Returns the opcode necessary to cast Val into Ty using usual casting
 | 
				
			||||||
  /// rules.
 | 
					  /// rules.
 | 
				
			||||||
  /// @brief Infer the opcode for cast operand and type
 | 
					  /// @brief Infer the opcode for cast operand and type
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2517,6 +2517,46 @@ bool CastInst::isCastable(Type *SrcTy, Type *DestTy) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool CastInst::isBitCastable(Type *SrcTy, Type *DestTy) {
 | 
				
			||||||
 | 
					  if (!SrcTy->isFirstClassType() || !DestTy->isFirstClassType())
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (SrcTy == DestTy)
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {
 | 
				
			||||||
 | 
					    if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy)) {
 | 
				
			||||||
 | 
					      if (SrcVecTy->getNumElements() == DestVecTy->getNumElements()) {
 | 
				
			||||||
 | 
					        // An element by element cast. Valid if casting the elements is valid.
 | 
				
			||||||
 | 
					        SrcTy = SrcVecTy->getElementType();
 | 
				
			||||||
 | 
					        DestTy = DestVecTy->getElementType();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (PointerType *DestPtrTy = dyn_cast<PointerType>(DestTy)) {
 | 
				
			||||||
 | 
					    if (PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy)) {
 | 
				
			||||||
 | 
					      return SrcPtrTy->getAddressSpace() == DestPtrTy->getAddressSpace();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  unsigned SrcBits = SrcTy->getPrimitiveSizeInBits();   // 0 for ptr
 | 
				
			||||||
 | 
					  unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Could still have vectors of pointers if the number of elements doesn't
 | 
				
			||||||
 | 
					  // match
 | 
				
			||||||
 | 
					  if (SrcBits == 0 || DestBits == 0)
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (SrcBits != DestBits)
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (DestTy->isX86_MMXTy() || SrcTy->isX86_MMXTy())
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Provide a way to get a "cast" where the cast opcode is inferred from the
 | 
					// Provide a way to get a "cast" where the cast opcode is inferred from the
 | 
				
			||||||
// types and size of the operand. This, basically, is a parallel of the
 | 
					// types and size of the operand. This, basically, is a parallel of the
 | 
				
			||||||
// logic in the castIsValid function below.  This axiom should hold:
 | 
					// logic in the castIsValid function below.  This axiom should hold:
 | 
				
			||||||
@@ -2535,6 +2575,7 @@ CastInst::getCastOpcode(
 | 
				
			|||||||
  if (SrcTy == DestTy)
 | 
					  if (SrcTy == DestTy)
 | 
				
			||||||
    return BitCast;
 | 
					    return BitCast;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // FIXME: Check address space sizes here
 | 
				
			||||||
  if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy))
 | 
					  if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy))
 | 
				
			||||||
    if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy))
 | 
					    if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy))
 | 
				
			||||||
      if (SrcVecTy->getNumElements() == DestVecTy->getNumElements()) {
 | 
					      if (SrcVecTy->getNumElements() == DestVecTy->getNumElements()) {
 | 
				
			||||||
@@ -2601,6 +2642,7 @@ CastInst::getCastOpcode(
 | 
				
			|||||||
    return BitCast;
 | 
					    return BitCast;
 | 
				
			||||||
  } else if (DestTy->isPointerTy()) {
 | 
					  } else if (DestTy->isPointerTy()) {
 | 
				
			||||||
    if (SrcTy->isPointerTy()) {
 | 
					    if (SrcTy->isPointerTy()) {
 | 
				
			||||||
 | 
					      // TODO: Address space pointer sizes may not match
 | 
				
			||||||
      return BitCast;                               // ptr -> ptr
 | 
					      return BitCast;                               // ptr -> ptr
 | 
				
			||||||
    } else if (SrcTy->isIntegerTy()) {
 | 
					    } else if (SrcTy->isIntegerTy()) {
 | 
				
			||||||
      return IntToPtr;                              // int -> ptr
 | 
					      return IntToPtr;                              // int -> ptr
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1010,7 +1010,8 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (!Caller->use_empty() &&
 | 
					    if (!Caller->use_empty() &&
 | 
				
			||||||
        // void -> non-void is handled specially
 | 
					        // void -> non-void is handled specially
 | 
				
			||||||
        !NewRetTy->isVoidTy() && !CastInst::isCastable(NewRetTy, OldRetTy))
 | 
					        !NewRetTy->isVoidTy() &&
 | 
				
			||||||
 | 
					        !CastInst::isBitCastable(NewRetTy, OldRetTy))
 | 
				
			||||||
      return false;   // Cannot transform this return value.
 | 
					      return false;   // Cannot transform this return value.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!CallerPAL.isEmpty() && !Caller->use_empty()) {
 | 
					    if (!CallerPAL.isEmpty() && !Caller->use_empty()) {
 | 
				
			||||||
@@ -1044,8 +1045,9 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
 | 
				
			|||||||
    Type *ParamTy = FT->getParamType(i);
 | 
					    Type *ParamTy = FT->getParamType(i);
 | 
				
			||||||
    Type *ActTy = (*AI)->getType();
 | 
					    Type *ActTy = (*AI)->getType();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!CastInst::isCastable(ActTy, ParamTy))
 | 
					    if (!CastInst::isBitCastable(ActTy, ParamTy)) {
 | 
				
			||||||
      return false;   // Cannot transform this parameter value.
 | 
					      return false;   // Cannot transform this parameter value.
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (AttrBuilder(CallerPAL.getParamAttributes(i + 1), i + 1).
 | 
					    if (AttrBuilder(CallerPAL.getParamAttributes(i + 1), i + 1).
 | 
				
			||||||
          hasAttributes(AttributeFuncs::
 | 
					          hasAttributes(AttributeFuncs::
 | 
				
			||||||
@@ -1074,7 +1076,8 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
 | 
				
			|||||||
      ParamTy == TD->getIntPtrType(Caller->getContext())) &&
 | 
					      ParamTy == TD->getIntPtrType(Caller->getContext())) &&
 | 
				
			||||||
              (ActTy->isPointerTy() ||
 | 
					              (ActTy->isPointerTy() ||
 | 
				
			||||||
              ActTy == TD->getIntPtrType(Caller->getContext()))));
 | 
					              ActTy == TD->getIntPtrType(Caller->getContext()))));
 | 
				
			||||||
    if (Callee->isDeclaration() && !isConvertible) return false;
 | 
					    if (Callee->isDeclaration() && !isConvertible)
 | 
				
			||||||
 | 
					      return false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (Callee->isDeclaration()) {
 | 
					  if (Callee->isDeclaration()) {
 | 
				
			||||||
@@ -1141,12 +1144,11 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
 | 
				
			|||||||
  AI = CS.arg_begin();
 | 
					  AI = CS.arg_begin();
 | 
				
			||||||
  for (unsigned i = 0; i != NumCommonArgs; ++i, ++AI) {
 | 
					  for (unsigned i = 0; i != NumCommonArgs; ++i, ++AI) {
 | 
				
			||||||
    Type *ParamTy = FT->getParamType(i);
 | 
					    Type *ParamTy = FT->getParamType(i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((*AI)->getType() == ParamTy) {
 | 
					    if ((*AI)->getType() == ParamTy) {
 | 
				
			||||||
      Args.push_back(*AI);
 | 
					      Args.push_back(*AI);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      Instruction::CastOps opcode = CastInst::getCastOpcode(*AI,
 | 
					      Args.push_back(Builder->CreateBitCast(*AI, ParamTy));
 | 
				
			||||||
          false, ParamTy, false);
 | 
					 | 
				
			||||||
      Args.push_back(Builder->CreateCast(opcode, *AI, ParamTy));
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Add any parameter attributes.
 | 
					    // Add any parameter attributes.
 | 
				
			||||||
@@ -1217,9 +1219,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
 | 
				
			|||||||
  Value *NV = NC;
 | 
					  Value *NV = NC;
 | 
				
			||||||
  if (OldRetTy != NV->getType() && !Caller->use_empty()) {
 | 
					  if (OldRetTy != NV->getType() && !Caller->use_empty()) {
 | 
				
			||||||
    if (!NV->getType()->isVoidTy()) {
 | 
					    if (!NV->getType()->isVoidTy()) {
 | 
				
			||||||
      Instruction::CastOps opcode =
 | 
					      NV = NC = CastInst::Create(CastInst::BitCast, NC, OldRetTy);
 | 
				
			||||||
        CastInst::getCastOpcode(NC, false, OldRetTy, false);
 | 
					 | 
				
			||||||
      NV = NC = CastInst::Create(opcode, NC, OldRetTy);
 | 
					 | 
				
			||||||
      NC->setDebugLoc(Caller->getDebugLoc());
 | 
					      NC->setDebugLoc(Caller->getDebugLoc());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // If this is an invoke instruction, we should insert it after the first
 | 
					      // If this is an invoke instruction, we should insert it after the first
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,9 +16,14 @@ define void @c(...) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define void @g(i32* %y) {
 | 
					define void @g(i32* %y) {
 | 
				
			||||||
 | 
					; CHECK-LABEL: @g(
 | 
				
			||||||
 | 
					; CHECK: call i64 bitcast (i32 (i32*)* @b to i64 (i32)*)(i32 0)
 | 
				
			||||||
 | 
						%x = call i64 bitcast (i32 (i32*)* @b to i64 (i32)*)( i32 0 )		; <i64> [#uses=0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; The rest should not have bitcasts remaining
 | 
				
			||||||
 | 
					; CHECK-NOT: bitcast
 | 
				
			||||||
  call void bitcast (void ()* @a to void (i32*)*)( i32* noalias  %y )
 | 
					  call void bitcast (void ()* @a to void (i32*)*)( i32* noalias  %y )
 | 
				
			||||||
  call <2 x i32> bitcast (i32 (i32*)* @b to <2 x i32> (i32*)*)( i32* inreg  null )		; <<2 x i32>>:1 [#uses=0]
 | 
					  call <2 x i32> bitcast (i32 (i32*)* @b to <2 x i32> (i32*)*)( i32* inreg  null )		; <<2 x i32>>:1 [#uses=0]
 | 
				
			||||||
	%x = call i64 bitcast (i32 (i32*)* @b to i64 (i32)*)( i32 0 )		; <i64> [#uses=0]
 | 
					 | 
				
			||||||
  call void bitcast (void (...)* @c to void (i32)*)( i32 0 )
 | 
					  call void bitcast (void (...)* @c to void (i32)*)( i32 0 )
 | 
				
			||||||
  call void bitcast (void (...)* @c to void (i32)*)( i32 zeroext  0 )
 | 
					  call void bitcast (void (...)* @c to void (i32)*)( i32 zeroext  0 )
 | 
				
			||||||
  ret void
 | 
					  ret void
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,8 +3,10 @@
 | 
				
			|||||||
define void @f(i16 %y) {
 | 
					define void @f(i16 %y) {
 | 
				
			||||||
  ret void
 | 
					  ret void
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
; CHECK-NOT: bitcast
 | 
					
 | 
				
			||||||
define i32 @g(i32 %y) {
 | 
					define i32 @g(i32 %y) {
 | 
				
			||||||
 | 
					; CHECK-LABEL: @g(
 | 
				
			||||||
 | 
					; CHECK: call i32 bitcast
 | 
				
			||||||
  %x = call i32 bitcast (void (i16)* @f to i32 (i32)*)( i32 %y )		; <i32> [#uses=1]
 | 
					  %x = call i32 bitcast (void (i16)* @f to i32 (i32)*)( i32 %y )		; <i32> [#uses=1]
 | 
				
			||||||
  ret i32 %x
 | 
					  ret i32 %x
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,16 +3,17 @@
 | 
				
			|||||||
target datalayout = "e-p:32:32"
 | 
					target datalayout = "e-p:32:32"
 | 
				
			||||||
target triple = "i686-pc-linux-gnu"
 | 
					target triple = "i686-pc-linux-gnu"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
; CHECK-NOT: bitcast
 | 
					 | 
				
			||||||
; CHECK: call
 | 
					 | 
				
			||||||
; CHECK-NOT: bitcast
 | 
					 | 
				
			||||||
define i32 @main() {
 | 
					define i32 @main() {
 | 
				
			||||||
 | 
					; CHECK-LABEL: @main(
 | 
				
			||||||
 | 
					; CHECK: call i32 bitcast
 | 
				
			||||||
entry:
 | 
					entry:
 | 
				
			||||||
	%tmp = call i32 bitcast (i7* (i999*)* @ctime to i32 (i99*)*)( i99* null )
 | 
						%tmp = call i32 bitcast (i7* (i999*)* @ctime to i32 (i99*)*)( i99* null )
 | 
				
			||||||
	ret i32 %tmp
 | 
						ret i32 %tmp
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define i7* @ctime(i999*) {
 | 
					define i7* @ctime(i999*) {
 | 
				
			||||||
 | 
					; CHECK-LABEL: @ctime(
 | 
				
			||||||
 | 
					; CHECK: call i7* bitcast
 | 
				
			||||||
entry:
 | 
					entry:
 | 
				
			||||||
	%tmp = call i7* bitcast (i32 ()* @main to i7* ()*)( )
 | 
						%tmp = call i7* bitcast (i32 ()* @main to i7* ()*)( )
 | 
				
			||||||
	ret i7* %tmp
 | 
						ret i7* %tmp
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										229
									
								
								test/Transforms/InstCombine/bitcast-alias-function.ll
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										229
									
								
								test/Transforms/InstCombine/bitcast-alias-function.ll
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,229 @@
 | 
				
			|||||||
 | 
					; RUN: opt -S -instcombine -o - %s | FileCheck %s
 | 
				
			||||||
 | 
					target datalayout = "e-p:32:32:32-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v64:64:64-v128:128:128-a0:0:64"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Cases that should be bitcast
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast between scalars with same bit sizes
 | 
				
			||||||
 | 
					@alias_i32_to_f32 = alias bitcast (i32 (i32)* @func_i32 to float (float)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast between vectors with same number of elements and bit sizes
 | 
				
			||||||
 | 
					@alias_v2i32_to_v2f32 = alias bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <2 x float> (<2 x float>)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast from vector to scalar with same number of bits
 | 
				
			||||||
 | 
					@alias_v2f32_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <2 x float> (<2 x float>)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast from scalar to vector with same number of bits
 | 
				
			||||||
 | 
					@alias_i64_to_v2f32 = alias bitcast (<2 x float> (<2 x float>)* @func_v2f32 to i64 (i64)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast between vectors of pointers
 | 
				
			||||||
 | 
					@alias_v2i32p_to_v2i64p = alias bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to <2 x i64*> (<2 x i64*>)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Cases that should be invalid and unchanged
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast between scalars with different bit sizes
 | 
				
			||||||
 | 
					@alias_i64_to_f32 = alias bitcast (i64 (i64)* @func_i64 to float (float)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast between vectors with different bit sizes but the
 | 
				
			||||||
 | 
					; same number of elements
 | 
				
			||||||
 | 
					@alias_v2i64_to_v2f32 = alias bitcast (<2 x i64> (<2 x i64>)* @func_v2i64 to <2 x float> (<2 x float>)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast between vectors with same number of bits and different
 | 
				
			||||||
 | 
					; numbers of elements
 | 
				
			||||||
 | 
					@alias_v2i32_to_v4f32 = alias bitcast (<2 x i32> (<2 x i32>)* @func_v2i32 to <4 x float> (<4 x float>)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast between scalar and vector with different number of bits
 | 
				
			||||||
 | 
					@alias_i64_to_v4f32 = alias bitcast (<4 x float> (<4 x float>)* @func_v4f32 to i64 (i64)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast between vector and scalar with different number of bits
 | 
				
			||||||
 | 
					@alias_v4f32_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <4 x float> (<4 x float>)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast from scalar to vector of pointers with same number of bits
 | 
				
			||||||
 | 
					; We don't know the pointer size at this point, so this can't be done
 | 
				
			||||||
 | 
					@alias_i64_to_v2i32p = alias bitcast (<2 x i32*> (<2 x i32*>)* @func_v2i32p to i64 (i64)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Test cast between vector of pointers and scalar with different number of bits
 | 
				
			||||||
 | 
					@alias_v4i32p_to_i64 = alias bitcast (i64 (i64)* @func_i64 to <4 x i32*> (<4 x i32*>)*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define internal <2 x i32> @func_v2i32(<2 x i32> %v) noinline nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					  ret <2 x i32> %v
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define internal <2 x float> @func_v2f32(<2 x float> %v) noinline nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					  ret <2 x float> %v
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define internal <4 x float> @func_v4f32(<4 x float> %v) noinline nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					  ret <4 x float> %v
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define internal i32 @func_i32(i32 %v) noinline nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					  ret i32 %v
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define internal i64 @func_i64(i64 %v) noinline nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					  ret i64 %v
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define internal <2 x i64> @func_v2i64(<2 x i64> %v) noinline nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					  ret <2 x i64> %v
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define internal <2 x i32*> @func_v2i32p(<2 x i32*> %v) noinline nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					  ret <2 x i32*> %v
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Valid cases, only bitcast for argument / return type and call underlying function
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Sizes match, should only bitcast
 | 
				
			||||||
 | 
					define void @bitcast_alias_scalar(float* noalias %source, float* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_scalar
 | 
				
			||||||
 | 
					; CHECK: bitcast float %tmp to i32
 | 
				
			||||||
 | 
					; CHECK-NOT: fptoui
 | 
				
			||||||
 | 
					; CHECK-NOT: uitofp
 | 
				
			||||||
 | 
					; CHECK: bitcast i32 %call to float
 | 
				
			||||||
 | 
					  %tmp = load float* %source, align 8
 | 
				
			||||||
 | 
					  %call = call float @alias_i32_to_f32(float %tmp) nounwind
 | 
				
			||||||
 | 
					  store float %call, float* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Sizes match, should only bitcast
 | 
				
			||||||
 | 
					define void @bitcast_alias_vector(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_vector
 | 
				
			||||||
 | 
					; CHECK: bitcast <2 x float> %tmp to <2 x i32>
 | 
				
			||||||
 | 
					; CHECK-NOT: fptoui
 | 
				
			||||||
 | 
					; CHECK-NOT: uitofp
 | 
				
			||||||
 | 
					; CHECK: bitcast <2 x i32> %call to <2 x float>
 | 
				
			||||||
 | 
					  %tmp = load <2 x float>* %source, align 8
 | 
				
			||||||
 | 
					  %call = call <2 x float> @alias_v2i32_to_v2f32(<2 x float> %tmp) nounwind
 | 
				
			||||||
 | 
					  store <2 x float> %call, <2 x float>* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Sizes match, should only bitcast
 | 
				
			||||||
 | 
					define void @bitcast_alias_vector_scalar_same_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_vector_scalar_same_size
 | 
				
			||||||
 | 
					; CHECK: bitcast <2 x float> %tmp to i64
 | 
				
			||||||
 | 
					; CHECK: %call = call i64 @func_i64
 | 
				
			||||||
 | 
					; CHECK: bitcast i64 %call to <2 x float>
 | 
				
			||||||
 | 
					  %tmp = load <2 x float>* %source, align 8
 | 
				
			||||||
 | 
					  %call = call <2 x float> @alias_v2f32_to_i64(<2 x float> %tmp) nounwind
 | 
				
			||||||
 | 
					  store <2 x float> %call, <2 x float>* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @bitcast_alias_scalar_vector_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_scalar_vector_same_size
 | 
				
			||||||
 | 
					; CHECK: bitcast i64 %tmp to <2 x float>
 | 
				
			||||||
 | 
					; CHECK: call <2 x float> @func_v2f32
 | 
				
			||||||
 | 
					; CHECK: bitcast <2 x float> %call to i64
 | 
				
			||||||
 | 
					  %tmp = load i64* %source, align 8
 | 
				
			||||||
 | 
					  %call = call i64 @alias_i64_to_v2f32(i64 %tmp) nounwind
 | 
				
			||||||
 | 
					  store i64 %call, i64* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @bitcast_alias_vector_ptrs_same_size(<2 x i64*>* noalias %source, <2 x i64*>* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_vector_ptrs_same_size
 | 
				
			||||||
 | 
					; CHECK: bitcast <2 x i64*> %tmp to <2 x i32*>
 | 
				
			||||||
 | 
					; CHECK: call <2 x i32*> @func_v2i32p
 | 
				
			||||||
 | 
					; CHECK: bitcast <2 x i32*> %call to <2 x i64*>
 | 
				
			||||||
 | 
					  %tmp = load <2 x i64*>* %source, align 8
 | 
				
			||||||
 | 
					  %call = call <2 x i64*> @alias_v2i32p_to_v2i64p(<2 x i64*> %tmp) nounwind
 | 
				
			||||||
 | 
					  store <2 x i64*> %call, <2 x i64*>* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					; Invalid cases:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @bitcast_alias_mismatch_scalar_size(float* noalias %source, float* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_mismatch_scalar_size
 | 
				
			||||||
 | 
					; CHECK-NOT: fptoui
 | 
				
			||||||
 | 
					; CHECK: @alias_i64_to_f32
 | 
				
			||||||
 | 
					; CHECK-NOT: uitofp
 | 
				
			||||||
 | 
					  %tmp = load float* %source, align 8
 | 
				
			||||||
 | 
					  %call = call float @alias_i64_to_f32(float %tmp) nounwind
 | 
				
			||||||
 | 
					  store float %call, float* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @bitcast_alias_mismatch_vector_element_and_bit_size(<2 x float>* noalias %source, <2 x float>* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_mismatch_vector_element_and_bit_size
 | 
				
			||||||
 | 
					; CHECK-NOT: fptoui <2 x float> %tmp to <2 x i64>
 | 
				
			||||||
 | 
					; CHECK: @alias_v2i64_to_v2f32
 | 
				
			||||||
 | 
					; CHECK-NOT: uitofp <2 x i64> %call to <2 x float>
 | 
				
			||||||
 | 
					  %tmp = load <2 x float>* %source, align 8
 | 
				
			||||||
 | 
					  %call = call <2 x float> @alias_v2i64_to_v2f32(<2 x float> %tmp) nounwind
 | 
				
			||||||
 | 
					  store <2 x float> %call, <2 x float>* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @bitcast_alias_vector_mismatched_number_elements(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_vector_mismatched_number_elements
 | 
				
			||||||
 | 
					; CHECK:  %call = call <4 x float> @alias_v2i32_to_v4f32
 | 
				
			||||||
 | 
					  %tmp = load <4 x float>* %source, align 8
 | 
				
			||||||
 | 
					  %call = call <4 x float> @alias_v2i32_to_v4f32(<4 x float> %tmp) nounwind
 | 
				
			||||||
 | 
					  store <4 x float> %call, <4 x float>* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @bitcast_alias_vector_scalar_mismatched_bit_size(<4 x float>* noalias %source, <4 x float>* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_vector_scalar_mismatched_bit_size
 | 
				
			||||||
 | 
					; CHECK:  %call = call <4 x float> @alias_v4f32_to_i64
 | 
				
			||||||
 | 
					  %tmp = load <4 x float>* %source, align 8
 | 
				
			||||||
 | 
					  %call = call <4 x float> @alias_v4f32_to_i64(<4 x float> %tmp) nounwind
 | 
				
			||||||
 | 
					  store <4 x float> %call, <4 x float>* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size(<4 x i32*>* noalias %source, <4 x i32*>* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_vector_ptrs_scalar_mismatched_bit_size
 | 
				
			||||||
 | 
					; CHECK: @alias_v4i32p_to_i64
 | 
				
			||||||
 | 
					  %tmp = load <4 x i32*>* %source, align 8
 | 
				
			||||||
 | 
					  %call = call <4 x i32*> @alias_v4i32p_to_i64(<4 x i32*> %tmp) nounwind
 | 
				
			||||||
 | 
					  store <4 x i32*> %call, <4 x i32*>* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @bitcast_alias_scalar_vector_ptrs_same_size(i64* noalias %source, i64* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_scalar_vector_ptrs_same_size
 | 
				
			||||||
 | 
					; CHECK: @alias_i64_to_v2i32p
 | 
				
			||||||
 | 
					  %tmp = load i64* %source, align 8
 | 
				
			||||||
 | 
					  %call = call i64 @alias_i64_to_v2i32p(i64 %tmp) nounwind
 | 
				
			||||||
 | 
					  store i64 %call, i64* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					define void @bitcast_alias_scalar_vector_mismatched_bit_size(i64* noalias %source, i64* noalias %dest) nounwind {
 | 
				
			||||||
 | 
					entry:
 | 
				
			||||||
 | 
					; CHECK-LABEL: @bitcast_alias_scalar_vector_mismatched_bit_size
 | 
				
			||||||
 | 
					; CHECK: call i64 @alias_i64_to_v4f32
 | 
				
			||||||
 | 
					  %tmp = load i64* %source, align 8
 | 
				
			||||||
 | 
					  %call = call i64 @alias_i64_to_v4f32(i64 %tmp) nounwind
 | 
				
			||||||
 | 
					  store i64 %call, i64* %dest, align 8
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -3,11 +3,9 @@
 | 
				
			|||||||
target datalayout = "e-p:32:32"
 | 
					target datalayout = "e-p:32:32"
 | 
				
			||||||
target triple = "i686-pc-linux-gnu"
 | 
					target triple = "i686-pc-linux-gnu"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
; CHECK-NOT: bitcast
 | 
					 | 
				
			||||||
; CHECK: call
 | 
					 | 
				
			||||||
; CHECK-NOT: bitcast
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
define i32 @main() {
 | 
					define i32 @main() {
 | 
				
			||||||
 | 
					; CHECK-LABEL: @main
 | 
				
			||||||
 | 
					; CHECK: call i32 bitcast
 | 
				
			||||||
entry:
 | 
					entry:
 | 
				
			||||||
  %tmp = call i32 bitcast (i8* (i32*)* @ctime to i32 (i32*)*)( i32* null )          ; <i32> [#uses=1]
 | 
					  %tmp = call i32 bitcast (i8* (i32*)* @ctime to i32 (i32*)*)( i32* null )          ; <i32> [#uses=1]
 | 
				
			||||||
  ret i32 %tmp
 | 
					  ret i32 %tmp
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,26 +7,28 @@ target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:1
 | 
				
			|||||||
declare void @test1a(i8*)
 | 
					declare void @test1a(i8*)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define void @test1(i32* %A) {
 | 
					define void @test1(i32* %A) {
 | 
				
			||||||
        call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
 | 
					; CHECK-LABEL: @test1(
 | 
				
			||||||
        ret void
 | 
					 | 
				
			||||||
; CHECK: %1 = bitcast i32* %A to i8*
 | 
					; CHECK: %1 = bitcast i32* %A to i8*
 | 
				
			||||||
; CHECK: call void @test1a(i8* %1)
 | 
					; CHECK: call void @test1a(i8* %1)
 | 
				
			||||||
; CHECK: ret void
 | 
					; CHECK: ret void
 | 
				
			||||||
 | 
					  call void bitcast (void (i8*)* @test1a to void (i32*)*)( i32* %A )
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
; More complex case, translate argument because of resolution.  This is safe
 | 
					; More complex case, translate argument because of resolution.  This is safe
 | 
				
			||||||
; because we have the body of the function
 | 
					; because we have the body of the function
 | 
				
			||||||
define void @test2a(i8 %A) {
 | 
					define void @test2a(i8 %A) {
 | 
				
			||||||
        ret void
 | 
					; CHECK-LABEL: @test2a(
 | 
				
			||||||
; CHECK: ret void
 | 
					; CHECK: ret void
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define i32 @test2(i32 %A) {
 | 
					define i32 @test2(i32 %A) {
 | 
				
			||||||
 | 
					; CHECK-LABEL: @test2(
 | 
				
			||||||
 | 
					; CHECK: call void bitcast
 | 
				
			||||||
 | 
					; CHECK: ret i32 %A
 | 
				
			||||||
  call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
 | 
					  call void bitcast (void (i8)* @test2a to void (i32)*)( i32 %A )
 | 
				
			||||||
  ret i32 %A
 | 
					  ret i32 %A
 | 
				
			||||||
; CHECK: %1 = trunc i32 %A to i8
 | 
					 | 
				
			||||||
; CHECK: call void @test2a(i8 %1)
 | 
					 | 
				
			||||||
; CHECK: ret i32 %A
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -35,64 +37,64 @@ define i32 @test2(i32 %A) {
 | 
				
			|||||||
define void @test3a(i8, ...) {unreachable }
 | 
					define void @test3a(i8, ...) {unreachable }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define void @test3(i8 %A, i8 %B) {
 | 
					define void @test3(i8 %A, i8 %B) {
 | 
				
			||||||
        call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B 
 | 
					; CHECK-LABEL: @test3(
 | 
				
			||||||
)
 | 
					 | 
				
			||||||
        ret void
 | 
					 | 
				
			||||||
; CHECK: %1 = zext i8 %B to i32
 | 
					; CHECK: %1 = zext i8 %B to i32
 | 
				
			||||||
; CHECK: call void (i8, ...)* @test3a(i8 %A, i32 %1)
 | 
					; CHECK: call void (i8, ...)* @test3a(i8 %A, i32 %1)
 | 
				
			||||||
; CHECK: ret void
 | 
					; CHECK: ret void
 | 
				
			||||||
 | 
					  call void bitcast (void (i8, ...)* @test3a to void (i8, i8)*)( i8 %A, i8 %B)
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
; test conversion of return value...
 | 
					; test conversion of return value...
 | 
				
			||||||
define i8 @test4a() {
 | 
					define i8 @test4a() {
 | 
				
			||||||
        ret i8 0
 | 
					; CHECK-LABEL: @test4a(
 | 
				
			||||||
; CHECK: ret i8 0
 | 
					; CHECK: ret i8 0
 | 
				
			||||||
 | 
					  ret i8 0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define i32 @test4() {
 | 
					define i32 @test4() {
 | 
				
			||||||
 | 
					; CHECK-LABEL: @test4(
 | 
				
			||||||
 | 
					; CHECK: call i32 bitcast
 | 
				
			||||||
  %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( )            ; <i32> [#uses=1]
 | 
					  %X = call i32 bitcast (i8 ()* @test4a to i32 ()*)( )            ; <i32> [#uses=1]
 | 
				
			||||||
  ret i32 %X
 | 
					  ret i32 %X
 | 
				
			||||||
; CHECK: %X = call i8 @test4a()
 | 
					 | 
				
			||||||
; CHECK: %1 = zext i8 %X to i32
 | 
					 | 
				
			||||||
; CHECK: ret i32 %1
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
; test conversion of return value... no value conversion occurs so we can do
 | 
					; test conversion of return value... no value conversion occurs so we can do
 | 
				
			||||||
; this with just a prototype...
 | 
					; this with just a prototype...
 | 
				
			||||||
declare i32 @test5a()
 | 
					declare i32 @test5a()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define i32 @test5() {
 | 
					define i32 @test5() {
 | 
				
			||||||
        %X = call i32 @test5a( )                ; <i32> [#uses=1]
 | 
					; CHECK-LABEL: @test5(
 | 
				
			||||||
        ret i32 %X
 | 
					 | 
				
			||||||
; CHECK: %X = call i32 @test5a()
 | 
					; CHECK: %X = call i32 @test5a()
 | 
				
			||||||
; CHECK: ret i32 %X
 | 
					; CHECK: ret i32 %X
 | 
				
			||||||
 | 
					  %X = call i32 @test5a( )                ; <i32> [#uses=1]
 | 
				
			||||||
 | 
					  ret i32 %X
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
; test addition of new arguments...
 | 
					; test addition of new arguments...
 | 
				
			||||||
declare i32 @test6a(i32)
 | 
					declare i32 @test6a(i32)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define i32 @test6() {
 | 
					define i32 @test6() {
 | 
				
			||||||
        %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
 | 
					; CHECK-LABEL: @test6(
 | 
				
			||||||
        ret i32 %X
 | 
					 | 
				
			||||||
; CHECK: %X = call i32 @test6a(i32 0)
 | 
					; CHECK: %X = call i32 @test6a(i32 0)
 | 
				
			||||||
; CHECK: ret i32 %X
 | 
					; CHECK: ret i32 %X
 | 
				
			||||||
 | 
					  %X = call i32 bitcast (i32 (i32)* @test6a to i32 ()*)( )
 | 
				
			||||||
 | 
					  ret i32 %X
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
; test removal of arguments, only can happen with a function body
 | 
					; test removal of arguments, only can happen with a function body
 | 
				
			||||||
define void @test7a() {
 | 
					define void @test7a() {
 | 
				
			||||||
        ret void
 | 
					; CHECK-LABEL: @test7a(
 | 
				
			||||||
; CHECK: ret void
 | 
					; CHECK: ret void
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define void @test7() {
 | 
					define void @test7() {
 | 
				
			||||||
        call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
 | 
					; CHECK-LABEL: @test7(
 | 
				
			||||||
        ret void
 | 
					 | 
				
			||||||
; CHECK: call void @test7a()
 | 
					; CHECK: call void @test7a()
 | 
				
			||||||
; CHECK: ret void
 | 
					; CHECK: ret void
 | 
				
			||||||
 | 
					  call void bitcast (void ()* @test7a to void (i32)*)( i32 5 )
 | 
				
			||||||
 | 
					  ret void
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -100,6 +102,11 @@ define void @test7() {
 | 
				
			|||||||
declare void @test8a()
 | 
					declare void @test8a()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
define i8* @test8() {
 | 
					define i8* @test8() {
 | 
				
			||||||
 | 
					; CHECK-LABEL: @test8(
 | 
				
			||||||
 | 
					; CHECK-NEXT: invoke void @test8a()
 | 
				
			||||||
 | 
					; Don't turn this into "unreachable": the callee and caller don't agree in
 | 
				
			||||||
 | 
					; calling conv, but the implementation of test8a may actually end up using the
 | 
				
			||||||
 | 
					; right calling conv.
 | 
				
			||||||
  invoke void @test8a()
 | 
					  invoke void @test8a()
 | 
				
			||||||
          to label %invoke.cont unwind label %try.handler
 | 
					          to label %invoke.cont unwind label %try.handler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -114,19 +121,13 @@ try.handler:                                      ; preds = %entry
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
declare i32 @__gxx_personality_v0(...)
 | 
					declare i32 @__gxx_personality_v0(...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
; Don't turn this into "unreachable": the callee and caller don't agree in
 | 
					 | 
				
			||||||
; calling conv, but the implementation of test8a may actually end up using the
 | 
					 | 
				
			||||||
; right calling conv.
 | 
					 | 
				
			||||||
; CHECK: @test8() {
 | 
					 | 
				
			||||||
; CHECK-NEXT: invoke void @test8a()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
; Don't turn this into a direct call, because test9x is just a prototype and
 | 
					; Don't turn this into a direct call, because test9x is just a prototype and
 | 
				
			||||||
; doing so will make it varargs.
 | 
					; doing so will make it varargs.
 | 
				
			||||||
; rdar://9038601
 | 
					; rdar://9038601
 | 
				
			||||||
declare i8* @test9x(i8*, i8*, ...) noredzone
 | 
					declare i8* @test9x(i8*, i8*, ...) noredzone
 | 
				
			||||||
define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
 | 
					define i8* @test9(i8* %arg, i8* %tmp3) nounwind ssp noredzone {
 | 
				
			||||||
 | 
					; CHECK-LABEL: @test9
 | 
				
			||||||
entry:
 | 
					entry:
 | 
				
			||||||
  %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
 | 
					  %call = call i8* bitcast (i8* (i8*, i8*, ...)* @test9x to i8* (i8*, i8*)*)(i8* %arg, i8* %tmp3) noredzone
 | 
				
			||||||
  ret i8* %call
 | 
					  ret i8* %call
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -117,11 +117,35 @@ TEST(InstructionsTest, CastInst) {
 | 
				
			|||||||
  LLVMContext &C(getGlobalContext());
 | 
					  LLVMContext &C(getGlobalContext());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Type *Int8Ty = Type::getInt8Ty(C);
 | 
					  Type *Int8Ty = Type::getInt8Ty(C);
 | 
				
			||||||
 | 
					  Type *Int16Ty = Type::getInt16Ty(C);
 | 
				
			||||||
 | 
					  Type *Int32Ty = Type::getInt32Ty(C);
 | 
				
			||||||
  Type *Int64Ty = Type::getInt64Ty(C);
 | 
					  Type *Int64Ty = Type::getInt64Ty(C);
 | 
				
			||||||
  Type *V8x8Ty = VectorType::get(Int8Ty, 8);
 | 
					  Type *V8x8Ty = VectorType::get(Int8Ty, 8);
 | 
				
			||||||
  Type *V8x64Ty = VectorType::get(Int64Ty, 8);
 | 
					  Type *V8x64Ty = VectorType::get(Int64Ty, 8);
 | 
				
			||||||
  Type *X86MMXTy = Type::getX86_MMXTy(C);
 | 
					  Type *X86MMXTy = Type::getX86_MMXTy(C);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Type *HalfTy = Type::getHalfTy(C);
 | 
				
			||||||
 | 
					  Type *FloatTy = Type::getFloatTy(C);
 | 
				
			||||||
 | 
					  Type *DoubleTy = Type::getDoubleTy(C);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Type *V2Int32Ty = VectorType::get(Int32Ty, 2);
 | 
				
			||||||
 | 
					  Type *V2Int64Ty = VectorType::get(Int64Ty, 2);
 | 
				
			||||||
 | 
					  Type *V4Int16Ty = VectorType::get(Int16Ty, 4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Type *Int32PtrTy = PointerType::get(Int32Ty, 0);
 | 
				
			||||||
 | 
					  Type *Int64PtrTy = PointerType::get(Int64Ty, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Type *Int32PtrAS1Ty = PointerType::get(Int32Ty, 1);
 | 
				
			||||||
 | 
					  Type *Int64PtrAS1Ty = PointerType::get(Int64Ty, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Type *V2Int32PtrAS1Ty = VectorType::get(Int32PtrAS1Ty, 2);
 | 
				
			||||||
 | 
					  Type *V2Int64PtrAS1Ty = VectorType::get(Int64PtrAS1Ty, 2);
 | 
				
			||||||
 | 
					  Type *V4Int32PtrAS1Ty = VectorType::get(Int32PtrAS1Ty, 4);
 | 
				
			||||||
 | 
					  Type *V4Int64PtrAS1Ty = VectorType::get(Int64PtrAS1Ty, 4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Type *V2Int64PtrTy = VectorType::get(Int64PtrTy, 2);
 | 
				
			||||||
 | 
					  Type *V2Int32PtrTy = VectorType::get(Int32PtrTy, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const Constant* c8 = Constant::getNullValue(V8x8Ty);
 | 
					  const Constant* c8 = Constant::getNullValue(V8x8Ty);
 | 
				
			||||||
  const Constant* c64 = Constant::getNullValue(V8x64Ty);
 | 
					  const Constant* c64 = Constant::getNullValue(V8x64Ty);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -132,10 +156,49 @@ TEST(InstructionsTest, CastInst) {
 | 
				
			|||||||
  EXPECT_TRUE(CastInst::isCastable(V8x8Ty, V8x64Ty));
 | 
					  EXPECT_TRUE(CastInst::isCastable(V8x8Ty, V8x64Ty));
 | 
				
			||||||
  EXPECT_EQ(CastInst::Trunc, CastInst::getCastOpcode(c64, true, V8x8Ty, true));
 | 
					  EXPECT_EQ(CastInst::Trunc, CastInst::getCastOpcode(c64, true, V8x8Ty, true));
 | 
				
			||||||
  EXPECT_EQ(CastInst::SExt, CastInst::getCastOpcode(c8, true, V8x64Ty, true));
 | 
					  EXPECT_EQ(CastInst::SExt, CastInst::getCastOpcode(c8, true, V8x64Ty, true));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V8x8Ty, X86MMXTy));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(X86MMXTy, V8x8Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(Int64Ty, X86MMXTy));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V8x64Ty, V8x8Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V8x8Ty, V8x64Ty));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Check address space casts are rejected since we don't know the sizes here
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(Int32PtrTy, Int32PtrAS1Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(Int32PtrAS1Ty, Int32PtrTy));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V2Int32PtrTy, V2Int32PtrAS1Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V2Int32PtrAS1Ty, V2Int32PtrTy));
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(V2Int32PtrAS1Ty, V2Int64PtrAS1Ty));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Test mismatched number of elements for pointers
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V2Int32PtrAS1Ty, V4Int64PtrAS1Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V4Int64PtrAS1Ty, V2Int32PtrAS1Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V2Int32PtrAS1Ty, V4Int32PtrAS1Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(Int32PtrTy, V2Int32PtrTy));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V2Int32PtrTy, Int32PtrTy));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(Int32PtrTy, Int64PtrTy));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(DoubleTy, FloatTy));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(FloatTy, DoubleTy));
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(FloatTy, FloatTy));
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(FloatTy, FloatTy));
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(FloatTy, Int32Ty));
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(Int16Ty, HalfTy));
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(Int32Ty, FloatTy));
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(V2Int32Ty, Int64Ty));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(V2Int32Ty, V4Int16Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(Int32Ty, Int64Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(Int64Ty, Int32Ty));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V2Int32PtrTy, Int64Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(Int64Ty, V2Int32PtrTy));
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(V2Int64PtrTy, V2Int32PtrTy));
 | 
				
			||||||
 | 
					  EXPECT_TRUE(CastInst::isBitCastable(V2Int32PtrTy, V2Int64PtrTy));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V2Int32Ty, V2Int64Ty));
 | 
				
			||||||
 | 
					  EXPECT_FALSE(CastInst::isBitCastable(V2Int64Ty, V2Int32Ty));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TEST(InstructionsTest, VectorGep) {
 | 
					TEST(InstructionsTest, VectorGep) {
 | 
				
			||||||
  LLVMContext &C(getGlobalContext());
 | 
					  LLVMContext &C(getGlobalContext());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user