[llvm] r292440 - [InstCombine] add an assert to make a shl+icmp transform assumption explicit; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 18 13:16:13 PST 2017
Author: spatel
Date: Wed Jan 18 15:16:12 2017
New Revision: 292440
URL: http://llvm.org/viewvc/llvm-project?rev=292440&view=rev
Log:
[InstCombine] add an assert to make a shl+icmp transform assumption explicit; NFCI
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=292440&r1=292439&r2=292440&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Wed Jan 18 15:16:12 2017
@@ -1921,11 +1921,19 @@ Instruction *InstCombiner::foldICmpShlCo
// 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
More information about the llvm-commits
mailing list