This is an archive of the discontinued LLVM Phabricator instance.

[DAG] SimplifyDemandedBits - add sra(shl(x,c1),c1) -> sign_extend_inreg(x) demanded elts fold
ClosedPublic

Authored by RKSimon on Aug 15 2023, 5:57 AM.

Details

Summary

Move the sra(shl(x,c1),c1) -> sign_extend_inreg(x) fold inside SimplifyDemandedBits so we can recognize hidden splats with DemandedElts masks.

Because the c1 shift amount has multiple uses, hidden splats won't get simplified to a splat constant buildvector - meaning the existing fold in DAGCombiner::visitSRA can't fire as it won't see a uniform shift amount.

I also needed to add TLI preferSextInRegOfTruncate hook to help keep truncate(sign_extend_inreg(x)) vector patterns on X86 so we can use PACKSS more efficiently.

Diff Detail

Event Timeline

RKSimon created this revision.Aug 15 2023, 5:57 AM
RKSimon requested review of this revision.Aug 15 2023, 5:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2023, 5:57 AM
Herald added a subscriber: wangpc. · View Herald Transcript
RKSimon planned changes to this revision.Aug 15 2023, 6:32 AM
RKSimon updated this revision to Diff 550313.Aug 15 2023, 6:49 AM
RKSimon edited the summary of this revision. (Show Details)
pengfei added inline comments.Aug 15 2023, 7:41 AM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
1948

Did we check the constant c1 some where?

RKSimon added inline comments.Aug 15 2023, 7:45 AM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
1948

Yes - the *InnerSA == ShAmt check on line 1959

pengfei accepted this revision.Aug 15 2023, 7:49 AM

LGTM.

This revision is now accepted and ready to land.Aug 15 2023, 7:49 AM
This revision was landed with ongoing or failed builds.Aug 15 2023, 8:32 AM
This revision was automatically updated to reflect the committed changes.