This is an archive of the discontinued LLVM Phabricator instance.

[BasicAA] Use saturating multiply on range if nsw
ClosedPublic

Authored by nikic on Oct 29 2021, 2:53 PM.

Details

Summary

If we know that the var * scale multiplication is nsw, we can use a saturating multiplication on the range (as a good approximation of an nsw multiply). This recovers some cases where the fix from D112611 is unnecessarily strict. (This can be further strengthened by using a saturating add, but we currently don't track all the necessary information for that.)

This exposes an issue in our NSW tracking for multiplies. The code was assuming that (X +nsw Y) *nsw Z results in (X *nsw Z) +nsw (Y *nsw Z) -- however, it is possible that the distributed multiplications overflow, even if the non-distributed one does not. We should discard the nsw flag if the the offset is non-zero. If we just have (X *nsw Y) *nsw Z then concluding X *nsw (Y *nsw Z) is fine. I'm happy to land this part separately -- I've bundled these because I don't think it's possible to actually cause a miscompile otherwise, due to the specific way the NSW flag was previously used.

Diff Detail

Event Timeline

nikic created this revision.Oct 29 2021, 2:53 PM
nikic requested review of this revision.Oct 29 2021, 2:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 29 2021, 2:53 PM
nikic retitled this revision from [BasicAA] Use saturating multiply if nsw to [BasicAA] Use saturating multiply on range if nsw.Oct 29 2021, 2:58 PM
nikic edited the summary of this revision. (Show Details)
courbet accepted this revision.Nov 2 2021, 1:58 AM
This revision is now accepted and ready to land.Nov 2 2021, 1:58 AM
This revision was automatically updated to reflect the committed changes.