Added CPUI_INT_NEGATE to RuleEqual2Constant

This commit is contained in:
caheckman 2019-07-23 15:52:16 -04:00
parent 45c0f398d2
commit c7e3f54212

View file

@ -5470,6 +5470,7 @@ int4 RuleEqual2Zero::applyOp(PcodeOp *op,Funcdata &data)
/// Forms include: /// Forms include:
/// - `V * -1 == c => V == -c` /// - `V * -1 == c => V == -c`
/// - `V + c == d => V == (d-c)` /// - `V + c == d => V == (d-c)`
/// - `~V == c => V == ~c`
void RuleEqual2Constant::getOpList(vector<uint4> &oplist) const void RuleEqual2Constant::getOpList(vector<uint4> &oplist) const
{ {
@ -5488,13 +5489,14 @@ int4 RuleEqual2Constant::applyOp(PcodeOp *op,Funcdata &data)
PcodeOp *leftop = lhs->getDef(); PcodeOp *leftop = lhs->getDef();
Varnode *a; Varnode *a;
uintb newconst; uintb newconst;
if (leftop->code() == CPUI_INT_ADD) { OpCode opc = leftop->code();
if (opc == CPUI_INT_ADD) {
Varnode *otherconst = leftop->getIn(1); Varnode *otherconst = leftop->getIn(1);
if (!otherconst->isConstant()) return 0; if (!otherconst->isConstant()) return 0;
newconst = cvn->getOffset() - otherconst->getOffset(); newconst = cvn->getOffset() - otherconst->getOffset();
newconst &= calc_mask(cvn->getSize()); newconst &= calc_mask(cvn->getSize());
} }
else if (leftop->code() == CPUI_INT_MULT) { else if (opc == CPUI_INT_MULT) {
Varnode *otherconst = leftop->getIn(1); Varnode *otherconst = leftop->getIn(1);
if (!otherconst->isConstant()) return 0; if (!otherconst->isConstant()) return 0;
// The only multiply we transform, is multiply by -1 // The only multiply we transform, is multiply by -1
@ -5502,6 +5504,10 @@ int4 RuleEqual2Constant::applyOp(PcodeOp *op,Funcdata &data)
newconst = cvn->getOffset(); newconst = cvn->getOffset();
newconst = (-newconst) & calc_mask(otherconst->getSize()); newconst = (-newconst) & calc_mask(otherconst->getSize());
} }
else if (opc == CPUI_INT_NEGATE) {
newconst = cvn->getOffset();
newconst = (~newconst) & calc_mask(lhs->getSize());
}
else else
return 0; return 0;