mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
Simplify some comparisons to arithmetic, this implements:
Transforms/InstCombine/icmp.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35890 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f6e166b386
commit
a2e2c9bbf3
@ -6570,6 +6570,33 @@ Instruction *InstCombiner::visitZExt(CastInst &CI) {
|
|||||||
// cast to integer to avoid the comparison.
|
// cast to integer to avoid the comparison.
|
||||||
if (ConstantInt *Op1C = dyn_cast<ConstantInt>(ICI->getOperand(1))) {
|
if (ConstantInt *Op1C = dyn_cast<ConstantInt>(ICI->getOperand(1))) {
|
||||||
const APInt &Op1CV = Op1C->getValue();
|
const APInt &Op1CV = Op1C->getValue();
|
||||||
|
|
||||||
|
// zext (x <s 0) to i32 --> x>>u31 true if signbit set.
|
||||||
|
// zext (x >s -1) to i32 --> (x>>u31)^1 true if signbit clear.
|
||||||
|
if ((ICI->getPredicate() == ICmpInst::ICMP_SLT && Op1CV == 0) ||
|
||||||
|
(ICI->getPredicate() == ICmpInst::ICMP_SGT &&Op1CV.isAllOnesValue())){
|
||||||
|
Value *In = ICI->getOperand(0);
|
||||||
|
Value *Sh = ConstantInt::get(In->getType(),
|
||||||
|
In->getType()->getPrimitiveSizeInBits()-1);
|
||||||
|
In = InsertNewInstBefore(BinaryOperator::createLShr(In, Sh,
|
||||||
|
In->getName()+".lobit"),
|
||||||
|
CI);
|
||||||
|
if (In->getType() != CI.getType())
|
||||||
|
In = CastInst::createIntegerCast(In, CI.getType(),
|
||||||
|
false/*ZExt*/, "tmp", &CI);
|
||||||
|
|
||||||
|
if (ICI->getPredicate() == ICmpInst::ICMP_SGT) {
|
||||||
|
Constant *One = ConstantInt::get(In->getType(), 1);
|
||||||
|
In = InsertNewInstBefore(BinaryOperator::createXor(In, One,
|
||||||
|
In->getName()+".not"),
|
||||||
|
CI);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ReplaceInstUsesWith(CI, In);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// zext (X == 0) to i32 --> X^1 iff X has only the low bit set.
|
// zext (X == 0) to i32 --> X^1 iff X has only the low bit set.
|
||||||
// zext (X == 0) to i32 --> (X>>1)^1 iff X has only the 2nd bit set.
|
// zext (X == 0) to i32 --> (X>>1)^1 iff X has only the 2nd bit set.
|
||||||
// zext (X == 1) to i32 --> X iff X has only the low bit set.
|
// zext (X == 1) to i32 --> X iff X has only the low bit set.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user