This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Handle known shl nsw sign bit in SimplifyDemanded
ClosedPublic

Authored by nikic on Mar 20 2020, 5:03 AM.

Details

Summary

Ideally SimplifyDemanded should compute the same known bits as computeKnownBits(). This addresses one discrepancy, where ValueTracking is more powerful: If we have a shl nsw shift, we know that the sign bit of the input and output must be the same. If this results in a conflict, the result is poison.

This is implemented in https://github.com/llvm-mirror/llvm/blob/2c4ca6832fa6b306ee6a7010bfb80a3f2596f824/lib/Analysis/ValueTracking.cpp#L1175-L1179 and https://github.com/llvm-mirror/llvm/blob/2c4ca6832fa6b306ee6a7010bfb80a3f2596f824/lib/Analysis/ValueTracking.cpp#L904-L908.

This implements the same basic logic in SimplifyDemanded. It's slightly stronger, because I return undef instead of zero for the poison case (which is not an option inside ValueTracking).

As mentioned in https://reviews.llvm.org/D75801#inline-698484, we could detect undef in more cases, this just establishes parity with the existing logic.

Diff Detail

Event Timeline

nikic created this revision.Mar 20 2020, 5:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2020, 5:03 AM
nikic retitled this revision from [InstCombine] Handle know shl nsw sign bit in SimplifyDemanded to [InstCombine] Handle known shl nsw sign bit in SimplifyDemanded.Mar 20 2020, 8:58 AM
spatel accepted this revision.Mar 20 2020, 9:16 AM

LGTM

This revision is now accepted and ready to land.Mar 20 2020, 9:16 AM
This revision was automatically updated to reflect the committed changes.