[InstCombine] Remove an unnecessary dyn_cast to Instruction and a switch over two opcodes. Just dyn_cast to the specific instruction classes individually. NFC
Change the helper methods to take the more specific class as well.
llvm-svn: 311527
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 7733a2c..19a37c1 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -1461,7 +1461,7 @@
/// Fold icmp (trunc X, Y), C.
Instruction *InstCombiner::foldICmpTruncConstant(ICmpInst &Cmp,
- Instruction *Trunc,
+ TruncInst *Trunc,
const APInt *C) {
ICmpInst::Predicate Pred = Cmp.getPredicate();
Value *X = Trunc->getOperand(0);
@@ -2470,7 +2470,7 @@
}
Instruction *InstCombiner::foldICmpSelectConstant(ICmpInst &Cmp,
- Instruction *Select,
+ SelectInst *Select,
ConstantInt *C) {
assert(C && "Cmp RHS should be a constant int!");
@@ -2482,8 +2482,8 @@
Value *OrigLHS, *OrigRHS;
ConstantInt *C1LessThan, *C2Equal, *C3GreaterThan;
if (Cmp.hasOneUse() &&
- matchThreeWayIntCompare(cast<SelectInst>(Select), OrigLHS, OrigRHS,
- C1LessThan, C2Equal, C3GreaterThan)) {
+ matchThreeWayIntCompare(Select, OrigLHS, OrigRHS, C1LessThan, C2Equal,
+ C3GreaterThan)) {
assert(C1LessThan && C2Equal && C3GreaterThan);
bool TrueWhenLessThan =
@@ -2577,26 +2577,19 @@
}
// Match against CmpInst LHS being instructions other than binary operators.
- Instruction *LHSI;
- if (match(Cmp.getOperand(0), m_Instruction(LHSI))) {
- switch (LHSI->getOpcode()) {
- case Instruction::Select:
- {
- // For now, we only support constant integers while folding the
- // ICMP(SELECT)) pattern. We can extend this to support vector of integers
- // similar to the cases handled by binary ops above.
- if (ConstantInt *ConstRHS = dyn_cast<ConstantInt>(Cmp.getOperand(1)))
- if (Instruction *I = foldICmpSelectConstant(Cmp, LHSI, ConstRHS))
- return I;
- break;
- }
- case Instruction::Trunc:
- if (Instruction *I = foldICmpTruncConstant(Cmp, LHSI, C))
+
+ if (auto *SI = dyn_cast<SelectInst>(Cmp.getOperand(0))) {
+ // For now, we only support constant integers while folding the
+ // ICMP(SELECT)) pattern. We can extend this to support vector of integers
+ // similar to the cases handled by binary ops above.
+ if (ConstantInt *ConstRHS = dyn_cast<ConstantInt>(Cmp.getOperand(1)))
+ if (Instruction *I = foldICmpSelectConstant(Cmp, SI, ConstRHS))
return I;
- break;
- default:
- break;
- }
+ }
+
+ if (auto *TI = dyn_cast<TruncInst>(Cmp.getOperand(0))) {
+ if (Instruction *I = foldICmpTruncConstant(Cmp, TI, C))
+ return I;
}
if (Instruction *I = foldICmpIntrinsicWithConstant(Cmp, C))
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 65a08ce..6dcfade 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -687,9 +687,9 @@
Instruction *foldICmpBinOp(ICmpInst &Cmp);
Instruction *foldICmpEquality(ICmpInst &Cmp);
- Instruction *foldICmpSelectConstant(ICmpInst &Cmp, Instruction *Select,
+ Instruction *foldICmpSelectConstant(ICmpInst &Cmp, SelectInst *Select,
ConstantInt *C);
- Instruction *foldICmpTruncConstant(ICmpInst &Cmp, Instruction *Trunc,
+ Instruction *foldICmpTruncConstant(ICmpInst &Cmp, TruncInst *Trunc,
const APInt *C);
Instruction *foldICmpAndConstant(ICmpInst &Cmp, BinaryOperator *And,
const APInt *C);