This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Use helper functions to check sign-/zero-extended value
ClosedPublic

Authored by inouehrs on Oct 17 2017, 12:36 AM.

Details

Summary

Helper functions to identify sign- and zero-extending machine instruction is introduced in rL315888.
This patch makes PPCInstrInfo::optimizeCompareInstr use the helper functions. It simplifies the code and also makes possible more optimizations since the helper can do more analysis than the original check code; I observed about 5000 more compare instructions are eliminated while building LLVM.

Also, this patch fixes a bug in helpers on ANDIo instruction handling due to the order of checks. This bug causes a failure in an existing test case for optimizeCompareInstr.

Diff Detail

Repository
rL LLVM

Event Timeline

inouehrs created this revision.Oct 17 2017, 12:36 AM
nemanjai edited edge metadata.Oct 17 2017, 5:00 AM

This seems like a perfectly valid thing to do. Please add a test case before this can proceed though.
I would imagine that one of the extra 5000 eliminated compare instructions would make for a good test case.

And FWIW, I still don't like the names of these helper functions. There isn't really much indication in the name what it is sign/zero extending from/to. Presume I want to do add/remove an instruction depending on whether the input is known to be sign-extended from a halfword to a doubleword, but not if it is only known to be sign-extended from a word to a doubleword, it isn't clear how I would use these functions to determine that.

inouehrs updated this revision to Diff 119432.Oct 17 2017, 10:50 PM
  • a test case added

And FWIW, I still don't like the names of these helper functions. There isn't really much indication in the name what it is sign/zero extending from/to. Presume I want to do add/remove an instruction depending on whether the input is known to be sign-extended from a halfword to a doubleword, but not if it is only known to be sign-extended from a word to a doubleword, it isn't clear how I would use these functions to determine that.

Is isSignExtendedFromWord better? Other candidates I have are isSignExtendedWord or isSignExtended_32_64. Any suggestions?

nemanjai accepted this revision.Oct 18 2017, 12:58 AM

And FWIW, I still don't like the names of these helper functions. There isn't really much indication in the name what it is sign/zero extending from/to. Presume I want to do add/remove an instruction depending on whether the input is known to be sign-extended from a halfword to a doubleword, but not if it is only known to be sign-extended from a word to a doubleword, it isn't clear how I would use these functions to determine that.

Is isSignExtendedFromWord better? Other candidates I have are isSignExtendedWord or isSignExtended_32_64. Any suggestions?

Well, I think it is important to also communicate that the zero/sign extendedness is a property of the instruction rather than a computation of known bits. So I'm thinking a name like instrZeroExtends32To64() and instrSignExtends32To64(). Or perhaps I'm being pedantic here, maybe @echristo or @hfinkel want to chime in. Of course, the rename can be done in a separate patch.

But this patch LGTM now.

This revision is now accepted and ready to land.Oct 18 2017, 12:58 AM
This revision was automatically updated to reflect the committed changes.