summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanya Lattner <tonic@nondot.org>2009-10-01 15:12:41 +0000
committerTanya Lattner <tonic@nondot.org>2009-10-01 15:12:41 +0000
commit43012b0b19ff6f58118b7d18d7833788808f3146 (patch)
tree3523c28da48b7d832b07c020425aab2eea91b845
parentMerge in fix for PR4910. (diff)
downloadllvm-project-43012b0b19ff6f58118b7d18d7833788808f3146.tar.gz
llvm-project-43012b0b19ff6f58118b7d18d7833788808f3146.tar.bz2
llvm-project-43012b0b19ff6f58118b7d18d7833788808f3146.zip
Merge from mainline (reg).
Don't constant propagate byval pointers, since they are not really pointers, but rather structs passed by value. This fixes PR5038. llvm-svn: 83200
-rw-r--r--llvm/lib/Transforms/IPO/IPConstantPropagation.cpp3
-rw-r--r--llvm/lib/Transforms/Scalar/SCCP.cpp4
-rw-r--r--llvm/test/Transforms/IPConstantProp/2009-09-24-byval-ptr.ll24
3 files changed, 30 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
index bb2448610f28..95c3f4e35485 100644
--- a/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
+++ b/llvm/lib/Transforms/IPO/IPConstantPropagation.cpp
@@ -130,7 +130,8 @@ bool IPCP::PropagateConstantsIntoArguments(Function &F) {
Function::arg_iterator AI = F.arg_begin();
for (unsigned i = 0, e = ArgumentConstants.size(); i != e; ++i, ++AI) {
// Do we have a constant argument?
- if (ArgumentConstants[i].second || AI->use_empty())
+ if (ArgumentConstants[i].second || AI->use_empty() ||
+ (AI->hasByValAttr() && isa<PointerType>(AI->getType())))
continue;
Value *V = ArgumentConstants[i].first;
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index 4a9675aa02da..5b948e3b22f3 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -1263,6 +1263,10 @@ CallOverdefined:
for (Function::arg_iterator AI = F->arg_begin(), E = F->arg_end();
AI != E; ++AI, ++CAI) {
LatticeVal &IV = ValueState[AI];
+ if (AI->hasByValAttr() && isa<PointerType>(AI->getType())) {
+ IV.markOverdefined();
+ continue;
+ }
if (!IV.isOverdefined())
mergeInValue(IV, AI, getValueState(*CAI));
}
diff --git a/llvm/test/Transforms/IPConstantProp/2009-09-24-byval-ptr.ll b/llvm/test/Transforms/IPConstantProp/2009-09-24-byval-ptr.ll
new file mode 100644
index 000000000000..75055d41a648
--- /dev/null
+++ b/llvm/test/Transforms/IPConstantProp/2009-09-24-byval-ptr.ll
@@ -0,0 +1,24 @@
+; RUN: llvm-as <%s | opt -ipsccp | llvm-dis | FileCheck %s
+; Don't constant-propagate byval pointers, since they are not pointers!
+; PR5038
+%struct.MYstr = type { i8, i32 }
+@mystr = internal global %struct.MYstr zeroinitializer ; <%struct.MYstr*> [#uses=3]
+define internal void @vfu1(%struct.MYstr* byval align 4 %u) nounwind {
+entry:
+ %0 = getelementptr %struct.MYstr* %u, i32 0, i32 1 ; <i32*> [#uses=1]
+ store i32 99, i32* %0, align 4
+; CHECK: %struct.MYstr* %u
+ %1 = getelementptr %struct.MYstr* %u, i32 0, i32 0 ; <i8*> [#uses=1]
+ store i8 97, i8* %1, align 4
+; CHECK: %struct.MYstr* %u
+ br label %return
+
+return: ; preds = %entry
+ ret void
+}
+define void @unions() nounwind {
+entry:
+ call void @vfu1(%struct.MYstr* byval align 4 @mystr) nounwind
+ ret void
+}
+