OSDN Git Service

[PowerPC] eliminate redundant compare instruction
authorHiroshi Inoue <inouehrs@jp.ibm.com>
Tue, 5 Sep 2017 04:15:17 +0000 (04:15 +0000)
committerHiroshi Inoue <inouehrs@jp.ibm.com>
Tue, 5 Sep 2017 04:15:17 +0000 (04:15 +0000)
commit7166ffbe09f61d09422d01a1426b6a7e3a88b1ac
treea691b268fb24400d71b461b51b0728a726d37fa3
parenta9601423aaa71cb1e70735ce2a492d23625970f7
[PowerPC] eliminate redundant compare instruction

If multiple conditional branches are executed based on the same comparison, we can execute multiple conditional branches based on the result of one comparison on PPC. For example,

if (a == 0) { ... }
else if (a < 0) { ... }

can be executed by one compare and two conditional branches instead of two pairs of a compare and a conditional branch.

This patch identifies a code sequence of the two pairs of a compare and a conditional branch and merge the compares if possible.
To maximize the opportunity, we do canonicalization of code sequence before merging compares.
For the above example, the input for this pass looks like:

cmplwi r3, 0
beq    0, .LBB0_3
cmpwi  r3, -1
bgt    0, .LBB0_4

So, before merging two compares, we canonicalize it as

cmpwi  r3, 0       ; cmplwi and cmpwi yield same result for beq
beq    0, .LBB0_3
cmpwi  r3, 0       ; greather than -1 means greater or equal to 0
bge    0, .LBB0_4

The generated code should be

cmpwi  r3, 0
beq    0, .LBB0_3
bge    0, .LBB0_4

Differential Revision: https://reviews.llvm.org/D37211

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312514 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/PowerPC/PPCMIPeephole.cpp
test/CodeGen/PowerPC/cmp_elimination.ll [new file with mode: 0644]