Page MenuHomePhabricator

[PowerPC] Fold select_cc constants when comparing zero into trivial ops
Needs ReviewPublic

Authored by lkail on Dec 13 2020, 9:41 PM.

Details

Reviewers
spatel
steven.zhang
jsji
nemanjai
RKSimon
Group Reviewers
Restricted Project
Summary

Fold select_cc x, 0, const0, const1, lt into sub (z, and ((sra x, sizeof(x)-1), z - y)), see https://alive2.llvm.org/ce/z/jqcf8t. On PPC, it's cheap to performance such optimization with rlwinm.

Diff Detail

Event Timeline

lkail created this revision.Dec 13 2020, 9:41 PM
lkail requested review of this revision.Dec 13 2020, 9:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2020, 9:41 PM
RKSimon added inline comments.Jan 3 2021, 3:55 AM
llvm/include/llvm/CodeGen/TargetLowering.h
2790 ↗(On Diff #311484)

We need to determine whether other targets would benefit from this - otherwise I'd suggest the initial implementation was purely inside PPCISelLowering

@lkail Reverse ping - as I said earlier I'd probably suggest we make this ppc only initially

lkail updated this revision to Diff 330559.Mar 14 2021, 10:26 PM
lkail retitled this revision from [DAGCombine][PowerPC] Fold select_cc constants when comparing zero into trivial ops to [PowerPC] Fold select_cc constants when comparing zero into trivial ops.
lkail edited the summary of this revision. (Show Details)

@RKSimon Sorry for late response. I have moved the transformation into PPCISelLowering.

RKSimon resigned from this revision.Mar 22 2021, 12:01 PM

I'll leave this to the PowerPC gurus now that its target specific

shchenz added inline comments.Apr 2 2021, 2:06 AM
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
16736

Can we handle CmpOpVT.bitsLT(VT) case by using extend operation?

16758

Is it better to check Diff.isNegative()?

llvm/test/CodeGen/PowerPC/select.ll
7

Could you please add some run lines for AIX too?

shchenz added inline comments.Apr 2 2021, 2:08 AM
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
16731

Use same variable names for these comments? c0/c1 or y/z?

lkail updated this revision to Diff 336371.Apr 9 2021, 3:12 AM

Adjust comments.

lkail marked 2 inline comments as done.Apr 9 2021, 3:15 AM
lkail added inline comments.
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
16736

I don't think it's always profitable. I've updated the comment to make it clearer. The transformation involves in arithmetic shift and SIGN_EXTEND looks not zero overhead under some circumstances.