aboutsummaryrefslogtreecommitdiff
path: root/lib
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
commit797249bc136378d8af429b136a6c35242bd71623 (patch)
treeb3fd67061c5f0a55a5b5ab9266183f96e2e33c7e /lib
parent1474b47600a8c89c1f62f9e263a0f462628259e0 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6837 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index bd95a18a70..a0a09e4b1d 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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;
}