diff options
author | Andrew Lenharth <andrewl@lenharth.org> | 2006-09-19 18:24:51 +0000 |
---|---|---|
committer | Andrew Lenharth <andrewl@lenharth.org> | 2006-09-19 18:24:51 +0000 |
commit | 4f339bebb02eef043e62b763ec64f91ad0b09d3e (patch) | |
tree | c42cd3c8a3f1552d7f0cbb5ca0acb3f3f355deed /llvm/lib/Transforms | |
parent | 731f2d52a3b75790e4f7792c050e33b23aff0f12 (diff) | |
download | bcm5719-llvm-4f339bebb02eef043e62b763ec64f91ad0b09d3e.tar.gz bcm5719-llvm-4f339bebb02eef043e62b763ec64f91ad0b09d3e.zip |
If we have an add, do it in the pointer realm, not the int realm. This is critical in the linux kernel for pointer analysis correctness
llvm-svn: 30496
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 40dfb4163c8..e5f2d9294eb 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -1595,6 +1595,28 @@ FoundSExt: return R; } + // add (cast *A to intptrtype) B -> cast (GEP (cast *A to sbyte*) B) -> intptrtype + { + CastInst* CI = dyn_cast<CastInst>(LHS); + Value* Other = RHS; + if (!CI) { + CI = dyn_cast<CastInst>(RHS); + Other = LHS; + } + if (CI) { + const Type *UIntPtrTy = TD->getIntPtrType(); + const Type *SIntPtrTy = UIntPtrTy->getSignedVersion(); + if((CI->getType() == UIntPtrTy || CI->getType() == SIntPtrTy) + && isa<PointerType>(CI->getOperand(0)->getType())) { + Instruction* I2 = new CastInst(CI->getOperand(0), PointerType::get(Type::SByteTy), "ctg", &I); + WorkList.push_back(I2); + I2 = new GetElementPtrInst(I2, Other, "ctg", &I); + WorkList.push_back(I2); + return new CastInst(I2, CI->getType()); + } + } + } + return Changed ? &I : 0; } |