Skip to content

Commit

Permalink
Transfer functions for overflow insts (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
manasij7479 authored and regehr committed Jan 27, 2020
1 parent 09efbd5 commit 64eff6f
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions lib/Infer/AbstractInterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,30 +686,34 @@ namespace souper {
}
break;
}
// case ExtractValue:
// return "extractvalue";
// case SAddWithOverflow:
// return "sadd.with.overflow";
// case UAddWithOverflow:
// return "uadd.with.overflow";
// case SSubWithOverflow:
// return "ssub.with.overflow";
// case USubWithOverflow:
// return "usub.with.overflow";
// case SMulWithOverflow:
// return "smul.with.overflow";
// case UMulWithOverflow:
// return "umul.with.overflow";
case souper::Inst::ExtractValue: {
if (I->Ops[1]->Val == 0) {
auto IOld = I;
I = I->Ops[0]->Ops[0];
switch (IOld->Ops[0]->K) {
case souper::Inst::SAddWithOverflow:
case souper::Inst::UAddWithOverflow:
return BinaryTransferFunctionsKB::add(KB0, KB1);

case souper::Inst::SSubWithOverflow:
case souper::Inst::USubWithOverflow:
return BinaryTransferFunctionsKB::sub(KB0, KB1);

case souper::Inst::SMulWithOverflow:
case souper::Inst::UMulWithOverflow:
return BinaryTransferFunctionsKB::mul(KB0, KB1);
default:
llvm::report_fatal_error("Wrong operand in ExtractValue.");
}
I = IOld; // needed for caching
}
// returns TOP for the carry bit
}

// case ReservedConst:
// return "reservedconst";
// case ReservedInst:
// return "reservedinst";
// case SAddO:
// case UAddO:
// case SSubO:
// case USubO:
// case SMulO:
// case UMulO:
default :
break;
}
Expand Down Expand Up @@ -858,6 +862,30 @@ namespace souper {
// return R0.sdiv(R1); // unimplemented
// }
// TODO: Xor pattern for not, truncs and extends, etc
case souper::Inst::ExtractValue: {
if (I->Ops[1]->Val == 0) {
auto IOld = I;
I = I->Ops[0]->Ops[0];
switch (IOld->Ops[0]->K) {
case souper::Inst::SAddWithOverflow:
case souper::Inst::UAddWithOverflow:
return CR0.add(CR1);

case souper::Inst::SSubWithOverflow:
case souper::Inst::USubWithOverflow:
return CR0.sub(CR1);

case souper::Inst::SMulWithOverflow:
case souper::Inst::UMulWithOverflow:
return CR0.multiply(CR1);
default:
llvm::errs() << Inst::getKindName(I->Ops[0]->K) << "\n";
llvm::report_fatal_error("Wrong operand in ExtractValue.");
}
I = IOld; // needed for caching
}
// returns TOP for the carry bit
}
default:
break;
}
Expand Down

0 comments on commit 64eff6f

Please sign in to comment.