mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-26 07:24:25 +00:00
Transform (x&C)>V into (x&C)!=0 where possible
When the least bit of C is greater than V, (x&C) must be greater than V if it is not zero, so the comparison can be simplified. Although this was suggested in Target/X86/README.txt, it benefits any architecture with a directly testable form of AND. Patch by Kevin Schoedel git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170576 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -1226,6 +1226,16 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI,
|
||||
ICI.setOperand(0, NewAnd);
|
||||
return &ICI;
|
||||
}
|
||||
|
||||
// Replace ((X & AndCST) > RHSV) with ((X & AndCST) != 0), if any
|
||||
// bit set in (X & AndCST) will produce a result greater than RHSV.
|
||||
if (ICI.getPredicate() == ICmpInst::ICMP_UGT) {
|
||||
unsigned NTZ = AndCST->getValue().countTrailingZeros();
|
||||
if ((NTZ < AndCST->getBitWidth()) &&
|
||||
APInt::getOneBitSet(AndCST->getBitWidth(), NTZ).ugt(RHSV))
|
||||
return new ICmpInst(ICmpInst::ICMP_NE, LHSI,
|
||||
Constant::getNullValue(RHS->getType()));
|
||||
}
|
||||
}
|
||||
|
||||
// Try to optimize things like "A[i]&42 == 0" to index computations.
|
||||
|
Reference in New Issue
Block a user