forked from OSchip/llvm-project
Sink a couple of transforms from instcombine into instsimplify.
llvm-svn: 321467
This commit is contained in:
parent
7a6db4fc4f
commit
5000ba69d7
|
@ -4495,6 +4495,22 @@ static Value *SimplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd,
|
|||
return *ArgBegin;
|
||||
return nullptr;
|
||||
}
|
||||
case Intrinsic::bswap: {
|
||||
Value *IIOperand = *ArgBegin;
|
||||
Value *X = nullptr;
|
||||
// bswap(bswap(x)) -> x
|
||||
if (match(IIOperand, m_BSwap(m_Value(X))))
|
||||
return X;
|
||||
return nullptr;
|
||||
}
|
||||
case Intrinsic::bitreverse: {
|
||||
Value *IIOperand = *ArgBegin;
|
||||
Value *X = nullptr;
|
||||
// bitreverse(bitreverse(x)) -> x
|
||||
if (match(IIOperand, m_BitReverse(m_Value(X))))
|
||||
return X;
|
||||
return nullptr;
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -4549,6 +4565,16 @@ static Value *SimplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd,
|
|||
return SimplifyRelativeLoad(C0, C1, Q.DL);
|
||||
return nullptr;
|
||||
}
|
||||
case Intrinsic::powi:
|
||||
if (ConstantInt *Power = dyn_cast<ConstantInt>(RHS)) {
|
||||
// powi(x, 0) -> 1.0
|
||||
if (Power->isZero())
|
||||
return ConstantFP::get(LHS->getType(), 1.0);
|
||||
// powi(x, 1) -> x
|
||||
if (Power->isOne())
|
||||
return LHS;
|
||||
}
|
||||
return nullptr;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -1901,16 +1901,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
lowerObjectSizeCall(II, DL, &TLI, /*MustSucceed=*/false))
|
||||
return replaceInstUsesWith(CI, N);
|
||||
return nullptr;
|
||||
|
||||
case Intrinsic::bswap: {
|
||||
Value *IIOperand = II->getArgOperand(0);
|
||||
Value *X = nullptr;
|
||||
|
||||
// TODO should this be in InstSimplify?
|
||||
// bswap(bswap(x)) -> x
|
||||
if (match(IIOperand, m_BSwap(m_Value(X))))
|
||||
return replaceInstUsesWith(CI, X);
|
||||
|
||||
// bswap(trunc(bswap(x))) -> trunc(lshr(x, c))
|
||||
if (match(IIOperand, m_Trunc(m_BSwap(m_Value(X))))) {
|
||||
unsigned C = X->getType()->getPrimitiveSizeInBits() -
|
||||
|
@ -1921,18 +1915,6 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Intrinsic::bitreverse: {
|
||||
Value *IIOperand = II->getArgOperand(0);
|
||||
Value *X = nullptr;
|
||||
|
||||
// TODO should this be in InstSimplify?
|
||||
// bitreverse(bitreverse(x)) -> x
|
||||
if (match(IIOperand, m_BitReverse(m_Value(X))))
|
||||
return replaceInstUsesWith(CI, X);
|
||||
break;
|
||||
}
|
||||
|
||||
case Intrinsic::masked_load:
|
||||
if (Value *SimplifiedMaskedOp = simplifyMaskedLoad(*II, Builder))
|
||||
return replaceInstUsesWith(CI, SimplifiedMaskedOp);
|
||||
|
@ -1946,12 +1928,8 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
|
|||
|
||||
case Intrinsic::powi:
|
||||
if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
|
||||
// powi(x, 0) -> 1.0
|
||||
if (Power->isZero())
|
||||
return replaceInstUsesWith(CI, ConstantFP::get(CI.getType(), 1.0));
|
||||
// powi(x, 1) -> x
|
||||
if (Power->isOne())
|
||||
return replaceInstUsesWith(CI, II->getArgOperand(0));
|
||||
// 0 and 1 are handled in instsimplify
|
||||
|
||||
// powi(x, -1) -> 1/x
|
||||
if (Power->isMinusOne())
|
||||
return BinaryOperator::CreateFDiv(ConstantFP::get(CI.getType(), 1.0),
|
||||
|
|
Loading…
Reference in New Issue