diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-01-10 07:40:50 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-01-10 07:40:50 +0000 |
| commit | 2fff10c424bc5b27b2db7d82527d81855357cec5 (patch) | |
| tree | be13b59cee5920aa3c8c4becb262d01f2783c9fb /llvm/lib/Transforms | |
| parent | b8fd152d9400a7a6573e04e4b38e7d458a7d2253 (diff) | |
| download | bcm5719-llvm-2fff10c424bc5b27b2db7d82527d81855357cec5.tar.gz bcm5719-llvm-2fff10c424bc5b27b2db7d82527d81855357cec5.zip | |
now that the cost model has changed, we can always consider
elimination of a sign extend to be a win, which simplifies
the client of CanEvaluateSExtd, and allows us to eliminate
more casts (examples taken from real code).
llvm-svn: 93109
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index b0d017e0620..13f60716f2e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -919,34 +919,25 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) { if (NumBitsSExt == 0) return 0; + // Okay, we can transform this! Insert the new expression now. + DEBUG(dbgs() << "ICE: EvaluateInDifferentType converting expression type" + " to avoid sign extend: " << CI); + Value *Res = EvaluateInDifferentType(Src, DestTy, true); + assert(Res->getType() == DestTy); + uint32_t SrcBitSize = SrcTy->getScalarSizeInBits(); uint32_t DestBitSize = DestTy->getScalarSizeInBits(); + + // If the high bits are already filled with sign bit, just replace this + // cast with the result. + if (NumBitsSExt > DestBitSize - SrcBitSize || + ComputeNumSignBits(Res) > DestBitSize - SrcBitSize) + return ReplaceInstUsesWith(CI, Res); - // Because this is a sign extension, we can always transform it by inserting - // two new shifts (to do the extension). However, this is only profitable - // if we've eliminated two or more casts from the input. If we know the - // result will be sign-extended enough to not require these shifts, we can - // always do the transformation. - if (NumCastsRemoved >= 2 || - NumBitsSExt > DestBitSize-SrcBitSize) { - - // Okay, we can transform this! Insert the new expression now. - DEBUG(dbgs() << "ICE: EvaluateInDifferentType converting expression type" - " to avoid sign extend: " << CI); - Value *Res = EvaluateInDifferentType(Src, DestTy, true); - assert(Res->getType() == DestTy); - - // If the high bits are already filled with sign bit, just replace this - // cast with the result. - if (NumBitsSExt > DestBitSize - SrcBitSize || - ComputeNumSignBits(Res) > DestBitSize - SrcBitSize) - return ReplaceInstUsesWith(CI, Res); - - // We need to emit a shl + ashr to do the sign extend. - Value *ShAmt = ConstantInt::get(DestTy, DestBitSize-SrcBitSize); - return BinaryOperator::CreateAShr(Builder->CreateShl(Res, ShAmt, "sext"), - ShAmt); - } + // We need to emit a shl + ashr to do the sign extend. + Value *ShAmt = ConstantInt::get(DestTy, DestBitSize-SrcBitSize); + return BinaryOperator::CreateAShr(Builder->CreateShl(Res, ShAmt, "sext"), + ShAmt); } // If the input is a shl/ashr pair of a same constant, then this is a sign |

