diff options
| author | Chris Lattner <sabre@nondot.org> | 2001-12-06 18:06:13 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2001-12-06 18:06:13 +0000 | 
| commit | 71ffba7b70a5dd9acbcea981029793061121f746 (patch) | |
| tree | c33c8b63a6a69e7b67f85c76e83a8bfddbdf69cc /llvm/lib/Transforms | |
| parent | b1995e1e69851f4a268f93150c17c06442ee1265 (diff) | |
| download | bcm5719-llvm-71ffba7b70a5dd9acbcea981029793061121f746.tar.gz bcm5719-llvm-71ffba7b70a5dd9acbcea981029793061121f746.zip | |
We can do cast-add elimination even on casts that reinterpret
llvm-svn: 1427
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/LevelRaise.cpp | 24 | 
1 files changed, 11 insertions, 13 deletions
| diff --git a/llvm/lib/Transforms/LevelRaise.cpp b/llvm/lib/Transforms/LevelRaise.cpp index 19325b065c2..c35b5c67308 100644 --- a/llvm/lib/Transforms/LevelRaise.cpp +++ b/llvm/lib/Transforms/LevelRaise.cpp @@ -51,7 +51,6 @@ static inline bool isReinterpretingCast(const CastInst *CI) { -#if 0  // Unneccesary code, handled by convert exprs  // Peephole optimize the following instructions:  // %t1 = cast ? to x *  // %t2 = add x * %SP, %t1              ;; Constant must be 2nd operand @@ -117,8 +116,7 @@ static bool HandleCastToPointer(BasicBlock::iterator BI,        OtherPtr = C;      } -    GetElementPtrInst *GEP = new GetElementPtrInst(OtherPtr, Indices, -                                                   I->getName()); +    GetElementPtrInst *GEP = new GetElementPtrInst(OtherPtr, Indices);      PRINT_PEEPHOLE1("cast-add-to-gep:i", I); @@ -128,7 +126,6 @@ static bool HandleCastToPointer(BasicBlock::iterator BI,    }    return true;  } -#endif  // Peephole optimize the following instructions:  // %t1 = cast ulong <const int> to {<...>} * @@ -269,16 +266,17 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {  #endif          return true;        } -#if 0 -      // Otherwise find out it this cast is a cast to a pointer type, which is -      // then added to some other pointer, then loaded or stored through.  If -      // so, convert the add into a getelementptr instruction... -      // -      if (const PointerType *DestPTy = dyn_cast<PointerType>(DestTy)) { -        if (HandleCastToPointer(BI, DestPTy)) -          return true; +    } + +    // Otherwise find out it this cast is a cast to a pointer type, which is +    // then added to some other pointer, then loaded or stored through.  If +    // so, convert the add into a getelementptr instruction... +    // +    if (const PointerType *DestPTy = dyn_cast<PointerType>(DestTy)) { +      if (HandleCastToPointer(BI, DestPTy)) { +        BI = BB->begin();  // Rescan basic block.  BI might be invalidated. +        return true;        } -#endif      }      // Check to see if we are casting from a structure pointer to a pointer to | 

