Skip to content

Commit

Permalink
RedundantFlagCalculationElimination: select testz
Browse files Browse the repository at this point in the history
this saves uops.

Signed-off-by: Alyssa Rosenzweig <[email protected]>
  • Loading branch information
alyssarosenzweig committed Sep 6, 2024
1 parent 834f887 commit f41240b
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,21 @@ bool DeadFlagCalculationEliminination::ProcessBlock(IREmitter* IREmit, IRListVie
} else if (Info.Replacement) {
IROp->Op = Info.Replacement;
}
} else {
FlagsRead &= ~Info.Write;
} else if (Info.ReplacementNoWrite && CodeNode->GetUses() == 0) {
IROp->Op = Info.ReplacementNoWrite;
}

if (Info.ReplacementNoWrite && CodeNode->GetUses() == 0) {
IROp->Op = Info.ReplacementNoWrite;
}
// If we don't care about the sign or carry, we can optimize testnz.
// Carry is inverted between testz and testnz so we check that too. Note
// this flag is outside of the if, since the TestNZ might result from
// optimizing AndWithFlags, and we need to converge locally in a single
// iteration.
if (IROp->Op == OP_TESTNZ && IROp->Size < 4 && !(FlagsRead & (FLAG_N | FLAG_C))) {
IROp->Op = OP_TESTZ;
}

FlagsRead &= ~Info.Write;

// If we eliminated the instruction, we eliminate its read too. This
// check is required to ensure the pass converges locally in a single
// iteration.
Expand Down

0 comments on commit f41240b

Please sign in to comment.