This is an archive of the discontinued LLVM Phabricator instance.

[PPC] Eliminate redundant sign- and zero-extensions in PPC MI Peephole pass
ClosedPublic

Authored by inouehrs on Mar 24 2017, 12:24 AM.

Details

Summary

This patch enables redundant sign- and zero-extension elimination in PowerPC MI Peephole pass.
If the input value of a sign- or zero-extension is known to be already sign- or zero-extended, the operation is redundant and can be eliminated.
One common case is sign-extensions for a method parameter or for a method return value; they must be sign- or zero-extended as defined in PPC ELF ABI. For example of the following simple code, two extsw instructions are generated before the invocation of int_func and before the return. With this patch, both extsw are eliminated.

void int_func(int);
void ii_test(int a) {
    if (a & 1) return int_func(a);
}

Such redundant sign- or zero-extensions are common in many programs; e.g. I observed about 60,000 occurrences of the elimination while compiling the LLVM+CLANG for PPC.

Diff Detail

Repository
rL LLVM

Event Timeline

inouehrs created this revision.Mar 24 2017, 12:24 AM
inouehrs updated this revision to Diff 93212.Mar 27 2017, 11:33 PM
  • I added more code patterns in which we can eliminate sign- or zero-extensions.
  • I added more test cases in the regression test.
inouehrs updated this revision to Diff 93215.Mar 28 2017, 12:04 AM
  • I reverted the recent change in the patch. I will submit it later as a separate patch.

Eric,
Thank you for the advice.

nemanjai commandeered this revision.Apr 12 2017, 4:27 AM
nemanjai edited reviewers, added: inouehrs; removed: nemanjai.
nemanjai edited edge metadata.

Temporarily commandeering this to update it to incorporate changes in https://reviews.llvm.org/D31847.

nemanjai updated this revision to Diff 94953.Apr 12 2017, 4:32 AM

The update simply incorporates the related changes introduced by https://reviews.llvm.org/D31847.

echristo edited edge metadata.Oct 5 2017, 5:58 PM

One question here: Where are the sign and zero extensions coming from? I want to make sure we're not producing extra ones where we could avoid it.

inouehrs commandeered this revision.Oct 6 2017, 1:34 AM
inouehrs removed a reviewer: inouehrs.

commandeered back to update the patch

inouehrs updated this revision to Diff 117963.Oct 6 2017, 1:36 AM
inouehrs edited the summary of this revision. (Show Details)
  • rebased to the latest tree
  • some improvements for wider coverage

@echristo For the motivating example in summary, EXTSW is generated while selecting instructions for the method call since ABI requires sign-extended parameters.
For method that returns a value, a sign-/zero-entension is also often (conservatively) generated for the return value to be compliant with ABI.

echristo accepted this revision.Oct 13 2017, 6:55 PM

LGTM.

This revision is now accepted and ready to land.Oct 13 2017, 6:55 PM
This revision was automatically updated to reflect the committed changes.