This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Don't fall back to only calling computeKnownBits if the upper bit of Add/Sub is demanded.
ClosedPublic

Authored by craig.topper on Aug 8 2017, 1:38 PM.

Details

Summary

Just create an all 1s demanded mask and continue recursing like normal. The recursive calls should be able to handle and all 1s mask do the right thing.

The only time we should care about knowing whether the upper bit was demanded is when we need to know if we should clear the NSW/NUW flags.

Now that we have a consistent path through the code for all cases, use KnownBits::computeForAddSub to compute the known bits at the end since we already have the LHS and RHS.

My larger goal here is to move the code that turns add into xor if only 1 bit is demanded and no bits below it are non-zero from InstCombiner::OptAndOp to here. This will allow it to be more general instead of just looking for 'add' and 'and' with constant RHS.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Aug 8 2017, 1:38 PM
spatel edited edge metadata.Aug 25 2017, 7:34 AM

Is there a potential function difference here, or is this just an efficiency improvement from calling KnownBits::computeForAddSub() directly?

I really hope there is no functional difference. I'm assuming passing an all ones demanded mask down in the case that the sign bit of the input mask is set will prevent any optimizations that can mess with the NSW/NUW property.

My desire is to move the last optimization from InstCombiner::OptAndOp to here. So if we demand only one bit from the Add, which could be the sign bit, we can turn it into an Xor. So I wanted a consistent path through the code regardless of the original demanded mask.

spatel accepted this revision.Aug 25 2017, 9:58 AM

Ok - I tried to expose a difference in output but can't find anything.

LGTM.

This revision is now accepted and ready to land.Aug 25 2017, 9:58 AM
This revision was automatically updated to reflect the committed changes.