forked from OSchip/llvm-project
parent
38238a4f56
commit
2cbe679774
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue