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 | 6580e09fef3c0feddb6e9270d9b3d7f5f919fa34 (patch) | |
| tree | 93b99985e09a5a5a542672974c5a9efedcbd3bbd /llvm/lib/Transforms | |
| parent | d2c8ed1170dc4fcc2515137e063595cb908544ee (diff) | |
| download | bcm5719-llvm-6580e09fef3c0feddb6e9270d9b3d7f5f919fa34.tar.gz bcm5719-llvm-6580e09fef3c0feddb6e9270d9b3d7f5f919fa34.zip | |
Implement InstCombine/getelementptr.ll:test9, which is the source of many
ugly and giant constnat exprs in some programs.
llvm-svn: 17066
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 18 | 
1 files changed, 18 insertions, 0 deletions
| diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 32686b3e851..a874723b541 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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); | 

