This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] More accurate unsigned add/sub overflow detection
ClosedPublic

Authored by nikic on Feb 24 2019, 2:49 AM.

Details

Reviewers
spatel
RKSimon
Summary

Based on the suggestion in D58329, this changes the existing computeOverflowForUnsignedAdd/Sub methods to detect never/always overflow conditions more accurately.

Rather than calling computeForAddSub() with an extra bit (which would be pretty wasteful, as we're not interested in the addition result here at all), I'm writing out the overflow conditions explicitly.

I've added some explicit tests for saturating add/sub (as we can see both always+never overflow there), but there's also some additional nuws inferred in other tests.

Diff Detail

Event Timeline

nikic created this revision.Feb 24 2019, 2:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 24 2019, 2:49 AM

Nice!

I want to be sure that we're not missing any diffs in the AddOverFlow.ll test file, so I regenerated that:
rL354993

I'd also prefer that we have the baseline tests for the intrinsics committed to trunk as a preliminary step, so we just have the diffs here. Can you rebase and re-upload the patch here after those changes?

nikic updated this revision to Diff 188583.Feb 27 2019, 11:06 AM

Rebase over tests.

spatel accepted this revision.Feb 27 2019, 11:24 AM

LGTM
As you've experienced, we may uncover bugs in other passes with the improved analysis. To minimize risk and make debug potentially easier, I'd push the change as 2 separate commits (1 for add, 1 for sub).

This revision is now accepted and ready to land.Feb 27 2019, 11:24 AM
nikic closed this revision.Feb 28 2019, 10:33 AM

Landed via rL355072 (add) and rL355109 (sub).