This is an archive of the discontinued LLVM Phabricator instance.

[DAG] SimplifyDemandedBits - if we're only demanding the signbits, a MIN/MAX node can be simplified to a OR or AND node
ClosedPublic

Authored by RKSimon on Aug 20 2023, 7:31 AM.

Details

Summary

Extension to the signbit case, if the signbits extend down through all the demanded bits then SMIN/SMAX/UMIN/UMAX nodes can be simplified to a OR/AND/AND/OR.

Alive2: https://alive2.llvm.org/ce/z/mFVFAn (general case)

Diff Detail

Event Timeline

RKSimon created this revision.Aug 20 2023, 7:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 20 2023, 7:31 AM
RKSimon requested review of this revision.Aug 20 2023, 7:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 20 2023, 7:31 AM

Can you parameterize the proofs with C1 and C2 instead of just 3 and 1 to make them complete?

Also I think this also works for umax / umin (although inverted): https://alive2.llvm.org/ce/z/UX_NYn
There is a fair bit of common codes between, maybe a this should also come with a helper like
simplifyMinMaxWithDemandedBits.

RKSimon planned changes to this revision.Aug 22 2023, 10:35 AM
RKSimon edited the summary of this revision. (Show Details)
RKSimon added a reviewer: goldstein.w.n.

I'll update this to add umin/umax handling

RKSimon edited the summary of this revision. (Show Details)Aug 22 2023, 10:48 AM
RKSimon updated this revision to Diff 553432.Aug 25 2023, 3:50 AM
RKSimon retitled this revision from [DAG] SimplifyDemandedBits - if we're only demanding the signbits, a SMIN/SMAX node can be simplified to a OR/AND node respectively. to [DAG] SimplifyDemandedBits - if we're only demanding the signbits, a MIN/MAX node can be simplified to a OR or AND node.
RKSimon edited the summary of this revision. (Show Details)

Added UMIN/UMAX handling and merged all MIN/MAX cases to share code

SMIN/SMAX are still missing proper known bits handling in SimplifyDemandedBits - I'll address this separately with proper test coverage.

Other than the few nits looks good.

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
2185

Should compute Known for smin/smax? Imo also just fill in the TODO. Its not much code required.

2195

I guess already existed but Known computation should be after the condition folding has failed already.

RKSimon added inline comments.Aug 31 2023, 11:20 AM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
2185

Adding smin/smax knownbits handling adds a couple of unrelated changes - I'd prefer to handle that separately. If you prefer, I can refactor the existing min/max cases into this new layout first (with existing functionality) and then fix the missing knownbits handling first?

goldstein.w.n accepted this revision.Aug 31 2023, 11:27 AM

LGTM

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
2185

No, fine to leave as todo I guess.

This revision is now accepted and ready to land.Aug 31 2023, 11:27 AM