This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC][NFC] Do not enter prefix selection if it cannot do better.
ClosedPublic

Authored by stefanp on Mar 17 2021, 9:40 AM.

Details

Summary

Do not try to materialize a constant using prefix instructions if the selection
using non prefix instructions was able to do it using a single non prefix
instruction.

Diff Detail

Event Timeline

stefanp created this revision.Mar 17 2021, 9:40 AM
stefanp requested review of this revision.Mar 17 2021, 9:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2021, 9:40 AM
stefanp added reviewers: lei, Restricted Project.Mar 17 2021, 9:41 AM
NeHuang added inline comments.
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
1174

Please correct me if I my understand is wrong here. It seems to me InstCntDirect=1 case has been covered in the check below.

 // If the prefix and non-prefix cases use the same number of instructions
// we will prefer the non-prefix case.
    if (ResultP && (!Result || InstCntDirectP < InstCntDirect))

Then intention of adding an early exit for InstCntDirect == 1 case is to save the trial of calling selectI64ImmDirectPrefix and further checks below.

amyk added a subscriber: amyk.Mar 19 2021, 3:06 PM
amyk added inline comments.
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
1172

nit: Spelling.

nemanjai accepted this revision.Mar 19 2021, 7:37 PM

LGTM.

llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
1173

I think you should simplify this comment to something like:

// If we have prefixed instructions and there is a chance we can
// materialize the constant with fewer prefixed instructions than
// non-prefixed, try that.

This clearly communicates that there is no point doing any further checks if we can materialize this with just a single non-prefixed instruction (i.e. we won't be able to materialize it with zero instructions).

This revision is now accepted and ready to land.Mar 19 2021, 7:37 PM
stefanp updated this revision to Diff 332278.Mar 22 2021, 7:13 AM

Updated comment.

stefanp added inline comments.Mar 22 2021, 7:15 AM
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
1174

Yes that is correct. There is no need to call selectI64ImmDirectPrefix if we already know that it will fail the check InstCntDirectP < InstCntDirect and that the result it produces won't be used.

This revision was landed with ongoing or failed builds.Mar 22 2021, 7:18 AM
This revision was automatically updated to reflect the committed changes.
NeHuang added inline comments.Mar 22 2021, 7:18 AM
llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp
1174

Thanks. LGTM.