This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] don't try SimplifyDemandedInstructionBits from add/sub because it's slow and unlikely to succeed
ClosedPublic

Authored by spatel on Feb 22 2017, 12:57 PM.

Details

Summary

Notably, no regression tests change when we remove these calls, and these are expensive calls.

The motivation comes from the general acknowledgement that the compiler is getting slower:
http://lists.llvm.org/pipermail/llvm-dev/2017-January/109188.html
http://lists.llvm.org/pipermail/llvm-dev/2016-December/108279.html

And specifically the test case attached to PR32037:
https://bugs.llvm.org//show_bug.cgi?id=32037

Profiling the middle-end (opt) part of the compile:
$ ./opt -O2 row_common.bc -o /dev/null

...visitAdd and visitSub are near the top of the instcombine list, and the calls to SimplifyDemandedInstructionBits() are high within each of those. Those calls account for 1%+ of the opt time in either debug or release profiles. And that's the rough win I see from this patch when testing opt built release from r295864 on an iMac with Haswell 4GHz (model 4790K).

It seems unlikely that we'd be able to eliminate add/sub or change their operands given that add/sub normally affect all bits, and the PR32037 example shows no IR difference after this change using -O2.

Also worth noting - the code comment in visitAdd:
// This handles stuff like (X & 254)+1 -> (X&254)|1
...isn't true. That transform is handled later with a call to haveNoCommonBitsSet().

Diff Detail

Repository
rL LLVM

Event Timeline

spatel created this revision.Feb 22 2017, 12:57 PM
efriedma accepted this revision.Feb 22 2017, 2:19 PM

It looks like in the current version of SimplifyDemandedUseBits, simplifying the demanded bits on an Add with an all-ones mask is equivalent to calling computeKnownBits. That explains why you didn't find any regressions. :)

Like you've said, I can't see any reason why we'd want to do this; LGTM.

This revision is now accepted and ready to land.Feb 22 2017, 2:19 PM
davide accepted this revision.Feb 22 2017, 2:23 PM

Agree with Eli. LGTM.

This revision was automatically updated to reflect the committed changes.