This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] avoid unprofitable Repl32 flag in BitPermutationSelector
ClosedPublic

Authored by inouehrs on Jun 6 2018, 11:06 PM.

Details

Summary

BitPermutationSelector sets Repl32 flag for bit groups which can be (potentially) benefit from 32-bit rotate-and-mask instructions with bit replication, i.e. rlwinm/rlwimi copies lower 32 bits into upper 32 bits on 64-bit PowerPC before rotation.
However, enforcing 32-bit instruction sometimes results in redundant generated code.
For example, the following simple code is compiled into rotldi + rlwimi while it can be compiled into only rldimi instruction if Repl32 flag is not set on the bit group for (a & 0xFFFFFFFF).

uint64_t func(uint64_t a, uint64_t b) {
	return (a & 0xFFFFFFFF) | (b << 32) ;
}

To avoid such problem, this patch checks the potential benefit of Repl32 flag before setting it. If a bit group does not require rotation (i.e. RLAmt == 0) and won't be merged into another group, we do not benefit from Repl32 flag on this group.

Diff Detail

Repository
rL LLVM

Event Timeline

inouehrs created this revision.Jun 6 2018, 11:06 PM
inouehrs retitled this revision from [PowerPC] avoid redundant Repl32 flag in BitPermutationSelector to [PowerPC] avoid unprofitable Repl32 flag in BitPermutationSelector.Jun 7 2018, 3:38 AM
inouehrs edited the summary of this revision. (Show Details)
hfinkel added inline comments.Jun 7 2018, 5:09 AM
lib/Target/PowerPC/PPCISelDAGToDAG.cpp
1455 ↗(On Diff #150255)

insrtruction -> instruction

1460 ↗(On Diff #150255)

Don't you also need to check that the StartIdx or EndIdx is 0 or 32?

inouehrs updated this revision to Diff 150304.Jun 7 2018, 5:47 AM
inouehrs marked an inline comment as done.
inouehrs added inline comments.
lib/Target/PowerPC/PPCISelDAGToDAG.cpp
1460 ↗(On Diff #150255)

Based on this condition, I think merging can happen if StartIdx and EndIdx are not 0 or 32.

if (I->Repl32 && IP->Repl32 && I->V == IP->V && I->RLAmt == IP->RLAmt &&
    I->StartIdx == (IP->EndIdx + 1) % 64 && I != IP) {

I want to be conservative for not to reduce the opportunity of using Repl32 flag.

hfinkel accepted this revision.Jun 7 2018, 5:50 AM

LGTM

lib/Target/PowerPC/PPCISelDAGToDAG.cpp
1460 ↗(On Diff #150255)

Makes sense.

This revision is now accepted and ready to land.Jun 7 2018, 5:50 AM
This revision was automatically updated to reflect the committed changes.