[PATCH] D37211: [PowerPC] eliminate redundant compare instruction
Hiroshi Inoue via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 28 04:55:37 PDT 2017
inouehrs created this revision.
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
https://reviews.llvm.org/D37211
Files:
lib/Target/PowerPC/PPCMIPeephole.cpp
test/CodeGen/PowerPC/cmp_elimination.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37211.112884.patch
Type: text/x-patch
Size: 24105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170828/d4917776/attachment.bin>
More information about the llvm-commits
mailing list