This is an archive of the discontinued LLVM Phabricator instance.

[TargetLowering]: Fix unnecessary call to `computeKnownBits`
ClosedPublic

Authored by 0xdc03 on May 8 2023, 4:24 AM.

Details

Summary

In the SimplifyDemandedBits function, there is a fallthrough to the
default case in the case of ISD::ADD, ISD::MUL and ISD::SUB. This
leads to a call to computeKnownBits which is unnecessary as the
calls to SimplifyDemandedBits in the cases themselves handle the
calculation of the known bits. This information is discarded through the
Known2 variables.

By keeping this information around and calling
KnownBits::mul or KnownBits::computeForAddSub directly, the
unnecessary computation can be avoided. For now, the NSW bit is not
passed through to KnownBits as this is something that
computeKnownBits does not handle either. This requires updating
computeForAddCarry to handle the flag as well.

Diff Detail

Event Timeline

0xdc03 created this revision.May 8 2023, 4:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2023, 4:24 AM
0xdc03 requested review of this revision.May 8 2023, 4:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2023, 4:24 AM
0xdc03 added a reviewer: nikic.May 8 2023, 4:24 AM
nikic accepted this revision.May 8 2023, 7:05 AM

LGTM

This revision is now accepted and ready to land.May 8 2023, 7:05 AM
0xdc03 updated this revision to Diff 520363.May 8 2023, 7:06 AM
  • Fix formatting
0xdc03 added a comment.May 8 2023, 7:09 AM

As I do not have commit access, can you please land this patch on my behalf @nikic using "Dhruv Chawla <dhruv263.dc@gmail.com>"?

This revision was landed with ongoing or failed builds.May 8 2023, 7:14 AM
This revision was automatically updated to reflect the committed changes.