This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] When calculating known bits for integer abs, make sure we're looking at a negate and not just any instruction with the nsw flag set.
ClosedPublic

Authored by craig.topper on Aug 2 2019, 11:35 PM.

Details

Summary

The matchSelectPattern code can match patterns like (x >= 0) ? x : -x
for absolute value. But it can also match ((x-y) >= 0) ? (x-y) : (y-x).
If the latter form was matched we can only use the nsw flag if its
set on both subtracts.

This match makes sure we're looking at the former case only.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Aug 2 2019, 11:35 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2019, 11:35 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic added a subscriber: nikic.Aug 2 2019, 11:52 PM

As we only have a handful of SPF_ABS uses, it might make sense to introduce a separate abs flavor for the nsw case (which would also allow to handle the x-y case more accurately). SPF_PABS? SPF_ABS_NSW?

(Not in this revision of course.)

llvm/lib/Analysis/ValueTracking.cpp
1098 ↗(On Diff #213181)

I think this should still be going through IIQ, otherwise NewGVN might be unhappy.

Continue using IIQ. Also use IIQ to the other location that checks for the NSW.

nikic accepted this revision.Aug 6 2019, 9:52 AM

LGTM

This revision is now accepted and ready to land.Aug 6 2019, 9:52 AM
This revision was automatically updated to reflect the committed changes.