[indvars] Common a bit of code [NFC]

This commit is contained in:
Philip Reames 2020-12-08 15:25:22 -08:00
parent caab41c08e
commit 5171b7b40e
1 changed files with 11 additions and 27 deletions
llvm/lib/Transforms/Utils

View File

@ -1272,28 +1272,8 @@ Instruction *WidenIV::cloneArithmeticIVUser(WidenIV::NarrowIVDefUse DU,
}
// WideUse is "WideDef `op.wide` X" as described in the comment.
const SCEV *WideUse = nullptr;
switch (NarrowUse->getOpcode()) {
default:
llvm_unreachable("No other possibility!");
case Instruction::Add:
WideUse = SE->getAddExpr(WideLHS, WideRHS);
break;
case Instruction::Mul:
WideUse = SE->getMulExpr(WideLHS, WideRHS);
break;
case Instruction::UDiv:
WideUse = SE->getUDivExpr(WideLHS, WideRHS);
break;
case Instruction::Sub:
WideUse = SE->getMinusSCEV(WideLHS, WideRHS);
break;
}
const SCEV *WideUse =
getSCEVByOpCode(WideLHS, WideRHS, NarrowUse->getOpcode());
return WideUse == WideAR;
};
@ -1332,14 +1312,18 @@ WidenIV::ExtendKind WidenIV::getExtendKind(Instruction *I) {
const SCEV *WidenIV::getSCEVByOpCode(const SCEV *LHS, const SCEV *RHS,
unsigned OpCode) const {
if (OpCode == Instruction::Add)
switch (OpCode) {
case Instruction::Add:
return SE->getAddExpr(LHS, RHS);
if (OpCode == Instruction::Sub)
case Instruction::Sub:
return SE->getMinusSCEV(LHS, RHS);
if (OpCode == Instruction::Mul)
case Instruction::Mul:
return SE->getMulExpr(LHS, RHS);
llvm_unreachable("Unsupported opcode.");
case Instruction::UDiv:
return SE->getUDivExpr(LHS, RHS);
default:
llvm_unreachable("Unsupported opcode.");
};
}
/// No-wrap operations can transfer sign extension of their result to their