aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2008-06-17 12:20:24 +0000
committerMatthijs Kooijman <matthijs@stdin.nl>2008-06-17 12:20:24 +0000
commitbfb4e84913551f92dccd3b725b66f2ba9bd81f47 (patch)
treeb7d728f7e4f2eb9a840e088c076b459be91e594a
parentb951a957dcb24c4ec671d7f4a99751b9a9f66c94 (diff)
downloadexternal_llvm-bfb4e84913551f92dccd3b725b66f2ba9bd81f47.zip
external_llvm-bfb4e84913551f92dccd3b725b66f2ba9bd81f47.tar.gz
external_llvm-bfb4e84913551f92dccd3b725b66f2ba9bd81f47.tar.bz2
Learn IPConstProp to propagate arguments that are directly returned. Strictly
speaking these are not constant values. However, when a function always returns one of its arguments, then from the point of view of each caller the return value is constant (or at least a known value) and can be replaced. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52397 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/IPConstantPropagation.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp
index 0e654a5..54127f6 100644
--- a/lib/Transforms/IPO/IPConstantPropagation.cpp
+++ b/lib/Transforms/IPO/IPConstantPropagation.cpp
@@ -145,6 +145,10 @@ bool IPCP::PropagateConstantsIntoArguments(Function &F) {
// all callers that use those return values with the constant value. This will
// leave in the actual return values and instructions, but deadargelim will
// clean that up.
+//
+// Additionally if a function always returns one of its arguments directly,
+// callers will be updated to use the value they pass in directly instead of
+// using the return value.
bool IPCP::PropagateConstantReturn(Function &F) {
if (F.getReturnType() == Type::VoidTy)
return false; // No return value.
@@ -188,8 +192,8 @@ bool IPCP::PropagateConstantReturn(Function &F) {
if (isa<UndefValue>(V))
continue;
- // Try to see if all the rets return the same constant.
- if (isa<Constant>(V)) {
+ // Try to see if all the rets return the same constant or argument.
+ if (isa<Constant>(V) || isa<Argument>(V)) {
if (isa<UndefValue>(RV)) {
// No value found yet? Try the current one.
RetVals[i] = V;
@@ -255,6 +259,11 @@ bool IPCP::PropagateConstantReturn(Function &F) {
if (index != -1) {
Value *New = RetVals[index];
if (New) {
+ if (Argument *A = dyn_cast<Argument>(New))
+ // Was an argument returned? Then find the corresponding argument in
+ // the call instruction and use that. Add 1 to the argument number
+ // to skipp the first argument (the function itself).
+ New = Call->getOperand(A->getArgNo() + 1);
Ins->replaceAllUsesWith(New);
Ins->eraseFromParent();
}