summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-06-21 23:12:02 +0000
committerChris Lattner <sabre@nondot.org>2003-06-21 23:12:02 +0000
commitd0d51605b2deab725abbc12dcb8236cfd1c5b4d4 (patch)
tree1e83f19c7bfac9c0a3e3b52f1eb5dbc4b8251d6b /llvm/lib/Transforms
parenta103d76cbe4befa6639837054c991bbde165b091 (diff)
downloadbcm5719-llvm-d0d51605b2deab725abbc12dcb8236cfd1c5b4d4.tar.gz
bcm5719-llvm-d0d51605b2deab725abbc12dcb8236cfd1c5b4d4.zip
Instcombine cast (getelementptr Ptr, 0, 0, 0) to ... into: cast Ptr to ...
This fixes type safety problems in a variety of benchmarks that were confusing DSA. llvm-svn: 6837
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index bd95a18a701..a0a09e4b1da 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -930,6 +930,23 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) {
}
}
+ // If casting the result of a getelementptr instruction with no offset, turn
+ // this into a cast of the original pointer!
+ //
+ if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CI.getOperand(0))) {
+ bool AllZeroOperands = true;
+ for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i)
+ if (!isa<Constant>(GEP->getOperand(i)) ||
+ !cast<Constant>(GEP->getOperand(i))->isNullValue()) {
+ AllZeroOperands = false;
+ break;
+ }
+ if (AllZeroOperands) {
+ CI.setOperand(0, GEP->getOperand(0));
+ return &CI;
+ }
+ }
+
return 0;
}
OpenPOWER on IntegriCloud