mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
my instcombine transformations to make extension elimination more
aggressive changed the canonical form from sext(trunc(x)) to ashr(lshr(x)), make sure to transform a couple more things into that canonical form, and catch a case where we missed turning zext/shl/ashr into a single sext. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93787 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -955,6 +955,19 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) {
|
||||
ShAmt);
|
||||
}
|
||||
|
||||
// If this input is a trunc from our destination, then turn sext(trunc(x))
|
||||
// into shifts.
|
||||
if (TruncInst *TI = dyn_cast<TruncInst>(Src))
|
||||
if (TI->hasOneUse() && TI->getOperand(0)->getType() == DestTy) {
|
||||
uint32_t SrcBitSize = SrcTy->getScalarSizeInBits();
|
||||
uint32_t DestBitSize = DestTy->getScalarSizeInBits();
|
||||
|
||||
// We need to emit a shl + ashr to do the sign extend.
|
||||
Value *ShAmt = ConstantInt::get(DestTy, DestBitSize-SrcBitSize);
|
||||
Value *Res = Builder->CreateShl(TI->getOperand(0), ShAmt, "sext");
|
||||
return BinaryOperator::CreateAShr(Res, ShAmt);
|
||||
}
|
||||
|
||||
// If the input is a shl/ashr pair of a same constant, then this is a sign
|
||||
// extension from a smaller value. If we could trust arbitrary bitwidth
|
||||
// integers, we could turn this into a truncate to the smaller bit and then
|
||||
|
Reference in New Issue
Block a user