1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

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

llvm-svn: 292440
This commit is contained in:
Sanjay Patel 2017-01-18 21:16:12 +00:00
parent a5b100a7d1
commit 18abc2c940

View File

@ -1921,11 +1921,19 @@ Instruction *InstCombiner::foldICmpShlConstant(ICmpInst &Cmp,
// A 'shl nuw' is just shifting out zeros, so adjust the compare constant // A 'shl nuw' is just shifting out zeros, so adjust the compare constant
// and eliminate the shift. // and eliminate the shift.
if (Shl->hasNoUnsignedWrap()) { 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) // icmp Pred (shl nuw X, ShiftAmt), C --> icmp Pred X, (C >>u ShiftAmt)
APInt ShiftedC = C->lshr(*ShiftAmt); APInt ShiftedC = C->lshr(*ShiftAmt);
return new ICmpInst(Pred, X, ConstantInt::get(ShType, ShiftedC)); 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) { if (Pred == ICmpInst::ICMP_ULT) {
// ULE is the same as above, but ULE is canonicalized to ULT, so convert: // 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 // (X << S) <=u C is equiv to X <=u (C >> S) for all C