OSDN Git Service

Subzero: Fold icmp into br/select lowering.
authorJim Stichnoth <stichnot@chromium.org>
Sun, 17 May 2015 17:11:41 +0000 (10:11 -0700)
committerJim Stichnoth <stichnot@chromium.org>
Sun, 17 May 2015 17:11:41 +0000 (10:11 -0700)
commita59ae6ffa3d06baaedc25883615a8e8bce67e3fe
treee8bb762c6bfa115f8de2b6e812448bf5ad1c3516
parent33492e7603a11fab7ecf4ad471ce2a30557cd787
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
src/IceCfgNode.cpp
src/IceClFlags.cpp
src/IceDefs.h
src/IceInst.h
src/IceTargetLowering.cpp
src/IceTargetLowering.h
src/IceTargetLoweringX8632.cpp
src/IceTargetLoweringX8632.h
tests_lit/llvm2ice_tests/8bit.pnacl.ll
tests_lit/llvm2ice_tests/bool-folding.ll [new file with mode: 0644]
tests_lit/llvm2ice_tests/select-opt.ll