mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-26 07:29:55 +00:00
InstCombine: Replace custom constant folding code with ConstantExpr.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201352 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d8be721249
commit
62356fc694
@ -666,22 +666,12 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||||||
// Check for constant LHS & RHS - in this case we just simplify.
|
// Check for constant LHS & RHS - in this case we just simplify.
|
||||||
bool Zext = (II->getIntrinsicID() == Intrinsic::arm_neon_vmullu);
|
bool Zext = (II->getIntrinsicID() == Intrinsic::arm_neon_vmullu);
|
||||||
VectorType *NewVT = cast<VectorType>(II->getType());
|
VectorType *NewVT = cast<VectorType>(II->getType());
|
||||||
unsigned NewWidth = NewVT->getElementType()->getIntegerBitWidth();
|
if (Constant *CV0 = dyn_cast<Constant>(Arg0)) {
|
||||||
if (ConstantDataVector *CV0 = dyn_cast<ConstantDataVector>(Arg0)) {
|
if (Constant *CV1 = dyn_cast<Constant>(Arg1)) {
|
||||||
if (ConstantDataVector *CV1 = dyn_cast<ConstantDataVector>(Arg1)) {
|
CV0 = ConstantExpr::getIntegerCast(CV0, NewVT, /*isSigned=*/!Zext);
|
||||||
VectorType* VT = cast<VectorType>(CV0->getType());
|
CV1 = ConstantExpr::getIntegerCast(CV1, NewVT, /*isSigned=*/!Zext);
|
||||||
SmallVector<Constant*, 4> NewElems;
|
|
||||||
for (unsigned i = 0; i < VT->getNumElements(); ++i) {
|
return ReplaceInstUsesWith(CI, ConstantExpr::getMul(CV0, CV1));
|
||||||
APInt CV0E =
|
|
||||||
(cast<ConstantInt>(CV0->getAggregateElement(i)))->getValue();
|
|
||||||
CV0E = Zext ? CV0E.zext(NewWidth) : CV0E.sext(NewWidth);
|
|
||||||
APInt CV1E =
|
|
||||||
(cast<ConstantInt>(CV1->getAggregateElement(i)))->getValue();
|
|
||||||
CV1E = Zext ? CV1E.zext(NewWidth) : CV1E.sext(NewWidth);
|
|
||||||
NewElems.push_back(
|
|
||||||
ConstantInt::get(NewVT->getElementType(), CV0E * CV1E));
|
|
||||||
}
|
|
||||||
return ReplaceInstUsesWith(CI, ConstantVector::get(NewElems));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Couldn't simplify - canonicalize constant to the RHS.
|
// Couldn't simplify - canonicalize constant to the RHS.
|
||||||
@ -689,17 +679,12 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle mul by one:
|
// Handle mul by one:
|
||||||
if (ConstantDataVector *CV1 = dyn_cast<ConstantDataVector>(Arg1)) {
|
if (Constant *CV1 = dyn_cast<Constant>(Arg1))
|
||||||
if (ConstantInt *Splat =
|
if (ConstantInt *Splat =
|
||||||
dyn_cast_or_null<ConstantInt>(CV1->getSplatValue())) {
|
dyn_cast_or_null<ConstantInt>(CV1->getSplatValue()))
|
||||||
if (Splat->isOne()) {
|
if (Splat->isOne())
|
||||||
if (Zext)
|
return CastInst::CreateIntegerCast(Arg0, II->getType(),
|
||||||
return CastInst::CreateZExtOrBitCast(Arg0, II->getType());
|
/*isSigned=*/!Zext);
|
||||||
// else
|
|
||||||
return CastInst::CreateSExtOrBitCast(Arg0, II->getType());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user