[llvm-commits] [llvm] r52397 - /llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp
Matthijs Kooijman
matthijs at stdin.nl
Tue Jun 17 05:20:36 PDT 2008
Author: matthijs
Date: Tue Jun 17 07:20:24 2008
New Revision: 52397
URL: http://llvm.org/viewvc/llvm-project?rev=52397&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp
Modified: llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp?rev=52397&r1=52396&r2=52397&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp Tue Jun 17 07:20:24 2008
@@ -145,6 +145,10 @@
// 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 @@
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 @@
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();
}
More information about the llvm-commits
mailing list