Subzero: Fold icmp into br/select lowering. Originally there was a peephole-style optimization in lowerIcmp() that looks ahead to see if the next instruction is a conditional branch with the right properties, and if so, folds the icmp and br into a single lowering sequence. However, sometimes extra instructions come between the icmp and br instructions, disabling the folding even though it would still be possible. One thought is to do the folding inside lowerBr() instead of lowerIcmp(), by looking backward for a suitable icmp instruction. The problem here is that the icmp lowering code may leave lowered instructions that can't easily be dead-code eliminated, e.g. instructions lacking a dest variable. Instead, before lowering a basic block, we do a prepass on the block to identify folding candidates. For the icmp/br example, the prepass would tentatively delete the icmp instruction and then the br lowering would fold in the icmp. This folding can also be extended to several producers: icmp (i32 operands), icmp (i64 operands), fcmp, trunc .. to i1 and several consumers: br, select, sext, zext This CL starts with 2 combinations: icmp32 paired with br & select. Other combinations will be added in later CLs. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4162 BUG= https://code.google.com/p/nativeclient/issues/detail?id=4095 R=jvoung@chromium.org Review URL: https://codereview.chromium.org/1141213004
diff --git a/src/IceInst.h b/src/IceInst.h index e3262c8..28fb046 100644 --- a/src/IceInst.h +++ b/src/IceInst.h
@@ -81,6 +81,7 @@ bool isDeleted() const { return Deleted; } void setDeleted() { Deleted = true; } + void setDead(bool Value = true) { Dead = Value; } void deleteIfDead(); bool hasSideEffects() const { return HasSideEffects; } @@ -178,7 +179,9 @@ InstNumberT Number; // Deleted means irrevocably deleted. bool Deleted; - // Dead means pending deletion after liveness analysis converges. + // Dead means one of two things depending on context: (1) pending + // deletion after liveness analysis converges, or (2) marked for + // deletion during lowering due to a folded bool operation. bool Dead; // HasSideEffects means the instruction is something like a function // call or a volatile load that can't be removed even if its Dest