@@ -2061,25 +2061,24 @@ Instruction *InstCombiner::foldICmpShlConstant(ICmpInst &Cmp, Instruction *Shl,
2061
2061
return nullptr ;
2062
2062
}
2063
2063
2064
+ // / Fold icmp ({al}shr X, Y), C.
2064
2065
Instruction *InstCombiner::foldICmpShrConstant (ICmpInst &ICI, Instruction *LHSI,
2065
2066
const APInt *RHSV) {
2066
- // FIXME: This check restricts all folds under here to scalar types.
2067
- ConstantInt *RHS = dyn_cast<ConstantInt>(ICI.getOperand (1 ));
2068
- if (!RHS)
2069
- return nullptr ;
2067
+ // An exact shr only shifts out zero bits, so:
2068
+ // icmp eq/ne (shr X, Y), 0 --> icmp eq/ne X, 0
2069
+ CmpInst::Predicate Pred = ICI.getPredicate ();
2070
+ BinaryOperator *BO = cast<BinaryOperator>(LHSI);
2071
+ if (ICI.isEquality () && BO->isExact () && BO->hasOneUse () && *RHSV == 0 )
2072
+ return new ICmpInst (Pred, BO->getOperand (0 ), ICI.getOperand (1 ));
2070
2073
2074
+ // FIXME: This check restricts all folds under here to scalar types.
2071
2075
// Handle equality comparisons of shift-by-constant.
2072
- BinaryOperator *BO = cast<BinaryOperator>(LHSI);
2073
- if (ConstantInt *ShAmt = dyn_cast<ConstantInt>(LHSI->getOperand (1 ))) {
2074
- if (Instruction *Res = foldICmpShrConstConst (ICI, BO, ShAmt))
2075
- return Res;
2076
- }
2076
+ ConstantInt *ShAmt = dyn_cast<ConstantInt>(LHSI->getOperand (1 ));
2077
+ if (!ShAmt)
2078
+ return nullptr ;
2077
2079
2078
- // Handle exact shr's.
2079
- if (ICI.isEquality () && BO->isExact () && BO->hasOneUse ()) {
2080
- if (RHSV->isMinValue ())
2081
- return new ICmpInst (ICI.getPredicate (), BO->getOperand (0 ), RHS);
2082
- }
2080
+ if (Instruction *Res = foldICmpShrConstConst (ICI, BO, ShAmt))
2081
+ return Res;
2083
2082
2084
2083
return nullptr ;
2085
2084
}
0 commit comments