summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2008-01-13 08:02:44 +0000
committerDuncan Sands <baldrick@free.fr>2008-01-13 08:02:44 +0000
commite1e520f601f3b0186eab1bdf7df4a54d0c640a3e (patch)
tree91873cba8ed43802bda1910d539f40a19fb1d1b8
parent4db8f85c75c0eba5a9fe7981f4b9abe2be275899 (diff)
downloadllvm-e1e520f601f3b0186eab1bdf7df4a54d0c640a3e.tar.gz
llvm-e1e520f601f3b0186eab1bdf7df4a54d0c640a3e.tar.bz2
llvm-e1e520f601f3b0186eab1bdf7df4a54d0c640a3e.tar.xz
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
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp29
-rw-r--r--test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll3
-rw-r--r--test/Transforms/InstCombine/2008-01-13-NoBitCastAttributes.ll15
3 files changed, 33 insertions, 14 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 93fad0a1fa..ea53aec76c 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -8142,9 +8142,9 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
return false; // Cannot transform this return value.
if (!Caller->use_empty() &&
- !CastInst::isCastable(FT->getReturnType(), OldRetTy) &&
// void -> non-void is handled specially
- FT->getReturnType() != Type::VoidTy)
+ FT->getReturnType() != Type::VoidTy &&
+ !CastInst::isCastable(FT->getReturnType(), OldRetTy))
return false; // Cannot transform this return value.
if (CallerPAL && !Caller->use_empty()) {
@@ -8200,14 +8200,17 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
Callee->isDeclaration())
return false; // Do not delete arguments unless we have a function body...
- if (FT->getNumParams() < NumActualArgs && FT->isVarArg())
+ if (FT->getNumParams() < NumActualArgs && FT->isVarArg() && CallerPAL)
// In this case we have more arguments than the new function type, but we
- // won't be dropping them. Some of them may have attributes. If so, we
- // cannot perform the transform because attributes are not allowed after
- // the end of the function type.
- if (CallerPAL && CallerPAL->size() &&
- CallerPAL->getParamIndex(CallerPAL->size()-1) > FT->getNumParams())
- return false;
+ // won't be dropping them. Check that these extra arguments have attributes
+ // that are compatible with being a vararg call argument.
+ for (unsigned i = CallerPAL->size(); i; --i) {
+ if (CallerPAL->getParamIndex(i - 1) <= FT->getNumParams())
+ break;
+ uint16_t PAttrs = CallerPAL->getParamAttrsAtIndex(i - 1);
+ if (PAttrs & ParamAttr::VarArgsIncompatible)
+ return false;
+ }
// Okay, we decided that this is a safe thing to do: go ahead and start
// inserting cast instructions as necessary...
@@ -8269,10 +8272,12 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
} else {
Args.push_back(*AI);
}
- }
- // No need to add parameter attributes - we already checked that there
- // aren't any.
+ // Add any parameter attributes.
+ uint16_t PAttrs = CallerPAL ? CallerPAL->getParamAttrs(i + 1) : 0;
+ if (PAttrs)
+ attrVec.push_back(ParamAttrsWithIndex::get(i + 1, PAttrs));
+ }
}
if (FT->getReturnType() == Type::VoidTy)
diff --git a/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll b/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll
index 5bb8875961..99c34907c0 100644
--- a/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll
+++ b/test/Transforms/InstCombine/2008-01-06-BitCastAttributes.ll
@@ -1,4 +1,4 @@
-; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep bitcast | count 2
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep bitcast
define void @a() {
ret void
@@ -17,7 +17,6 @@ define void @g(i32* %y) {
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 i32 bitcast (i32 (i32*)* @b to i32 (i32)*)( i32 zeroext 0 ) ; <i32>:2 [#uses=0]
call void bitcast (void (...)* @c to void (i32)*)( i32 zeroext 0 )
ret void
}
diff --git a/test/Transforms/InstCombine/2008-01-13-NoBitCastAttributes.ll b/test/Transforms/InstCombine/2008-01-13-NoBitCastAttributes.ll
new file mode 100644
index 0000000000..d791d7be26
--- /dev/null
+++ b/test/Transforms/InstCombine/2008-01-13-NoBitCastAttributes.ll
@@ -0,0 +1,15 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep bitcast | count 2
+
+define i32 @b(i32* inreg %x) signext {
+ ret i32 0
+}
+
+define void @c(...) {
+ ret void
+}
+
+define void @g(i32* %y) {
+ call i32 bitcast (i32 (i32*)* @b to i32 (i32)*)( i32 zeroext 0 ) ; <i32>:2 [#uses=0]
+ call void bitcast (void (...)* @c to void (i32*)*)( i32* sret null )
+ ret void
+}