mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-04 21:31:03 +00:00
cleanup
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92790 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c0f79af143
commit
274ad68cc7
@ -498,12 +498,6 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
|||||||
if (Instruction *Result = commonCastTransforms(CI))
|
if (Instruction *Result = commonCastTransforms(CI))
|
||||||
return Result;
|
return Result;
|
||||||
|
|
||||||
Value *Src = CI.getOperand(0);
|
|
||||||
const Type *SrcTy = Src->getType();
|
|
||||||
const Type *DestTy = CI.getType();
|
|
||||||
uint32_t SrcBitSize = SrcTy->getScalarSizeInBits();
|
|
||||||
uint32_t DestBitSize = DestTy->getScalarSizeInBits();
|
|
||||||
|
|
||||||
// See if we can simplify any instructions used by the LHS whose sole
|
// See if we can simplify any instructions used by the LHS whose sole
|
||||||
// purpose is to compute bits we don't care about.
|
// purpose is to compute bits we don't care about.
|
||||||
if (SimplifyDemandedInstructionBits(CI))
|
if (SimplifyDemandedInstructionBits(CI))
|
||||||
@ -511,18 +505,23 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
|||||||
|
|
||||||
// If the source isn't an instruction or has more than one use then we
|
// If the source isn't an instruction or has more than one use then we
|
||||||
// can't do anything more.
|
// can't do anything more.
|
||||||
Instruction *SrcI = dyn_cast<Instruction>(Src);
|
Instruction *Src = dyn_cast<Instruction>(CI.getOperand(0));
|
||||||
if (!SrcI || !Src->hasOneUse())
|
if (!Src || !Src->hasOneUse())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
const Type *SrcTy = Src->getType();
|
||||||
|
const Type *DestTy = CI.getType();
|
||||||
|
uint32_t SrcBitSize = SrcTy->getScalarSizeInBits();
|
||||||
|
uint32_t DestBitSize = DestTy->getScalarSizeInBits();
|
||||||
|
|
||||||
// Attempt to propagate the cast into the instruction for int->int casts.
|
// Attempt to propagate the cast into the instruction for int->int casts.
|
||||||
int NumCastsRemoved = 0;
|
int NumCastsRemoved = 0;
|
||||||
// Only do this if the dest type is a simple type, don't convert the
|
// Only do this if the dest type is a simple type, don't convert the
|
||||||
// expression tree to something weird like i93 unless the source is also
|
// expression tree to something weird like i93 unless the source is also
|
||||||
// strange.
|
// strange.
|
||||||
if ((isa<VectorType>(DestTy) ||
|
if ((isa<VectorType>(DestTy) ||
|
||||||
ShouldChangeType(SrcI->getType(), DestTy)) &&
|
ShouldChangeType(Src->getType(), DestTy)) &&
|
||||||
CanEvaluateInDifferentType(SrcI, DestTy,
|
CanEvaluateInDifferentType(Src, DestTy,
|
||||||
CI.getOpcode(), NumCastsRemoved)) {
|
CI.getOpcode(), NumCastsRemoved)) {
|
||||||
// If this cast is a truncate, evaluting in a different type always
|
// If this cast is a truncate, evaluting in a different type always
|
||||||
// eliminates the cast, so it is always a win. If this is a zero-extension,
|
// eliminates the cast, so it is always a win. If this is a zero-extension,
|
||||||
@ -546,7 +545,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
|||||||
if (!DoXForm && 0) {
|
if (!DoXForm && 0) {
|
||||||
// If it's unnecessary to issue an AND to clear the high bits, it's
|
// If it's unnecessary to issue an AND to clear the high bits, it's
|
||||||
// always profitable to do this xform.
|
// always profitable to do this xform.
|
||||||
Value *TryRes = EvaluateInDifferentType(SrcI, DestTy, false);
|
Value *TryRes = EvaluateInDifferentType(Src, DestTy, false);
|
||||||
APInt Mask(APInt::getBitsSet(DestBitSize, SrcBitSize, DestBitSize));
|
APInt Mask(APInt::getBitsSet(DestBitSize, SrcBitSize, DestBitSize));
|
||||||
if (MaskedValueIsZero(TryRes, Mask))
|
if (MaskedValueIsZero(TryRes, Mask))
|
||||||
return ReplaceInstUsesWith(CI, TryRes);
|
return ReplaceInstUsesWith(CI, TryRes);
|
||||||
@ -559,7 +558,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
|||||||
}
|
}
|
||||||
case Instruction::SExt: {
|
case Instruction::SExt: {
|
||||||
DoXForm = NumCastsRemoved >= 2;
|
DoXForm = NumCastsRemoved >= 2;
|
||||||
if (!DoXForm && !isa<TruncInst>(SrcI) && 0) {
|
if (!DoXForm && !isa<TruncInst>(Src) && 0) {
|
||||||
// If we do not have to emit the truncate + sext pair, then it's always
|
// If we do not have to emit the truncate + sext pair, then it's always
|
||||||
// profitable to do this xform.
|
// profitable to do this xform.
|
||||||
//
|
//
|
||||||
@ -569,7 +568,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
|||||||
// t3 = sext i16 t2 to i32
|
// t3 = sext i16 t2 to i32
|
||||||
// !=
|
// !=
|
||||||
// i32 t1
|
// i32 t1
|
||||||
Value *TryRes = EvaluateInDifferentType(SrcI, DestTy, true);
|
Value *TryRes = EvaluateInDifferentType(Src, DestTy, true);
|
||||||
unsigned NumSignBits = ComputeNumSignBits(TryRes);
|
unsigned NumSignBits = ComputeNumSignBits(TryRes);
|
||||||
if (NumSignBits > (DestBitSize - SrcBitSize))
|
if (NumSignBits > (DestBitSize - SrcBitSize))
|
||||||
return ReplaceInstUsesWith(CI, TryRes);
|
return ReplaceInstUsesWith(CI, TryRes);
|
||||||
@ -585,7 +584,7 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) {
|
|||||||
if (DoXForm) {
|
if (DoXForm) {
|
||||||
DEBUG(errs() << "ICE: EvaluateInDifferentType converting expression type"
|
DEBUG(errs() << "ICE: EvaluateInDifferentType converting expression type"
|
||||||
" to avoid cast: " << CI);
|
" to avoid cast: " << CI);
|
||||||
Value *Res = EvaluateInDifferentType(SrcI, DestTy,
|
Value *Res = EvaluateInDifferentType(Src, DestTy,
|
||||||
CI.getOpcode() == Instruction::SExt);
|
CI.getOpcode() == Instruction::SExt);
|
||||||
if (JustReplace)
|
if (JustReplace)
|
||||||
// Just replace this cast with the result.
|
// Just replace this cast with the result.
|
||||||
@ -634,11 +633,9 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
|
|||||||
|
|
||||||
Value *Src = CI.getOperand(0);
|
Value *Src = CI.getOperand(0);
|
||||||
const Type *DestTy = CI.getType();
|
const Type *DestTy = CI.getType();
|
||||||
uint32_t DestBitWidth = DestTy->getScalarSizeInBits();
|
|
||||||
uint32_t SrcBitWidth = Src->getType()->getScalarSizeInBits();
|
|
||||||
|
|
||||||
// Canonicalize trunc x to i1 -> (icmp ne (and x, 1), 0)
|
// Canonicalize trunc x to i1 -> (icmp ne (and x, 1), 0)
|
||||||
if (DestBitWidth == 1) {
|
if (DestTy->isInteger(1)) {
|
||||||
Constant *One = ConstantInt::get(Src->getType(), 1);
|
Constant *One = ConstantInt::get(Src->getType(), 1);
|
||||||
Src = Builder->CreateAnd(Src, One, "tmp");
|
Src = Builder->CreateAnd(Src, One, "tmp");
|
||||||
Value *Zero = Constant::getNullValue(Src->getType());
|
Value *Zero = Constant::getNullValue(Src->getType());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user