Make !if short-circuit when possible.

llvm-svn: 73076
This commit is contained in:
David Greene 2009-06-08 19:16:56 +00:00
parent d9173b83db
commit b035445537
1 changed files with 17 additions and 1 deletions

View File

@ -965,9 +965,25 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
Init *TernOpInit::resolveReferences(Record &R, const RecordVal *RV) {
Init *lhs = LHS->resolveReferences(R, RV);
if (Opc == IF && lhs != LHS) {
IntInit *Value = dynamic_cast<IntInit*>(lhs);
if (Value != 0) {
// Short-circuit
if (Value->getValue()) {
Init *mhs = MHS->resolveReferences(R, RV);
return (new TernOpInit(getOpcode(), lhs, mhs, RHS, getType()))->Fold(&R, 0);
}
else {
Init *rhs = RHS->resolveReferences(R, RV);
return (new TernOpInit(getOpcode(), lhs, MHS, rhs, getType()))->Fold(&R, 0);
}
}
}
Init *mhs = MHS->resolveReferences(R, RV);
Init *rhs = RHS->resolveReferences(R, RV);
if (LHS != lhs || MHS != mhs || RHS != rhs)
return (new TernOpInit(getOpcode(), lhs, mhs, rhs, getType()))->Fold(&R, 0);
return Fold(&R, 0);