diff options
author | Chris Lattner <sabre@nondot.org> | 2004-10-16 19:44:59 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-10-16 19:44:59 +0000 |
commit | 061718cba87ed59ad60264eb43dd974b14c77ba4 (patch) | |
tree | db6748be228d793f4c5a808f32aaa0f008577f8c /lib | |
parent | 51a2c5aebf4bad4804635ee9a6fb8ec14a22eea6 (diff) | |
download | external_llvm-061718cba87ed59ad60264eb43dd974b14c77ba4.zip external_llvm-061718cba87ed59ad60264eb43dd974b14c77ba4.tar.gz external_llvm-061718cba87ed59ad60264eb43dd974b14c77ba4.tar.bz2 |
Implement InstCombine/getelementptr.ll:test9, which is the source of many
ugly and giant constnat exprs in some programs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17066 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 32686b3..a874723 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -4018,6 +4018,24 @@ bool InstCombiner::runOnFunction(Function &F) { // Instruction isn't dead, see if we can constant propagate it... if (Constant *C = ConstantFoldInstruction(I)) { + if (isa<GetElementPtrInst>(I) && + cast<Constant>(I->getOperand(0))->isNullValue() && + !isa<ConstantPointerNull>(C)) { + // If this is a constant expr gep that is effectively computing an + // "offsetof", fold it into 'cast int X to T*' instead of 'gep 0, 0, 12' + bool isFoldableGEP = true; + for (unsigned i = 1, e = I->getNumOperands(); i != e; ++i) + if (!isa<ConstantInt>(I->getOperand(i))) + isFoldableGEP = false; + if (isFoldableGEP) { + uint64_t Offset = TD->getIndexedOffset(I->getOperand(0)->getType(), + std::vector<Value*>(I->op_begin()+1, I->op_end())); + C = ConstantUInt::get(Type::ULongTy, Offset); + C = ConstantUInt::getCast(C, TD->getIntPtrType()); + C = ConstantExpr::getCast(C, I->getType()); + } + } + // Add operands to the worklist... AddUsesToWorkList(*I); ReplaceInstUsesWith(*I, C); |