llvm.org GIT mirror llvm / e1e520f
When turning a call to a bitcast function into a direct call, if this becomes a varargs call then deal correctly with any parameter attributes on the newly vararg call arguments. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45931 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan Sands 11 years ago
3 changed file(s) with 34 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
81418141 return false; // Cannot transform this return value.
81428142
81438143 if (!Caller->use_empty() &&
8144 !CastInst::isCastable(FT->getReturnType(), OldRetTy) &&
81458144 // void -> non-void is handled specially
8146 FT->getReturnType() != Type::VoidTy)
8145 FT->getReturnType() != Type::VoidTy &&
8146 !CastInst::isCastable(FT->getReturnType(), OldRetTy))
81478147 return false; // Cannot transform this return value.
81488148
81498149 if (CallerPAL && !Caller->use_empty()) {
81998199 Callee->isDeclaration())
82008200 return false; // Do not delete arguments unless we have a function body...
82018201
8202 if (FT->getNumParams() < NumActualArgs && FT->isVarArg())
8202 if (FT->getNumParams() < NumActualArgs && FT->isVarArg() && CallerPAL)
82038203 // In this case we have more arguments than the new function type, but we
8204 // won't be dropping them. Some of them may have attributes. If so, we
8205 // cannot perform the transform because attributes are not allowed after
8206 // the end of the function type.
8207 if (CallerPAL && CallerPAL->size() &&
8208 CallerPAL->getParamIndex(CallerPAL->size()-1) > FT->getNumParams())
8209 return false;
8204 // won't be dropping them. Check that these extra arguments have attributes
8205 // that are compatible with being a vararg call argument.
8206 for (unsigned i = CallerPAL->size(); i; --i) {
8207 if (CallerPAL->getParamIndex(i - 1) <= FT->getNumParams())
8208 break;
8209 uint16_t PAttrs = CallerPAL->getParamAttrsAtIndex(i - 1);
8210 if (PAttrs & ParamAttr::VarArgsIncompatible)
8211 return false;
8212 }
82108213
82118214 // Okay, we decided that this is a safe thing to do: go ahead and start
82128215 // inserting cast instructions as necessary...
82688271 } else {
82698272 Args.push_back(*AI);
82708273 }
8271 }
8272
8273 // No need to add parameter attributes - we already checked that there
8274 // aren't any.
8274
8275 // Add any parameter attributes.
8276 uint16_t PAttrs = CallerPAL ? CallerPAL->getParamAttrs(i + 1) : 0;
8277 if (PAttrs)
8278 attrVec.push_back(ParamAttrsWithIndex::get(i + 1, PAttrs));
8279 }
82758280 }
82768281
82778282 if (FT->getReturnType() == Type::VoidTy)
None ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep bitcast | count 2
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep bitcast
11
22 define void @a() {
33 ret void
1616 call <2 x i32> bitcast (i32 (i32*)* @b to <2 x i32> (i32*)*)( i32* inreg null ) ; <<2 x i32>>:1 [#uses=0]
1717 %x = call i64 bitcast (i32 (i32*)* @b to i64 (i32)*)( i32 0 ) ; [#uses=0]
1818 call void bitcast (void (...)* @c to void (i32)*)( i32 0 )
19 call i32 bitcast (i32 (i32*)* @b to i32 (i32)*)( i32 zeroext 0 ) ; :2 [#uses=0]
2019 call void bitcast (void (...)* @c to void (i32)*)( i32 zeroext 0 )
2120 ret void
2221 }
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep bitcast | count 2
1
2 define i32 @b(i32* inreg %x) signext {
3 ret i32 0
4 }
5
6 define void @c(...) {
7 ret void
8 }
9
10 define void @g(i32* %y) {
11 call i32 bitcast (i32 (i32*)* @b to i32 (i32)*)( i32 zeroext 0 ) ; :2 [#uses=0]
12 call void bitcast (void (...)* @c to void (i32*)*)( i32* sret null )
13 ret void
14 }