[InstCombine] add an assert to make a shl+icmp transform assumption explicit; NFCI

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292440 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Sanjay Patel 2017-01-18 21:16:12 +00:00
parent 9c79f14436
commit 82823ef719

View File

@ -1921,11 +1921,19 @@ Instruction *InstCombiner::foldICmpShlConstant(ICmpInst &Cmp,
// A 'shl nuw' is just shifting out zeros, so adjust the compare constant
// and eliminate the shift.
if (Shl->hasNoUnsignedWrap()) {
if (Cmp.isEquality() || Pred == ICmpInst::ICMP_UGT) {
if (Pred == ICmpInst::ICMP_UGT) {
// icmp Pred (shl nuw X, ShiftAmt), C --> icmp Pred X, (C >>u ShiftAmt)
APInt ShiftedC = C->lshr(*ShiftAmt);
return new ICmpInst(Pred, X, ConstantInt::get(ShType, ShiftedC));
}
if (Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE) {
// This is the same code as the UGT case, but assert the pre-condition
// that is needed for this to work with equality predicates.
assert(C->lshr(*ShiftAmt).shl(*ShiftAmt) == *C &&
"Compare known true or false was not folded");
APInt ShiftedC = C->lshr(*ShiftAmt);
return new ICmpInst(Pred, X, ConstantInt::get(ShType, ShiftedC));
}
if (Pred == ICmpInst::ICMP_ULT) {
// ULE is the same as above, but ULE is canonicalized to ULT, so convert:
// (X << S) <=u C is equiv to X <=u (C >> S) for all C