This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Use `analyzeKnownBitsFromAndXorOr` in `SimplifyDemandedUseBits` for and/xor/or
ClosedPublic

Authored by goldstein.w.n on Jan 23 2023, 5:39 PM.

Details

Summary

There are extra patterns that have for these three logic operations
that aren't covered in SimplifyDemandedUseBits. To avoid duplicating
the code, just use analyzeKnownBitsFromAndXorOr in
SimplifyDemandedUseBits to get full coverage.

Diff Detail

Event Timeline

goldstein.w.n created this revision.Jan 23 2023, 5:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 5:39 PM
goldstein.w.n requested review of this revision.Jan 23 2023, 5:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2023, 5:39 PM
nikic requested changes to this revision.Jan 24 2023, 12:47 AM

This is going to unnecessarily recompute known bits we already have. Please go with the helpers instead. Doing a recursive computeKnownBits() call for an operand we didn't check yet is fine, but we shouldn't recompute the known bits we already have.

This revision now requires changes to proceed.Jan 24 2023, 12:47 AM

Use helper instead of computeknownbits

goldstein.w.n retitled this revision from [InstCombine] Use `computeKnownBits` in `SimplifyDemandedUseBits` for and/xor/or to [InstCombine] Use `analyzeKnownBitsFromAndXorOr` in `SimplifyDemandedUseBits` for and/xor/or.Jan 24 2023, 2:55 AM
goldstein.w.n edited the summary of this revision. (Show Details)

This is going to unnecessarily recompute known bits we already have. Please go with the helpers instead. Doing a recursive computeKnownBits() call for an operand we didn't check yet is fine, but we shouldn't recompute the known bits we already have.

Done in V2. Made the AndXorOr helper public in previous patch (D142427) so now just goes through analyzeKnownBitsFromAndXorOr.

goldstein.w.n edited the summary of this revision. (Show Details)

Rebase

nikic added inline comments.Jan 25 2023, 3:01 AM
llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
198–199

You can use cast<Operator>(I) here and drop the if. Every Instruction is an Operator.

goldstein.w.n marked an inline comment as done.

Rebase + switch case

nikic accepted this revision.Jan 26 2023, 6:14 AM

LGTM

This revision is now accepted and ready to land.Jan 26 2023, 6:14 AM