This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Prune fshl/fshr with masked operands
ClosedPublic

Authored by shawnl on Apr 13 2019, 6:15 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

shawnl created this revision.Apr 13 2019, 6:15 PM
shawnl planned changes to this revision.Apr 13 2019, 6:20 PM

There is a bug there.

shawnl updated this revision to Diff 195047.Apr 13 2019, 6:51 PM
shawnl retitled this revision from [InstCombine] Simplify fshl/fshr with both sides the same and masked to [InstCombine] Prune fshl/fshr with masked operands.
shawnl edited the summary of this revision. (Show Details)

OK, ready for review

nikic added a comment.Apr 14 2019, 3:03 AM

The idea here looks reasonable to me, but this doesn't seem like the right place to make the transform. This is ultimately a demanded bits problem and as such should be handled in either BDCE or InstCombineSimplifyDemanded.

lib/Transforms/InstCombine/InstCombineCalls.cpp
2090 ↗(On Diff #195047)

You cannot assume that the ShAmtC is a ConstantInt here. It could also be a vector (something that should be covered in tests).

nikic requested changes to this revision.Apr 14 2019, 3:17 AM

Actually all the necessary support is already in place here, all you need to do is call SimplifyDemandedInstructionBits():

if (SimplifyDemandedInstructionBits(*II))
    return &CI;
This revision now requires changes to proceed.Apr 14 2019, 3:17 AM
shawnl updated this revision to Diff 195078.Apr 14 2019, 12:21 PM

use SimplifyDemandedInstructionBits

Please upload all patches with full context (-U99999)

lib/Transforms/InstCombine/InstCombineCalls.cpp
2087 ↗(On Diff #195078)

This should probably be at the top level of whatever function this is.
Not sure where in the function though.

nikic added inline comments.Apr 14 2019, 12:35 PM
lib/Transforms/InstCombine/InstCombineCalls.cpp
2087 ↗(On Diff #195078)

It should probably be right below this block. We already have the demanded bits simplification for the shift amount there (which we should probably move into the fshl handling in InstCombineSimplifyDemanded as a followup).

shawnl marked 2 inline comments as done.Apr 14 2019, 2:42 PM
shawnl added inline comments.
lib/Transforms/InstCombine/InstCombineCalls.cpp
2087 ↗(On Diff #195078)

I think it should go at the top of the match block here. This text is for the shift being a constant, and it can't be simplified unless the shift is a constant.

shawnl planned changes to this revision.Apr 14 2019, 2:45 PM
shawnl updated this revision to Diff 195083.Apr 14 2019, 2:47 PM

keep tests

Please can you place the original tests in a *new* differential,
with check lines for llvm trunk, and then rebase this patch ontop of that patch,
so that test diff shows diff and not whole new tests being added.

lib/Transforms/InstCombine/InstCombineCalls.cpp
2100–2101 ↗(On Diff #195083)

I think that new code should be here.

shawnl marked an inline comment as done.Apr 15 2019, 5:09 AM
shawnl added inline comments.
lib/Transforms/InstCombine/InstCombineCalls.cpp
2100–2101 ↗(On Diff #195083)

but it has to be above this:

if (!isPowerOf2_32(BitWidth))
shawnl updated this revision to Diff 195143.Apr 15 2019, 5:36 AM

base on top of D60688

lebedev.ri added inline comments.Apr 15 2019, 5:38 AM
lib/Transforms/InstCombine/InstCombineCalls.cpp
2100–2101 ↗(On Diff #195083)

Good point, then place it just before that check :)

shawnl updated this revision to Diff 195145.Apr 15 2019, 5:51 AM

move lower

shawnl updated this revision to Diff 195146.Apr 15 2019, 5:52 AM

kill newline

shawnl updated this revision to Diff 195147.Apr 15 2019, 5:54 AM
nikic accepted this revision.Apr 15 2019, 6:04 AM

LGTM

This revision is now accepted and ready to land.Apr 15 2019, 6:04 AM
lebedev.ri added inline comments.Apr 15 2019, 6:11 AM
lib/Transforms/InstCombine/InstCombineCalls.cpp
2090–2091 ↗(On Diff #195147)

Separate with newline