diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index e23b70ae6a8f..a02d8ea396dd 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -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(&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(B); - ConstantInt *CC = dyn_cast(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; }