[InstCombine] use m_APInt; NFCI

llvm-svn: 273715
This commit is contained in:
Sanjay Patel 2016-06-24 20:36:34 +00:00
parent 38238a4f56
commit 2cbe679774
1 changed files with 8 additions and 18 deletions

View File

@ -126,33 +126,23 @@ bool InstCombiner::ShouldChangeType(Type *From, Type *To) const {
// all other opcodes, the function conservatively returns false.
static bool MaintainNoSignedWrap(BinaryOperator &I, Value *B, Value *C) {
OverflowingBinaryOperator *OBO = dyn_cast<OverflowingBinaryOperator>(&I);
if (!OBO || !OBO->hasNoSignedWrap()) {
if (!OBO || !OBO->hasNoSignedWrap())
return false;
}
// We reason about Add and Sub Only.
Instruction::BinaryOps Opcode = I.getOpcode();
if (Opcode != Instruction::Add &&
Opcode != Instruction::Sub) {
if (Opcode != Instruction::Add && Opcode != Instruction::Sub)
return false;
}
ConstantInt *CB = dyn_cast<ConstantInt>(B);
ConstantInt *CC = dyn_cast<ConstantInt>(C);
if (!CB || !CC) {
const APInt *BVal, *CVal;
if (!match(B, m_APInt(BVal)) || !match(C, m_APInt(CVal)))
return false;
}
const APInt &BVal = CB->getValue();
const APInt &CVal = CC->getValue();
bool Overflow = false;
if (Opcode == Instruction::Add) {
BVal.sadd_ov(CVal, Overflow);
} else {
BVal.ssub_ov(CVal, Overflow);
}
if (Opcode == Instruction::Add)
BVal->sadd_ov(*CVal, Overflow);
else
BVal->ssub_ov(*CVal, Overflow);
return !Overflow;
}